How to run eslint --fix from npm script

JavascriptNpmEslintNpm Scripts

Javascript Problem Overview


I am trying to add lint-fix in my package.json. My basic lint is "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"

I did try "lint-fix": "eslint --fix --ext .js,.vue src test/unit/specs test/e2e/specs" but it is throwing my errors but not fixing them.

What do I have to change?

The error from NPM is:

217 problems (217 errors, 0 warnings)
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run-script" "lint-fix"
npm ERR! node v5.10.1
npm ERR! npm v3.8.3
npm ERR! code ELIFECYCLE
npm ERR! quasar-app@0.0.1 lint-fix: eslint --fix --ext .js,.vue src
npm ERR! Exit status 1
npm ERR! but it is caused by exit code 1 which is result of finding errors.

Javascript Solutions


Solution 1 - Javascript

You can run below command:

npm run lint -- --fix

Solution 2 - Javascript

You can add a new command in package.json.

"scripts": {
    "lint": "eslint --fix --ext .js,.jsx ."
}

And then you can run it in terminal npm run lint.

Solution 3 - Javascript

To add a new separate script to auto-fix the linting issues for files with extensions .js and .jsx, you may add the add the script in your package.json as below:

"lint:fix": "eslint --fix --ext .js,.jsx ."

So after adding the above command the scripts section of your package.json may look like as below:

...
....
"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject",
  "lint": "eslint .",
  "lint:fix": "eslint --fix --ext .js,.jsx ."
},
....
...

To run the newly added script to auto-fix the linting issues on the command line you should run the command like as below:

npm run lint:fix

Solution 4 - Javascript

Try

./node_modules/.bin/eslint --fix .

Solution 5 - Javascript

This is what I use:

npx eslint --fix . 

It fixes all files.

Solution 6 - Javascript

eslint auto-correct-command. It fixes all issues for me.

To check the errors first:

npx eslint .

To fix the issues for all files (auto-correct options)

npx eslint --fix .

Solution 7 - Javascript

I have used this:

 npm run lint -- --fix  

I have sourced it in this website

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarek UrbanowiczView Question on Stackoverflow
Solution 1 - Javascriptkallayya HiremathView Answer on Stackoverflow
Solution 2 - JavascriptVlad BîcuView Answer on Stackoverflow
Solution 3 - JavascriptRahul GuptaView Answer on Stackoverflow
Solution 4 - JavascriptSahilgrewalhereView Answer on Stackoverflow
Solution 5 - JavascriptCoder Gautam YTView Answer on Stackoverflow
Solution 6 - JavascriptMahbub AlamView Answer on Stackoverflow
Solution 7 - JavascriptJhune Carlo TrogelioView Answer on Stackoverflow