简体   繁体   English

ESLint不忽略.eslintrc.json中给定的全局变量

[英]ESLint not ignoring global variables given in .eslintrc.json

I am trying to get eslint to ignore a file I'm importing globally using webpack.ProvidePlugin , yet the file is still being linted. 我试图让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"

And yet I am still getting hundreds of linting errors from google.js. 但是,我仍然从google.js收到数百个掉毛错误。 It's minified but the webpack docs say that though that's preferred it probably isn't necessary and also the eslint docs don't mention it at all. 它被最小化了,但是webpack文档说,尽管这是首选,但它可能不是必需的,eslint文档也根本没有提到它。

I've also tried the comment style of ignoring mentioned in the docs 我还尝试了文档中提到的忽略评论的样式

//google.js
/*global google:true*/

Why is ESLint still giving me all of these linting errors? 为什么ESLint仍然给我所有这些掉毛错误?

The global option only refers to using a global variable and has no effect on whether a file is linted or not. 全局选项仅指使用全局变量,对文件是否被删除没有影响。

If you don't want to lint a specific file, you can use a .eslintignore file to exclude files matching a pattern from the linting process. 如果您不希望皮棉特定文件,则可以使用.eslintignore文件从皮棉过程中排除与模式匹配的文件。 It is very similar to a .gitignore . 它与.gitignore非常相似。

You probably want to exclude all vendor files, so you can use the pattern suggested in Ignoring files from linting . 您可能希望排除所有供应商文件,因此可以使用“ 从linting忽略文件”中建议的模式。

**/vendor/*.js

This will give you a warning for the files that are being ignored, because you're using a glob, which gets expanded by your shell and therefore you are explicitly passing the file to ESLint (see Ignored File Warnings ). 这将给您一个有关被忽略的文件的警告,因为您使用的是glob,shell会对其进行扩展,因此您将文件明确传递给ESLint(请参阅忽略的文件警告 )。 You can get rid of that warning by passing a directory instead, and ESLint will lint every JavaScript file in the directory, so your glob is not needed. 您可以通过传递目录来消除该警告,ESLint会整理目录中的每个JavaScript文件,因此不需要您的glob。

"lint": "eslint js/ webpack.config.js"

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

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