adrienverge / yamllint

A linter for YAML files.
GNU General Public License v3.0
2.83k stars 269 forks source link

Feature Request: list-ordering #454

Open cacack opened 2 years ago

cacack commented 2 years ago

Similar to the key-ordering rule, I'd like to be able to enforce that lists are sorted.

Pass:

foo:
  - a
  - b
  - c

bar:
  - abc12
  - agf77
  - bca23
  - bca45

Fail:

foo:
  - d
  - a
  - b

bar:
  - agf77
  - abc12
  - bca23
adrienverge commented 1 year ago

Hello,

I'm not very favorable to such a change, because yamllint aims to lint the form, not the content:

Additionally, the way heterogenous item types (e.g. [false, 1, "2", {3: 4}]) should be handled is very subjective and probably tricky.

mwgamble commented 1 year ago

Any kind of list sorting needs to be based on content-specific policies. It isn't really feasible to implement such a thing within a linter.

cacack commented 1 year ago

I do agree with the points @adrienverge raises, and is very much content-specific as @mwgamble notes. I do still have the need and cast an eye towards yamllint as the tool since it already has the yaml parsed into a DOM where I felt it might be an easy feature to add...

Maybe we'll just write our own parser to implement this check for our context..

thibautmery commented 4 months ago

Hello, Any update about this feature?

marcindabrowski commented 3 months ago

I agree that someone do not want to have list sorted, but this rule is similar to key-ordering rule, which is disabled by default.

I think that it would be worthy to have it, disabled by default. And actually there is a PR for this feature, but what is the reason it was not merged?

The lack of some test cases? I'm not sure but maybe @adrienverge you should write it explicitly, what should be added to the PR to be able to merge it.

adrienverge commented 3 months ago

Hello,

I tried to make it clear in my previous comment: https://github.com/adrienverge/yamllint/issues/454#issuecomment-1460609614 but I can try to write it differently. Yamllint aims to lint the form, not the content. The rule key-ordering is about the form (data-wise {a: 1, b: 2} is the same as {b: 2, a: 1}), whereas a rule to sort values would be about the content, i.e. forcing data to respect some arbitrary rules ([a, b] is not the same as [b, a]).