So my team is currently working on an application that uses a lot of YAML and we need to enforce some rules for common formatting. The best would be a command-line program so we can plug it into our CI.
Most importantly, we want to force 2-space indentation and indentation of lists, like this:
list:
- not indented
- not indented # this is BAD
list:
- indented
- indented # this is GOOD
mapping:
5 space indentation # this is BAD
Also it would be great to preventing trailing spaces and non-sense syntaxes.
I've found some websites that check YAML validity (i.e. whether it's possible to load it or not) -- but no linting. The same for yaml-lint, a Ruby app that only "checks if your YAML files can be loaded".
Is there a linter for YAML, similar to flake8 for python or eslint for javascript?
You're looking for yamllint. In your CI:
sudo pip install yamllint
yamllint file1.yml ...
It's highly configurable. Specifically, for 2-space indents and forcing list indentation, the conf would be:
rules:
indentation: {spaces: 2, indent-sequences: yes}
(It also handles trailing spaces, line-length etc.)
Have fun!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With