ruff check --fix: Auto-Fix Lint Violations
ruff check --fix rewrites files to resolve every violation that has a safe automatic fix.
Most lint noise (unused imports, sort order, simple rewrites) has a fix Ruff can apply for you. --fix does it; the rest still needs a human.
What it does
ruff check --fix lints, applies every safe fix it can, and writes the changed files back to disk. It then reports any violations that remain and exits non-zero if any are left. Violations without a safe fix are listed but untouched.
Common usage
ruff check --fix .
# fix and show a unified diff of what changed
ruff check --fix --diff .
# preview the fixes without writing files
ruff check --fix --diff --no-cache .Flags
| Flag | What it does |
|---|---|
| --fix | Apply safe fixes and write files in place |
| --diff | Print the fixes as a diff instead of (with --fix) or alongside applying |
| --fix-only | Apply fixes but do not report remaining violations |
| --unsafe-fixes | Also apply fixes marked unsafe |
| --show-fixes | List each fix that was applied |
In CI
CI should not run --fix on a branch and silently commit; instead run ruff check . (no fix) so unfixed violations fail the build, and let developers run --fix locally. If you do auto-fix in a workflow, gate on git diff afterward so an automated change is reviewed.
Common errors in CI
A surprising exit code 1 after --fix means there were violations with no safe fix, or that need --unsafe-fixes; the remaining count is printed. Files modified by --fix in CI but not committed cause a downstream "working tree dirty" failure. Note --fix only applies fixes Ruff considers safe; many rules have no autofix at all.