DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on • Edited on

Simple linter for yaml files modified in git

Yaml is fragile

If you edit yaml files often enough you might know that YAML syntax is way too fragile and accidental errors easy creep in and break your code.

Here is yaml-lint Sparrow6 plugin to the rescue.

Whenever you change your yaml files in git, lint them through yaml python module.

Yaml-lint picks up all the git A or M files and run yaml linter for them.

Install plugin

$ tom --profile yaml install yaml@yaml-lint ... 
Enter fullscreen mode Exit fullscreen mode

Use plugin

Just edit whatever file you want to edit:

$ nano main.yml # already added to git modified file - `M` $ nano foo.yml $ git add foo.yml # newly added to git file - `A` 
Enter fullscreen mode Exit fullscreen mode

And run linter before commit:

$ tom yaml-lint gimy@77b3f88acea1:~/projects/LFA-Applications$ tom yaml-lint 19:41:47 03/13/2019 [repository] index updated from file:///home/melezhik/projects/repo/api/v1/index 19:41:48 03/13/2019 [lint modified files] python -c 'import yaml,sys;yaml.safe_load(sys.stdin)' < main.yml 19:41:48 03/13/2019 [lint modified files] python -c 'import yaml,sys;yaml.safe_load(sys.stdin)' < foo.yml 
Enter fullscreen mode Exit fullscreen mode

Now you're good to commit:

git commit -a -m "we have a good yaml" 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)