ESLint 不忽略 .eslintrc.json 中给出的全局变量
ESLint not ignoring global variables given in .eslintrc.json
我正在尝试让 eslint 忽略我正在使用 webpack.ProvidePlugin
全局导入的文件,但该文件仍在检查。
//file arrangement
- vendor
`- google.js
- ...
- webpack.config.js
//relevant webpack configurations
resolve: {
extensions: ['.js', '.json'],
alias: {
'google': path.resolve(__dirname, './vendor/google.js')
}
},
....
plugins: [
new webpack.ProvidePlugin({
'google': 'google'
})
]
/*google is successfully available globally*/
//.eslintrc.json
{
"extends": ["standard", "standard-react"],
"globals": {
"google": true
}
}
//package.json script
"dev": "webpack-dev-server --port 5888",
...
"lint": "eslint js/**/*.js webpack.config.js"
然而我仍然从 google.js 收到数百个 linting 错误。它被缩小了,但是 webpack 文档说虽然这是首选,但可能没有必要,而且 eslint 文档根本没有提到它。
我也尝试过the docs
中提到的忽略评论方式
//google.js
/*global google:true*/
为什么 ESLint 仍然给我所有这些 linting 错误?
global option仅指使用全局变量,对文件是否lint没有影响
如果您不想对特定文件进行 lint,可以使用 .eslintignore
文件从 linting 过程中排除与模式匹配的文件。它与 .gitignore
.
非常相似
您可能想要排除所有供应商文件,因此您可以使用 Ignoring files from linting 中建议的模式。
**/vendor/*.js
这会给你一个关于被忽略的文件的警告,因为你正在使用一个 glob,它会被你的 shell 扩展,因此你明确地将文件传递给 ESLint(见 Ignored File Warnings).您可以通过传递一个目录来消除该警告,ESLint 将检查目录中的每个 JavaScript 文件,因此不需要您的 glob。
"lint": "eslint js/ webpack.config.js"
我正在尝试让 eslint 忽略我正在使用 webpack.ProvidePlugin
全局导入的文件,但该文件仍在检查。
//file arrangement
- vendor
`- google.js
- ...
- webpack.config.js
//relevant webpack configurations
resolve: {
extensions: ['.js', '.json'],
alias: {
'google': path.resolve(__dirname, './vendor/google.js')
}
},
....
plugins: [
new webpack.ProvidePlugin({
'google': 'google'
})
]
/*google is successfully available globally*/
//.eslintrc.json
{
"extends": ["standard", "standard-react"],
"globals": {
"google": true
}
}
//package.json script
"dev": "webpack-dev-server --port 5888",
...
"lint": "eslint js/**/*.js webpack.config.js"
然而我仍然从 google.js 收到数百个 linting 错误。它被缩小了,但是 webpack 文档说虽然这是首选,但可能没有必要,而且 eslint 文档根本没有提到它。
我也尝试过the docs
中提到的忽略评论方式//google.js
/*global google:true*/
为什么 ESLint 仍然给我所有这些 linting 错误?
global option仅指使用全局变量,对文件是否lint没有影响
如果您不想对特定文件进行 lint,可以使用 .eslintignore
文件从 linting 过程中排除与模式匹配的文件。它与 .gitignore
.
您可能想要排除所有供应商文件,因此您可以使用 Ignoring files from linting 中建议的模式。
**/vendor/*.js
这会给你一个关于被忽略的文件的警告,因为你正在使用一个 glob,它会被你的 shell 扩展,因此你明确地将文件传递给 ESLint(见 Ignored File Warnings).您可以通过传递一个目录来消除该警告,ESLint 将检查目录中的每个 JavaScript 文件,因此不需要您的 glob。
"lint": "eslint js/ webpack.config.js"