adrienverge/yamllint

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

Opened this issue · 2 comments

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?

@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.

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