Skip to content
Latchkey

yamllint "wrong indentation" error in CI

yamllint's indentation rule enforces a fixed step (2 spaces by default). A line indented by a different amount, or a tab, triggers "wrong indentation: expected N but found M".

What this error means

yamllint reports "wrong indentation: expected N but found M (indentation)" on a nested key or list item. The file may still parse, but the style rule fails the job.

yamllint
deploy.yml
  5:5       error    wrong indentation: expected 4 but found 5 (indentation)

Common causes

Inconsistent space counts between nested levels

One block uses 2 spaces and another uses 3 or 5, so a child sits at an offset the indentation rule does not allow.

A tab character standing in for spaces

An editor inserted a tab; YAML forbids tabs for indentation and yamllint flags the resulting width as wrong.

How to fix it

Normalize to the configured step

  1. Set your editor to insert 2 spaces per indent and never tabs.
  2. Re-indent the flagged block to a multiple of the step.
  3. Re-run yamllint to confirm the rule passes.
.yamllint
# yamllint config: allow a consistent 2-space step
rules:
  indentation:
    spaces: 2
    indent-sequences: true

Convert tabs to spaces

Expand any leading tabs to spaces so widths are computed consistently.

Terminal
sed -i 's/\t/  /g' deploy.yml

How to prevent it

  • Add an .editorconfig enforcing 2-space indent for *.yml.
  • Run yamllint in a pre-commit hook to catch drift before CI.
  • Never mix tabs and spaces in YAML files.

Frequently asked questions

What causes ""wrong indentation: expected N but found M""?
One block uses 2 spaces and another uses 3 or 5, so a child sits at an offset the indentation rule does not allow.
How do I fix "wrong indentation: expected N but found M"?
Normalize to the configured step

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card