Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

eslint --fix runs but the errors are still there

Erroreslint --fix exits with code 1 and prints the same errors

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

  • Applies to ESLint 9, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 1500
  2. 2Match what you see, then jump to its fix

    1. 1The problem is reported in the output with a rule name and survives the fix run.The rule has no auto-fixFix
    2. 2Your editor shows a light-bulb for the problem, but the command line leaves it.The rule only offers suggestionsFix
    3. 3Layout problems get fixed and others do not, or the other way round.A --fix-type filter limits what is appliedFix
    4. 4ESLint 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

What does the error look like?

  • eslint --fix exits with code 1 and prints the same errors
  • files 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 -c

2Fix

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 src

Confirmed by eslint.org

Did this fix it?

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 suggestions

2Fix

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 line

3Verify

Re-run eslint; the problem should be gone.

npx eslint src

Confirmed by eslint.org

Did this fix it?

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

2Fix

Remove the filter, or list every type you want.

npx eslint --fix --fix-type problem,suggestion,layout src

3Verify

Run the script again.

npx eslint src

Confirmed by eslint.org

Did this fix it?

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 --fix

2Fix

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 json

3Verify

Run npx eslint --fix on the real files and check git diff.

npx eslint --fix src && git diff --stat

Confirmed by eslint.org

Did this fix it?

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.