Skip to content

/flags/eslint/eslint-fix

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

bash
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.js

Output

/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.

OptionEffect
--fixapply fixes and write the files
--fix-dry-runcompute fixes without writing (use with --format json)
--fix-type problem,suggestion,layoutapply only these kinds of fixes
--max-warnings 0also fail when warnings remain
--cacheonly lint files that changed since the last run

Sources