General
YAML Formatter Linter Guide: Prettier vs yamllint vs Lint
Table of contents
Why YAML linting and formatting is non-negotiableThe three tools comparedPrettier: opinionated formatting for YAMLyamllint: rule-based linting for YAMLLint: catching typos and bad copy in YAML comments and stringsHow to choose for Docker Compose, Kubernetes manifests, and GitHub ActionsOther tools worth knowingFinal recommendationWhy YAML linting and formatting is non-negotiable
YAML's flexibility is also its biggest trap. A single missing space or an incorrectly quoted boolean can break a Kubernetes deployment or make a GitHub Actions workflow fail silently. For developers, YAML is not just configuration; it's infrastructure-as-code. That means it deserves the same care as application code: consistent formatting, lint rules, and human-readable feedback.
This guide compares three tools—Prettier, yamllint, and Lint—for keeping YAML clean across docker-compose files, Kubernetes manifests, and GitHub Actions workflows.
The three tools compared
Before diving in, here's a quick snapshot:
| Tool | Primary role | Auto-fix | Best for |
|------|-------------|----------|----------|
| Prettier | Opinionated formatter | Yes | Consistent indentation and quotes |
| yamllint | Rule-based linter | Mostly no | Catching structural and stylistic issues |
| Lint | Prose and naming checker | Yes | Typos, unclear comments, inconsistent keys |
Full disclosure: Lint is the tool we build, but the goal here is to help you pick the right combination for your stack.
Prettier: opinionated formatting for YAML
Prettier is best known for JavaScript, but it has supported YAML since version 1.15. It formats YAML files by enforcing consistent indentation (2 spaces), normalizing quotes, and wrapping long lines. Prettier's main advantage is zero configuration: you install it, run it, and everyone on the team gets the same output.
For Docker Compose files, Prettier cleans up messy arrays and multi-line strings. For GitHub Actions workflows, it ensures that
runs-on, steps, and env blocks are consistently indented. However, Prettier does not validate YAML semantics. It will not warn you about duplicate keys, unsafe yes/no booleans, or missing required fields in a Kubernetes manifest.Use Prettier as your first pass to eliminate formatting debates. Pair it with a YAML-specific linter for deeper checks.
yamllint: rule-based linting for YAML
yamllint is a Python-based linter designed specifically for YAML. It checks rules like
line-length, indentation, truthy, document-start, key-duplicates, and comments. yamllint does not reformat files by default; it reports violations and exits with a non-zero code, making it ideal for CI.One of yamllint's strengths is its configurability. You can disable the
truthy rule for GitHub Actions workflows, where on is a valid key but YAML 1.1 interprets it as a boolean. A typical .yamllint.yml looks like:``
yaml
extends: default
rules:
truthy: disable
line-length: {max: 120}
indentation: {spaces: 2}
`
For Kubernetes manifests, yamllint can enforce that apiVersion and kind appear in a consistent order, but it cannot check against the Kubernetes API schema. That's a separate tool, which we'll cover later.
yamllint is excellent for teams that want stable, rule-based style enforcement across many YAML files. It won't catch prose issues in comments or string values, though.
Lint: catching typos and bad copy in YAML comments and strings
Lint takes a different angle. Instead of focusing on indentation or YAML structure, it scans the human-facing parts of your YAML files—keys, comments, and string values used for descriptions—and flags typos, inconsistent casing, unclear placeholder text, and grammar issues. For example, it would catch verison in a Docker Compose environment variable or TODO: fix later in a Kubernetes manifest comment.
Where Prettier and yamllint treat YAML as pure configuration, Lint recognizes that YAML files are also documentation. A description field in a GitHub Actions workflow or a comment block in docker-compose is still writing. Lint's auto-fix can correct spelling and clean up repeated words in those fields without touching the YAML structure.
Lint is not a replacement for Prettier or yamllint. It does not format indentation or validate YAML syntax. Instead, it complements them: Prettier handles layout, yamllint enforces structural rules, and Lint improves the human-readable content. If your YAML files are mostly machine-generated or have no comments/string values, Lint adds little. If you write lots of comments and descriptions, it's a useful third layer.
How to choose for Docker Compose, Kubernetes manifests, and GitHub Actions
Here's a practical breakdown for each target file type:
- Docker Compose: Start with Prettier to keep services, ports, and volumes aligned. Add yamllint to catch duplicate service names or problematic truthy values. Use Lint if your Compose file has many explanatory comments or image tags that are meant to be human-readable.
- Kubernetes manifests: Prettier for consistent indentation across metadata, spec, and containers. yamllint to enforce style rules like key ordering and indentation. For schema validation, add Kubeconform or kubeval separately—neither Prettier nor yamllint checks the Kubernetes API.
- GitHub Actions workflows: Prettier for formatting. yamllint with truthy: disable to avoid false positives on the on key. Then use actionlint to validate workflow-specific syntax. Lint can help if you write long step names or description fields for reusable workflows.
Other tools worth knowing
The YAML ecosystem includes several specialized tools that pair well with the three above:
- Spectral: A JSON/YAML linter for OpenAPI and AsyncAPI documents. It enforces API style guides and is useful if your YAML files describe APIs rather than infrastructure.
- actionlint: A dedicated linter for GitHub Actions workflow files. It catches errors like invalid runs-on values, missing steps`, and incorrect expressions—issues that generic YAML linters miss.- Kubeconform: Validates Kubernetes manifests against the official API schemas. It's the "does this deployment actually work?" check.
- pre-commit: A framework for running all these tools automatically before each commit. You can configure Prettier, yamllint, and Lint as pre-commit hooks so they run on every staged YAML file.
Final recommendation
There is no single best tool—the winning setup is a layered one. For most developer teams, I suggest:
If you only pick two, Prettier + yamllint covers the most ground. If you care about the written content inside YAML—misspelled keys, confusing comments, inconsistent descriptions—add Lint to the mix. The goal is not a single tool, but a consistent, automated feedback loop that prevents YAML bugs before they reach production.
Check your own text — free
Paste a commit message, PR description, or code comment into the free Lint grammar checker. It proofreads the prose and leaves identifiers, commands, and fenced code blocks untouched — no signup needed for your first checks.
📌 Prices and tool count in this article may be outdated. Lint now ships 16 tools with Pro at $12/mo, or $60/year. See the current pricing page.
Stop letting Grammarly break your code
17 AI tools built for developers. Code-aware parsing.
Or upgrade to Pro for 500 checks a day · All tools · No ads