如何 运行 eslint --fix 来自 npm 脚本

How to run eslint --fix from npm script

我正在尝试在我的 package.json 中添加 lint-fix。 我的基本 lint 是 "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"

我确实尝试了 "lint-fix": "eslint --fix --ext .js,.vue src test/unit/specs test/e2e/specs" 但它抛出了我的错误但没有修复它们。

我需要更改什么?

NPM 的错误是:

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.

您可以运行以下命令:

npm run lint -- --fix

您可以在 package.json 中添加新命令。

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

然后你可以 运行 在终端 npm run lint

要添加新的单独脚本来自动修复扩展名为 .js.jsx 的文件的 linting 问题,您可以在 package.json 中添加脚本,如下所示:

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

因此,在添加上述命令后,您的 package.json 的脚本部分可能如下所示:

...
....
"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 ."
},
....
...

为了 运行 新添加的脚本自动修复命令行上的 linting 问题,你应该 运行 命令如下:

npm run lint:fix

尝试

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

这是我用的:

npx eslint --fix . 

它修复了所有文件。

我用过这个:

 npm run lint -- --fix  

我在这个 website

中找到了它

eslint auto-correct-command。它为我解决了所有问题。

先检查错误:

npx eslint .

修复所有文件的问题(auto-correct 选项)

npx eslint --fix .