yamllint is a linter for YAML files written in Python, version 1.38.0. It checks not only for syntax validity but also for common weirdnesses like key repetition and cosmetic issues such as line length, trailing spaces, and indentation. The project is actively maintained with regular releases.
pip install yamllintVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically lint a YAML string using `yamllint`. It creates a `YamlLintConfig` and then uses `linter.run` with an `io.StringIO` object to process the YAML content, iterating over any `LintProblem` objects found.
Upgrade Python to 3.10+ or pin `yamllint` to an older compatible version.
Run `yamllint` with the `--strict` (or `-s`) option in CI/CD environments: `yamllint --strict .`
Explicitly specify a configuration file using the `-c` option (`yamllint -c /path/to/myconfig.yaml file.yaml`) or disable automatic config search for specific use cases. Be aware of your project's directory structure for `.yamllint` files.
Avoid `yamllint` version 1.35.0 if programmatic file ignoration is critical; upgrade to 1.35.1 or newer, or downgrade to 1.34.x or older.
Run yamllint using `python -m yamllint <file.yaml>` or add the pip binaries directory (e.g., `~/.local/bin` on Linux/macOS) to your system's PATH.
Review the `.yamllint` file for syntax errors, ensuring it's valid YAML and conforms to the `yamllint` configuration specification.
Run `yamllint --help` to see the list of valid options, or consult the `yamllint` documentation for the correct command-line arguments.
Install the package using pip: `pip install yamllint`.