Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is it possible to make it so it forces blank lines between elements? #683

Open
Stasky745 opened this issue Aug 23, 2024 · 2 comments

Comments

@Stasky745
Copy link

So to make it that this is right:

# For all rules
ignore: |
  *.dont-lint-me.yaml
  /bin/
  !/bin/*.lint-me-anyway.yaml

rules:
  key-duplicates:
    ignore: |
      generated
      *.template.yaml

  trailing-spaces:
    ignore: |
      *.ignore-trailing-spaces.yaml
      /ascii-art/*

and this is wrong:

# For all rules
ignore: |
  *.dont-lint-me.yaml
  /bin/
  !/bin/*.lint-me-anyway.yaml
rules:
  key-duplicates:
    ignore: |
      generated
      *.template.yaml
  trailing-spaces:
    ignore: |
      *.ignore-trailing-spaces.yaml
      /ascii-art/*

I'd say when the following line has less identation than the previous one to force a blank space. Is this possible?

@victoraugustolls
Copy link

@adrienverge would you be open to a PR for this? I was thinking maybe a line_break rule that you can pass the root option, so you need to skip a line between root elements and level to say up until what level you need to jump a line between elements.

@adrienverge
Copy link
Owner

Hello Victor, I like the idea and would be open to such a contribution.

Instead of a new rule, maybe it would make sense to reuse the empty-lines rule?

Such a feature needs to be well designed and future-proof, so before developing any code (+ tests), we need a clear proposal of new options to be able to achieve complex configurations like:

# 2 empty lines required at top level
# 1 empty line required at levels 2, 3 and 4, for mappings only
# 1 empty line required at levels 2, for sequences only
a:
  k1: v1

  k2:
    x: 1
      s: 1

      t:
        no: line
        breaks: here
        but: it's OK

      u: 3

    y: 2

    z: 3

  k3: v2


b:
  - item

  - item

  - items:
    - subitem
    - subitem
    - subitem


c: 3

Ideally, we would also need a way to tell whether an empty line is required before first items in sequences and mappings, e.g. in the first comment's example:

# No empty line before first item:
rules:
  key-duplicates: 

  trailing-spaces: 

# versus:
rules:

  key-duplicates: 

  trailing-spaces: 

Also, should lines with comments be accounted for?

# comment
a: 1

b: 2

# vs.

# comment

a: 1

b: 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants