Skip to content
Latchkey

stylelint --fix: Autofix Stylesheets

stylelint --fix edits your stylesheets in place to resolve every problem from a rule that supports automatic fixing.

Many stylelint rules can fix themselves. The --fix flag applies those, leaving only the problems that need human judgement.

What it does

stylelint --fix runs the rules and writes corrected files back to disk for rules that implement a fixer (spacing, casing, quotes, ordering, and more). Problems from rules without a fixer remain and still affect the exit code.

Common usage

Terminal
npx stylelint "src/**/*.css" --fix
# fix and only fail if unfixable problems remain
npx stylelint "src/**/*.scss" --fix --max-warnings 0
# faster repeat runs
npx stylelint "**/*.css" --fix --cache

Flags

FlagWhat it does
--fixApply automatic fixes in place
--cacheSkip files that did not change
--max-warnings 0Still fail if unfixable warnings remain
--allow-empty-inputDo not error on an empty glob

In CI

Run --fix in a dedicated formatting job that commits the result, or run it locally via a pre-commit hook. In a gate job, run stylelint without --fix and let it fail, so the pipeline does not silently mutate the checkout under test.

Common errors in CI

A run that exits non-zero after --fix means problems remain from rules with no fixer; those need manual edits. If --fix appears to change nothing, the failing rules simply do not support autofix. On read-only mounts, --fix errors with EACCES writing the file.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →