我刚刚更新了我的 VS 2017(版本 15.8.2)。现在,当我打开任何 .js 文件时,我会在文件的第一行看到一条红色波浪线...这是警告消息:
Definition for rule 'react/jsx-sort-prop-types' was not found
当我将鼠标悬停在波浪线上时:
我不确定为什么突然出现这么多 .js 错误?
最佳答案
ESLint (这是一个 JS 代码分析器)在 VS 2017 中默认启用 - 来自 version 15.8 :
ESLint support: ESLint support has been reimplemented in this release. So, Visual Studio will now lint JavaScript files as you edit. 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. 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 编码指南,那么你需要做的就是重置全局 .eslintrc 文件。在 VS 中转到:
工具 > 选项 > 文本编辑器 > JavaScript/TypeScript > Linting
然后点击重置全局 .eslintrc 按钮:
重置 .eslintrc 将修复您的设置文件(它导入 react 插件)
注意VS自带的默认插件是react plugin ,这并不意味着您正在使用 react.js,而是意味着您正在使用 React 编码指南。
另请注意,上述步骤将 react 插件导入到设置中,并正确设置了 ESLint,但您可能仍然会遇到很多 .js 样式错误,因为您可能还没有遵循 React 编码指南或您项目中包含的一些 .js 库不遵循指南(如果 .js 文件未在 VS 中打开,则可能不会出现 linting 错误,打开几个 .js 文件并重新编译以获得 linting 错误)。
例如,我在 jquery.validate.js
上遇到了一些样式错误。您可能不想更改 jquery.validate.js
代码,请参阅 this question关于如何配置 ESLint 以忽略某些 .js 文件。
如果您不想对您的项目进行所有修改,您可以禁用 ESLint,如上图所示。
如果你想使用不同的插件,这是 full list预定义的插件。
关于javascript - (ESLint) 找不到规则 'react/jsx-sort-prop-types' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52158695/