A linter for YAML files.
yamllint does not only check for syntax validity, but for weirdnesses like key repetition and cosmetic problems such as lines length, trailing spaces, indentation, etc.
Written in Python (compatible with Python 2 & 3).
⚠ Python 2 upstream support stopped on January 1, 2020. yamllint will keep best-effort support for Python 2.7 until January 1, 2021. Past that date, yamllint will drop all Python 2-related code.
https://yamllint.readthedocs.io/
Using pip, the Python package manager:
pip install --user yamllint
yamllint is also packaged for all major operating systems, see installation
examples (dnf
, apt-get
...) in the documentation.
# Lint one or more files
yamllint my_file.yml my_other_file.yaml ...
# Lint all YAML files in a directory
yamllint .
# Use a pre-defined lint configuration
yamllint -d relaxed file.yaml
# Use a custom lint configuration
yamllint -c /path/to/myconfig file-to-lint.yaml
# Output a parsable format (for syntax checking in editors like Vim, emacs...)
yamllint -f parsable file.yaml
Read more in the complete documentation!
Here is a yamllint configuration file example:
extends: default
rules:
# 80 chars should be enough, but don't fail if a line is longer
line-length:
max: 80
level: warning
# don't bother me with this rule
indentation: disable
Within a YAML file, special comments can be used to disable checks for a single line:
This line is waaaaaaaaaay too long # yamllint disable-line
or for a whole block:
# yamllint disable rule:colons
- Lorem : ipsum
dolor : sit amet,
consectetur : adipiscing elit
# yamllint enable
Specific files can be ignored (totally or for some rules only) using a
.gitignore
-style pattern:
# For all rules
ignore: |
*.dont-lint-me.yaml
/bin/
!/bin/*.lint-me-anyway.yaml
rules:
key-duplicates:
ignore: |
generated
*.template.yaml
trailing-spaces:
ignore: |
*.ignore-trailing-spaces.yaml
/ascii-art/*
Read more in the complete documentation!