javascript - (ESLint) 找不到规则 'react/jsx-sort-prop-types' 的定义

标签 javascript visual-studio visual-studio-2017 eslint

我刚刚更新了我的 VS 2017(版本 15.8.2)。现在,当我打开任何 .js 文件时,我会在文件的第一行看到一条红色波浪线...这是警告消息:

Definition for rule 'react/jsx-sort-prop-types' was not found

enter image description here

当我将鼠标悬停在波浪线上时:

enter image description here

我不确定为什么突然出现这么多 .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 按钮:

enter image description here

重置 .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/

相关文章:

c# - 调试时模拟丢失的对象

git - 如何在更改事件的 Git 存储库时阻止 Visual Studio 关闭解决方案

c# - VS2017 - C#7 语言功能在 MVC View 中不起作用

c# - 通过 Selenium 检查 SelectElement 元素中是否存在选项

visual-studio-2017 - 如何在Visual Studio 2017中更改括号突出显示的颜色?

javascript - 如何访问 XMLHttpRequest 中的类方法?

javascript - 尝试复制 json 数据时出现 TypeError js

javascript - HighCharts - 条形图在 IE8 中无法正确呈现

javascript - angularJS 为什么 $scope.$watch 不能工作?

c# - cmake build x64 使用安装的任何 visual studio 版本