简体   繁体   English

(ESLint) 未找到规则“re​​act/jsx-sort-prop-types”的定义

[英](ESLint) Definition for rule 'react/jsx-sort-prop-types' was not found

I have just updated my VS 2017 (version 15.8.2).我刚刚更新了我的 VS 2017(版本 15.8.2)。 Now when I open any .js file, I see a red squiggly line on the first line of the file... this is the warning message:现在,当我打开任何.js 文件时,我会在文件的第一行看到一条红色波浪线……这是警告消息:

Definition for rule 'react/jsx-sort-prop-types' was not found未找到规则“re​​act/jsx-sort-prop-types”的定义

在此处输入图片说明

and when I hover over the squiggly line:当我将鼠标悬停在波浪线上时:

在此处输入图片说明

I am not sure why suddenly I am getting so many .js errors?我不知道为什么我突然收到这么多 .js 错误?

ESLint (which is a JS code analyzer) is enabled by default in VS 2017 - from version 15.8 : ESLint (这是一个 JS 代码分析器)在 VS 2017 中默认启用 - 从版本 15.8 开始

ESLint support: ESLint support has been reimplemented in this release. ESLint 支持:此版本中重新实现了 ESLint 支持。 So, Visual Studio will now lint JavaScript files as you edit.因此,Visual Studio 现在将在您编辑时对 JavaScript 文件进行 lint。 ESLint has been updated to use ESLint 4 by default, but if your project has a local installation of ESLint, it will use that version instead. ESLint 已更新为默认使用 ESLint 4,但如果您的项目在本地安装了 ESLint,它将改用该版本。 You can easily disable ESLint globally in VS by unchecking the “Enable ESLint” setting in the “Tools / Options” dialog in the location shown below.您可以通过取消选中下图所示位置的“工具/选项”对话框中的“启用 ESLint”设置,轻松地在 VS 中全局禁用 ESLint。

If you want to use ESLint coding guideline, then all you need to do is to Reset global .eslintrc file.如果你想使用 ESLint 编码指南,那么你需要做的就是重置全局 .eslintrc 文件。 In VS go to:在 VS 中转到:

Tools > Options > Text Editor > JavaScript/TypeScript > Linting工具 > 选项 > 文本编辑器 > JavaScript/TypeScript > Linting

And click on Reset global .eslintrc button:然后点击重置全局 .eslintrc按钮:

在此处输入图片说明

Resetting .eslintrc will fix your settings file (it imports react plugin)重置 .eslintrc 将修复您的设置文件(它导入 react 插件)

Note that the default plugin which comes with VS is react plugin , this does not mean that you are using react.js , but it means you are using react coding guidelines.请注意,VS 附带的默认插件是react plugin这并不意味着您正在使用react.js ,而是意味着您正在使用 react 编码指南。

Also note that, the above step imports react plugin into the setting, and sets up ESLint correctly, but you would probably still get a lot of .js styling errors, because you probably have not been following react coding guideline or some of the .js libraries that you have included in your project do not follow the guideline (the linting errors may not appear if the .js files are not open in VS, open a couple .js files and recompile to get the linting errors).另请注意,上述步骤将 react 插件导入到设置中,并正确设置了 ESLint,但您可能仍然会遇到很多 .js 样式错误,因为您可能没有遵循 react 编码指南或某些 .js您在项目中包含的库不遵循该指南(如果 .js 文件未在 VS 中打开,则可能不会出现 linting 错误,打开几个 .js 文件并重新编译以获取 linting 错误)。

As an example, I was getting some styling error on jquery.validate.js .例如,我在jquery.validate.jsjquery.validate.js了一些样式错误。 You probably don't want to change jquery.validate.js code, see this question on how to configure ESLint to ignore certain .js files.你可能不希望改变jquery.validate.js代码,请参阅这个问题如何ESLint配置忽略某些.js文件。


If you don't want to make all the modifications to your project, you can disable ESLint as shown in the picture above.如果您不想对项目进行所有修改,您可以禁用 ESLint,如上图所示。

If you want to use a different plugin, this is the full list of predefined plugins.如果您想使用不同的插件,这是预定义插件的完整列表

This just means that ESLint does not match the configuration found on .eslintrc file.这只是意味着 ESLint 与 .eslintrc 文件中的配置不匹配。

Clicking the "Reset global .eslintrc" button will fix it.单击“重置全局 .eslintrc”按钮将修复它。 It will reset your .eslintrc file to match with what ever required configuration of the ESLint installed on VS.它将重置您的 .eslintrc 文件以匹配安装在 VS 上的 ESLint 所需的配置。

在此处输入图片说明

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

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