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

Feature Request: list-ordering #454

Open
cacack opened this issue Apr 19, 2022 · 6 comments · May be fixed by #541
Open

Feature Request: list-ordering #454

cacack opened this issue Apr 19, 2022 · 6 comments · May be fixed by #541

Comments

@cacack
Copy link

cacack commented Apr 19, 2022

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
kainjow added a commit to kainjow/yamllint that referenced this issue Mar 1, 2023
This is based on the key-ordering rule and behaves the same with regards to locales.

Closes adrienverge#454
@kainjow kainjow linked a pull request Mar 1, 2023 that will close this issue
kainjow added a commit to kainjow/yamllint that referenced this issue Mar 1, 2023
This is based on the key-ordering rule and behaves the same with regards to locales.

Closes adrienverge#454
kainjow added a commit to kainjow/yamllint that referenced this issue Mar 3, 2023
This is based on the key-ordering rule and behaves the same with regards to locales.

Closes adrienverge#454
kainjow added a commit to kainjow/yamllint that referenced this issue Mar 3, 2023
This is based on the key-ordering rule and behaves the same with regards to locales.

Closes adrienverge#454
@adrienverge
Copy link
Owner

Hello,

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

  • Ensuring a given order for keys of a mapping is about form, because YAML mapping keys do not have an order, per the YAML specification. Expecting an alphabetical sorting of keys is just about style → what a linter does.
  • Ensuring a sort order for list values is about content: yamllint would impose to change the effective value of data ([h, e, l, l, o] is not the same as [e, h, l, l, o]).

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

@mwgamble
Copy link
Contributor

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
Copy link
Author

cacack commented May 25, 2023

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

blujupiter32 pushed a commit to blujupiter32/yamllint that referenced this issue Jul 25, 2023
This is based on the key-ordering rule and behaves the same with regards to locales.

Closes adrienverge#454
@thibautmery
Copy link

Hello,
Any update about this feature?

@marcindabrowski
Copy link

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
Copy link
Owner

Hello,

I tried to make it clear in my previous comment: #454 (comment) 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]).

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

Successfully merging a pull request may close this issue.

5 participants