Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program to lint YAML files? [closed]

Tags:

yaml

lint

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?

like image 859
Alex Dwaine Avatar asked Jan 27 '16 21:01

Alex Dwaine


1 Answers

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!

like image 167
Adrien Vergé Avatar answered Sep 23 '22 04:09

Adrien Vergé