yamllint
Lint YAML files for syntax and style
SYNOPSIS
yamllint [options] [path...]
yamllint --version
yamllint --help
PARAMETERS
-c FILE, --config-file=FILE
Use a specific configuration file (e.g., .yamllint.yaml) instead of the default search path.
-d DATA, --config-data=DATA
Provide configuration directly as a YAML string on the command line.
-f FORMAT, --format=FORMAT
Specify the output format for linting results. Common formats include standard, parsable, github, gitlab, and vs.
-s, --strict
Return a non-zero exit code (1) for warnings in addition to errors. By default, only errors cause a non-zero exit.
--no-warnings
Suppress all warning messages from being printed in the output.
-v, --version
Display the yamllint version number and exit.
-h, --help
Show the help message and exit.
DESCRIPTION
yamllint is a command-line utility designed to check YAML files for syntax validity and adherence to specified style guidelines. It helps developers and system administrators maintain consistent coding standards, prevent common errors, and ensure the readability of YAML configurations. Highly configurable, yamllint allows users to enable or disable specific rules, customize rule behavior, and define custom ignore paths. It's commonly integrated into CI/CD pipelines to automate code quality checks for configuration files, infrastructure-as-code definitions, and other YAML-based assets.
CAVEATS
yamllint is a static analysis tool that reports issues but does not automatically fix them. It requires Python to be installed on the system. While highly configurable, setting up complex custom rule sets can sometimes be challenging.
CONFIGURATION
yamllint can be configured via a file named .yamllint or .yamllint.yaml in the current directory, user's home directory, or a specified path. This configuration file defines which rules are enabled or disabled, their severity (error/warning), and various other settings like ignored paths, maximum line length, and indentation size.
EXIT STATUS
The command's exit status provides information about the linting outcome:
0: No errors or warnings were found (or only warnings if --strict is not used).
1: Errors or warnings (if --strict is used) were found.
2: A fatal error occurred (e.g., invalid configuration file, input file not found).
RULES
yamllint ships with a comprehensive set of built-in rules that cover common YAML best practices. These include checks for indentation, trailing spaces, line length, key ordering, document start/end markers, and more. Users can selectively enable, disable, or customize the behavior of these rules within their configuration file.
HISTORY
yamllint is an open-source project actively developed on GitHub. It emerged as a dedicated linter for YAML, addressing the growing need for quality control in configuration files, especially with the rise of Infrastructure as Code. Its development has focused on extensibility, robust rule sets, and ease of integration into continuous integration (CI) workflows.
SEE ALSO
ansible-lint(1), jsonlint(1), shellcheck(1), flake8(1)