eslint --fix runs but the errors are still there
eslint --fix exits with code 1 and prints the same errorsShort answer
ESLint fixes only what a rule can fix safely. Rules without the wrench mark in the rules reference have no fixer, and suggestions never apply from the CLI. Also check for a --fix-type filter, piped input and processors. Run eslint with --fix-dry-run and --format json to see what it would change.
Fix it fast
1Find out which cause you have
Ask ESLint what it would change, in a format that prints the fixes.
npx eslint --fix-dry-run --format json src | head -c 15002Match what you see, then jump to its fix
- 1
The problem is reported in the output with a rule name and survives the fix run.The rule has no auto-fixFix - 2
Your editor shows a light-bulb for the problem, but the command line leaves it.The rule only offers suggestionsFix - 3
Layout problems get fixed and others do not, or the other way round.A --fix-type filter limits what is appliedFix - 4
ESLint errors out when you pipe code with --fix, or file types handled by a processor never change.The code is piped in, or goes through a processorFix
- 1
What does the error look like?
eslint --fix exits with code 1 and prints the same errorsfiles are unchanged after eslint --fix
Cause 1 of 4
The rule has no auto-fix
1Check
ESLint documents that not all problems are fixable. Rules that can fix are marked with a wrench in the rules reference; others need a manual edit.
npx eslint src --format json | grep -o '"ruleId":"[^"]*"' | sort | uniq -c2Fix
Edit the code by hand for those rules, or turn the rule off or down if it does not suit the project.
// eslint.config.js
export default [
{ rules: { 'no-unused-vars': 'warn' } },
];3Verify
Run the linter again.
npx eslint srcConfirmed by eslint.org
Cause 2 of 4
The rule only offers suggestions
1Check
Suggestions can change application logic, so the CLI cannot apply them; they are available through editor integrations. These rules are marked with a bulb in the rules reference.
npx eslint src --format json | grep -c suggestions2Fix
Apply the suggestion from the editor's quick-fix menu, or edit the code yourself.
# no command: editor quick fix (light bulb) on the flagged line3Verify
Re-run eslint; the problem should be gone.
npx eslint srcConfirmed by eslint.org
Cause 3 of 4
A --fix-type filter limits what is applied
1Check
--fix-type restricts fixes to problem, suggestion, layout or directive. Look in package.json scripts and CI files for it.
grep -rn "fix-type" package.json .github 2>/dev/null2Fix
Remove the filter, or list every type you want.
npx eslint --fix --fix-type problem,suggestion,layout src3Verify
Run the script again.
npx eslint srcConfirmed by eslint.org
Cause 4 of 4
The code is piped in, or goes through a processor
1Check
The CLI docs state that --fix throws an error when code is piped to ESLint and has no effect on code that uses a processor, unless the processor allows autofixes.
cat src/app.js | npx eslint --stdin --fix2Fix
Run --fix on files on disk. To see fixes for piped input, use --stdin with --fix-dry-run and a JSON format.
cat src/app.js | npx eslint --stdin --fix-dry-run --format json3Verify
Run npx eslint --fix on the real files and check git diff.
npx eslint --fix src && git diff --statConfirmed by eslint.org
How do I stop it coming back?
- Read the wrench and bulb marks in the rules reference before you rely on --fix in CI.
- Keep one lint script in package.json so editor, CI and the terminal run the same flags.
- Commit before a big --fix run so the diff shows what changed.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix