简体   繁体   English

使Intellij IDEA处理ESLint配置中定义的全局JS变量

[英]Make Intellij IDEA handle global JS variables defined in ESLint config

I define some global variables in my project's .eslintrc , and this config file is detected correctly by ESLint when I run ESLint as a script. 我在项目的.eslintrc定义了一些全局变量,当我将ESLint作为脚本运行时,ESLint会正确检测到此配置文件。

Now, I would like to configure IntelliJ IDEA so that its JavaScript inspector notices that I have defined these global variables in .eslintrc , and doesn't bother me with "Missing import statement" warnings for these variables. 现在,我想配置IntelliJ IDEA,以便它的JavaScript检查器注意到我已经在.eslintrc定义了这些全局变量,并且不会因为这些变量的“Missing import statement”警告而烦恼。

For example, both ReactDOM and React are global variables defined in my .eslintrc , so I would like the warnings in this screenshot to disappear: 例如, ReactDOMReact都是我的.eslintrc定义的全局变量,所以我希望此屏幕截图中的警告消失:

缺少导入语句截图

FYI, the JavaScript language version selected in the project settings is "React JSX (JSX in ECMAScript 6)". 仅供参考,在项目设置中选择的JavaScript语言版本是“React JSX(ECMAScript 6中的JSX)”。

As far as I know, ESlint is configured correctly in the settings: 据我所知,ESlint在设置中配置正确:

IntelliJ IDEA设置截图

What am I missing? 我错过了什么?

(I am using the currently latest version of IntelliJ IDEA: 2016.3.4) (我使用的是当前最新版本的IntelliJ IDEA:2016.3.4)

ESLint configuration doesn't affect IDEA own inspections; ESLint配置不会影响IDEA自己的检查; you need to suppress 'Missing Import statement' inspection using Alt+Enter , Right , 'Suppress for statement' ; 你需要使用Alt+EnterRight'Suppress for statement'来禁止'缺少导入语句'检查;

there is a feature request to respect env and globals from .eslintrc - see https://youtrack.jetbrains.com/issue/WEB-21957 .eslintrc有一个尊重envglobals的功能请求 - 请参阅https://youtrack.jetbrains.com/issue/WEB-21957

You can turn off the inspections by hand that generate the above message. 您可以手动关闭检查以生成上述消息。 The one you are looking for is found here: 您正在寻找的那个在这里找到:

  • Go to preferences, and select Editor > Inspections 转到首选项,然后选择“编辑器”>“检查”
  • Type "missing" in the search field 在搜索字段中输入“missing”
  • Click the "collapse all" icon next to the search field and find the root node of JavaScript (with the ▶︎ in front) 单击搜索字段旁边的“全部折叠”图标,找到JavaScript的根节点(前面带有▶))
  • Under "General" is "Missing import statement"; 在“一般”下是“缺少进口声明”; Uncheck it 取消选中它
  • You might want to uncheck others.. 你可能想要取消选中其他人..

If you use a well configured eslint and .editorconfig you arguably don't need IDEA's own inspections for Javascript at all. 如果您使用配置良好的eslint和.editorconfig,您可能根本不需要IDEA自己的Javascript检查。 I have it setup like this: 我有这样设置:

  • Backup your project .idea folder (it's hidden, found in the root of your project) 备份您的项目.idea文件夹(它隐藏,在项目的根目录中找到)
  • Go to preferences, and select Editor > Inspections 转到首选项,然后选择“编辑器”>“检查”
  • Click the "collapse all" icon next to the search field and find the root node of JavaScript (with the ▶︎ in front) 单击搜索字段旁边的“全部折叠”图标,找到JavaScript的根节点(前面带有▶))
  • Click the checkbox directly to the right of it, so all JavaScript inspections are OFF 单击右侧的复选框,以便所有JavaScript检查都关闭
  • Now scroll down a bit until you see Code quality tools and ESlint 现在向下滚动一下,直到看到Code quality toolsESlint
  • Select the checkbox to the right. 选中右侧的复选框。 Now ESLint is your only active JS inspection. 现在,ESLint是您唯一的主动JS检查。
  • In the top-left of the Preferences window, type editorconfig and make sure you have the plugin active, together with an .editorconfig file . 在“首选项”窗口的左上角,键入editorconfig并确保将插件与.editorconfig文件一起激活。
  • Apply and OK 申请并确定

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

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