DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on • Edited on

2 1

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

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay