简体   繁体   English

从 package.json 作为脚本运行时出现 ESLint 错误

[英]ESLint errors when running as script from package.json

I am able of running ESLint from the command line using:我可以使用以下命令从命令行运行 ESLint:

./node_modules/.bin/eslint "src/**/*.js"

When I try to add this statements to the scripts section in my package.json as:当我尝试将此语句添加到我的 package.json 中的脚本部分时,如下所示:

"lint": "eslint src/**/*.js",

It does run and give the correct output but then crashes.它确实运行并给出正确的 output 但随后崩溃。 I am guessing it has to do with the quotation marks that are there if I do not run it as a package.json script.如果我不将它作为 package.json 脚本运行,我猜它与那里的引号有关。

How can I add a script to my package.json that runs eslint for all JavaScript files in my src/ directory?如何将脚本添加到我的 package.json 以对我的 src/ 目录中的所有 JavaScript 文件运行 eslint?

经过进一步研究(我可能会考虑使用Google中的所有搜索),当这是从npm作为脚本运行时,这是ESLint的正常行为: https : //github.com/eslint/eslint/issues/7933

试试吧:

"lint": "eslint -c .eslintrc ./src/"

只需使用单引号:

"lint": "eslint 'src/**/*.js'"

You can also use this pattern to run on the specific file extensions您还可以使用此模式在特定文件扩展名上运行

"lint": "eslint \"src/**/*.{js,jsx}\"" // default config file .eslintrc.js or .eslintrc.json 

If you want to use a specific config file then use the following pattern如果要使用特定的配置文件,请使用以下模式

"lint": "eslint \"src/**/*.{ts,tsx,jsx}\" --config ./.eslintrc.ui.js"

You can use something like this to run lint and to fix the linting issue automatically.您可以使用类似这样的东西来运行 lint 并自动修复 linting 问题。

"lint": "eslint 'src/**/*.js'"
"lintfix": "eslint 'src/**/*.js' --fix"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM