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 get yamllint to check for and enforce YAML 1.2? #676

Open
fabcor-maxiv opened this issue Jun 28, 2024 · 4 comments

Comments

@fabcor-maxiv
Copy link

This is a question rather than an issue report, and depending on the answer it might become a feature request...

Is it possible to get yamllint to check for and enforce YAML 1.2?

We would like to make sure that all our files follow YAML spec version 1.2. Can yamllint help us enforce this in some way? Maybe check for the presence of the %YAML 1.2 directive or maybe get yamllint to output an error if the file is not YAML 1.2 conform. We just started using yamllint so we might have just not found out how to do this yet.

@adrienverge
Copy link
Owner

Hello,

In general yamllint tries to enforce YAML 1.2, but it's not 100% consistent, mainly because of its YAML parser (PyYAML) and because some rules support both depending on what it detects (e.g. #650).

If you just want to check for the presence of the directive %YAML 1.2, a new rule could be implemented.
Otherwise, it really depends on what you mean by "enforce YAML 1.2": do you have a concrete example?

@fabcor-maxiv
Copy link
Author

If you just want to check for the presence of the directive %YAML 1.2, a new rule could be implemented.

I feel like such a rule would be useful for us.

some rules support both depending on what it detects

Exactly, we want to make sure that yamllint is not assuming YAML 1 when what we want is YAML 1.2. Sometimes we forget to place the %YAML 1.2 directive, so we do not know for sure what version yamllint is assuming. Having the rule mentioned above would remove the uncertainty, wouldn't it? Does that make sense?

@adrienverge
Copy link
Owner

Do you have a concrete example of YAML code where this makes a difference, in your use case?

@gboeing
Copy link

gboeing commented Jan 6, 2025

+1 to this suggestion.

YAML 1.2 has been out for >15 years now. It'd be nice to enforce it without having to add a %YAML 1.2 directive in every single file, which becomes burdensome if you have a lot of YAML files but more importantly violates the "don't repeat yourself" principle of software development.

@adrienverge in #650 you made the comment:

I agree that prepending explicit tags like %YAML 1.2 is not practical and few users would do it. I'm attracted by the idea of making yamllint 1.2-compatible by default, but that would partially defeat the purpose of some rules (e.g. octal-values or truthy which help detecting values valid in 1.1 but not in 1.2).

This makes a lot of sense to me. Perhaps YAML 1.2 could be made the default version and yamllint could get a new configuration option like yaml-version: 1.2 to allow users to set a lower version if needed for their purposes. This would also help with #430 and the myriad others who are surprised by Github's decision to use a truthy value (in YAML <1.2) for a standard key ("on:").

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