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

feat: use yamllint to check YAML files, instead of simply parsing and pretty-printing them #676

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from

Conversation

jenstroeger
Copy link
Owner

@jenstroeger jenstroeger commented Jan 3, 2024

There are differences between YAML 1.1 and YAML 1.2, and out there in the wild different tools use different YAML parsers for either version of YAML files.

Currently, we use

and
- id: pretty-format-yaml
args: [--autofix]
to check and pretty-print YAML files, both of which use the ruamel package which defaults to parsing and interpreting YAML 1.2 files (more details).

However — and that’s where trouble starts, and that’s what happened in a dependent repo — by pretty-printing the YAML files using a YAML 1.2 parser we turn a

- args:
  - --option
  - "on"

sequence into

- args:
  - --option
  - on

which is valid YAML 1.2 but creates problems with YAML 1.1 parsers: there, the scalar on is interpreted as a boolean value (docs) and turned into true, thus breaking the args sequence.

Adding this YAML linter actually prevents that breakage because the linter notes a violation of its truthy rule.


I’d like to tinker a little more here: for example, handling of multiple documents --- in a single file seems inconsistent between ruamel and yamllint, and it would be helpful to disable line-length checking (docs) without using other options. Also, see issue adrienverge/yamllint#632.

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 this pull request may close these issues.

1 participant