[英]Eslint: warning File ignored by default. Use a negated ignore pattern
我是使用 Eslint 的新手。
到目前为止,我已经在本地项目中安装了 Eslint 并进行了配置。 eslintrc.js 文件包含
module.exports = {
env: {
node: true,
commonjs: true,
es6: true,
mocha: true,
},
extends: [
'airbnb-base',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
},
rules: {
},
};
在 package.json 我有
"scripts": {
"lint": "eslint .eslintrc.js --fix",
}
在终端我跑
npm run lint
输出是
> apigateway@1.0.0 lint C:\nodeprojects\restapi
> eslint .eslintrc.js --fix
C:\nodeprojects\restapi\.eslintrc.js
0:0 warning File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'") to override
但如果我跑
eslint <foldername> --fix
然后就可以了。
我正在使用 webstorm IDE 和 windows 操作系统。
非常感谢任何帮助。
您的 npm 脚本在.eslintrc.js
文件上运行 linter,并且该文件正如注释中所说的File ignored by default.
您需要从以下位置更改 lint 脚本:
"lint": "eslint .eslintrc.js --fix",
至:
"lint": "eslint <foldername> --fix"
其中<foldername>
是正确的文件夹。
我遇到了这个问题,其中 pre-commit Husky 钩子在尝试提交合并时会尝试扫描此文件(之前有人更改了 .eslintrc.js),然后这将导致团队成员本地环境中的合并提交失败(文件被忽略默认)
您可以在.eslintrc.js
旁边创建一个.eslintignore
文件。 然后在 .eslintignore 中输入:
!.eslintrc.js
还要记住 ESlint 默认行为是忽略以.
- https://github.com/eslint/eslint/issues/10341 。
例如,如果你想对.storybook
文件夹进行 lint,ESLint 默认会忽略它。 要对其进行 lint, .eslintrc.js
必须包括:
{
...
// Lint ".storybook" folder (don't ignore it)
"ignorePatterns": ["!.storybook"],
...
}
由于默认的 ESLint 行为,我在我的所有项目中都这样做(从根目录对整个项目进行 lint):
{
...
// ESlint default behaviour ignores file/folders starting with "." - https://github.com/eslint/eslint/issues/10341
"ignorePatterns": ["!.*", "dist", "node_modules"],
...
}
我首先不忽略任何以.
然后我排除了我实际上想要忽略的文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.