eslint --fix: automatically fix lint problems
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
- tool
- ESLint
- command
- eslint
- flag
- --fix
- default
- off
npx eslint . --fix runs ESLint and rewrites the files to apply every fix that the reported rules can make safely, for example turning let into const (prefer-const). Problems without an automatic fix stay in the report, and the exit status is still 1 if any error remains.
Before and after
npm init -y >/dev/null && npm pkg set type=module
npm install --silent --no-audit --no-fund eslint@10 >/dev/null 2>&1
cat > eslint.config.js <<'JS'
export default [{ rules: { "prefer-const": "error", "no-extra-semi": "off", "eqeqeq": "error" } }];
JS
printf 'let total = 1 + 2;\nif (total == 3) console.log(total);\n' > app.js
npx eslint app.js; echo "exit status: $?"
npx eslint app.js --fix; echo "exit status after --fix: $?"
cat app.jsOutput
/tmp/work/app.js 1:5 error 'total' is never reassigned. Use 'const' instead prefer-const 2:11 error Expected '===' and instead saw '==' eqeqeq ✖ 2 problems (2 errors, 0 warnings) 1 error and 0 warnings potentially fixable with the `--fix` option. exit status: 1 /tmp/work/app.js 2:11 error Expected '===' and instead saw '==' eqeqeq ✖ 1 problem (1 error, 0 warnings) exit status after --fix: 1 const total = 1 + 2; if (total == 3) console.log(total);
prefer-const was fixed automatically; eqeqeq has no automatic fix because changing == to === can change behaviour, so it is still reported.
Related options
| Option | Effect |
|---|---|
| --fix | apply fixes and write the files |
| --fix-dry-run | compute fixes without writing (use with --format json) |
| --fix-type problem,suggestion,layout | apply only these kinds of fixes |
| --max-warnings 0 | also fail when warnings remain |
| --cache | only lint files that changed since the last run |
Sources
Related pages
commands · prettierprettier --write and --check: format files from the command lineFormat a project with npx prettier . --write, or fail CI on unformatted files with npx prettier . --check. Configure it with .prettierrc and .prettierignore.config · vitevite.config server.proxy: proxy API calls in the dev serverserver.proxy in vite.config.js forwards dev-server requests such as /api to a backend to avoid CORS in development. Targets, rewrite, changeOrigin, ws.errors · reactEach child in a list should have a unique "key" propReact warns Each child in a list should have a unique "key" prop when map() returns elements without key. Use a stable id from your data, not the index.