feat: use yamllint to check YAML files, instead of simply parsing and pretty-printing them
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 https://github.com/jenstroeger/python-package-template/blob/40e438b0adab9e4d90f754811bba7a1284d592d9/.pre-commit-config.yaml#L120 and https://github.com/jenstroeger/python-package-template/blob/40e438b0adab9e4d90f754811bba7a1284d592d9/.pre-commit-config.yaml#L148-L149 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 https://github.com/adrienverge/yamllint/issues/632.