Applying automatic fixes with ESLint in npm scripts

I’m stuck trying to set up an npm script for auto-fixing linting issues. My current lint script works fine:

"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"

But when I add a fix script like this:

"fix-lint": "eslint --fix --ext .js,.vue src test/unit/specs test/e2e/specs"

It shows errors without fixing anything. What am I doing wrong? The command runs but exits with code 1. Any ideas how to make it actually apply fixes?

hey liamj, have u tried running the fix command with --quiet flag? like this:

"fix-lint": "eslint --fix --quiet --ext .js,.vue src test/unit/specs test/e2e/specs"

it might suppress the error output and just apply fixes. worth a shot!

I’ve encountered a similar issue before. The problem might be that some errors can’t be automatically fixed by ESLint. Try running the fix command with the ‘–debug’ flag to get more detailed output. This can help identify which errors are causing the script to fail.

Another approach is to separate the fixing and reporting steps. You could create two scripts:

\"fix\": \"eslint --fix --ext .js,.vue src test/unit/specs test/e2e/specs\",
\"lint\": \"eslint --ext .js,.vue src test/unit/specs test/e2e/specs\"

Run ‘fix’ first, then ‘lint’ to see remaining issues. This way, you’ll apply all possible automatic fixes before reviewing any remaining errors manually.

As someone who’s dealt with ESLint in various projects, I can tell you that the --fix flag doesn’t always work miracles. Sometimes, the errors that remain are ones that ESLint can’t automatically fix.

What I’ve found helpful is to run the fix command with the --max-warnings flag set to a high number. This allows the command to complete successfully while still applying fixes:

"fix-lint": "eslint --fix --max-warnings 9999 --ext .js,.vue src test/unit/specs test/e2e/specs"

This way, you’ll see which issues were fixed and which ones need manual attention. It’s not perfect, but it’s a good starting point for cleaning up your code. Remember, some lint errors require human judgment to resolve properly.