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

Rule feature request: brackets - forbid after maximum size #680

Open
adammw opened this issue Jul 31, 2024 · 3 comments
Open

Rule feature request: brackets - forbid after maximum size #680

adammw opened this issue Jul 31, 2024 · 3 comments

Comments

@adammw
Copy link

adammw commented Jul 31, 2024

Rule feature to expand existing brackets to allow flow-style brackets for arrays up to n items, but forbid for longer than that.

e.g. { forbid: { max_size: 3 } }

PASS [ 1, 2, 3 ]

FAIL [ 1, 2, 3, 4, 5 ]

May also want to extend to allowing only certain character lengths in flow-style, or forbidding nested objects while allowing primitives.

@adrienverge
Copy link
Owner

Hello Adam, thanks for the proposal.

But the goal of yamllint is to lint the form of YAML, not the content or its structure. We could imagine many new rules to check the max number of items (what you propose), or the type of values, or that all strings contain a substring, or that all keys match a regex, etc. But the purpose of yamllint is to be focused on YAML itself, so I'm not favorable to adding such content-oriented rules.

@adammw
Copy link
Author

adammw commented Jul 31, 2024

In this, i'm referring solely to the form of the YAML..

Currently "forbid" will disallow simple one-liners like { key: "opt-out", values: ["true"] } whereas this is something we can consider 'cleaner' than an expanded form, while still requiring for long arrays to be expanded fully, e.g.

- key: "opt-out"
  values: 
  - a
  - b
  - c

@adrienverge
Copy link
Owner

Thanks for the clarification! Sorry, I initially misunderstood your proposal.

→ You want to be able to force sequences to be in block-style (i.e. forbid flow-style) if they contain more than n elements. And the same for mappings, I suppose.

Indeed this is about the form of the YAML, so it could be accepted. But it seems a bit a "niche" use case, and the goal (have "cleaner" and "easier to read" data) can maybe be achieved using the line-length rule?

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

2 participants