javascript - 关闭 ESLint 规则(在 React 应用程序中,使用 WebStorm)

标签 javascript reactjs webstorm eslint

我正在使用标准 React 设置在 WebStorm 中编写 React 应用程序。我以前从未明确设置过任何 linting,因此无论出现什么错误/警告消息,都来自某种默认配置。当我运行 npm start 时,我收到以下警告:

Compiled with warnings.

Warning in ./path/to/MyComponent.js

/my/complete/path/to/MyComponent.js
  19:49  warning  Unexpected whitespace before property bind  no-whitespace-before-property
...
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.

最后两行明确表明警告来自 ESLint(与 JSHint 或某些自定义 React linting 等相反)。

我想保持 ESLint 运行,即我不只是想全局禁用所有 linting。但是,我想关闭所有地方的“no-whitespace-before-property”警告,而不仅仅是在一行或一个文件中。我该怎么做?

我的 package.jsonnpm start 显示了以下内容(这是我在出现警告时运行的内容):

"scripts": {
  "start": "react-scripts start",
  ...
}

我正在 WebStorm 中开发。 ESLint 首选项面板未选中“启用”复选框,因此 IDE 中的所有 ESLint 配置选项都是灰色的并且可能是不相关的,因此 ESLint 的配置和调用可能也在其他地方发生(例如内置于 React 中?)。

我尝试将以下 .eslintrc.json 文件放入我的项目主目录:

{
  "rules": {
    "no-whitespace-before-property": "off"
  }
}

单独使用以及与 "extends": "eslint:recommended" 一起使用。

我尝试将以下内容添加到我项目的 package.json 文件中:

{
  ...
  "eslintConfig": {
    "rules": {
      "no-whitespace-before-property": "off"
    }
  }
}

我还尝试将值设置为 0 而不是 "off"

我正在编写 React 应用程序可能相关也可能不相关,我在 WebStorm 中开发可能相关也可能不相关,但我包含这些事实以防万一。

我在 StackOverflow 上四处查看,找不到答案。

最佳答案

错误下方的注释不是来自 ESLint(错误是)。所以我假设你正在使用某种包装器,比如 github.com/facebookincubator/create-react-app 这些包装器不使用 .eslintrc 文件,不能直接配置。您必须通读包装器的文档才能弄清楚如何禁用此规则。

一般来说,ESLint 包装器(如 create-react-app、standard、xo 等)专门设计用于“正常工作”,因此移除了配置和微调样式/规则的能力。

关于javascript - 关闭 ESLint 规则(在 React 应用程序中,使用 WebStorm),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42041953/

相关文章:

javascript - jQuery Datepicker 格式,从 mm-dd-yy 到 dd-mm-yy

javascript - 在 react 组件中每 1.5 秒更改/改组文本

css - ReactJS 导航项,不包装在工具栏组件中

javascript - 带有 Webstorm 的 Node.js -

javascript - 多行字符串的 WebStorm 突出显示

javascript - 不要在 WebStorm 的预提交中重新格式化 JSX 解构代码样式

javascript - 在 jQueryUI ProgressBar 中显示值

javascript - 如何给 HTML5 Canvas 色轮添加触摸事件?

javascript - ReactJS - 如何检测何时在文件输入上单击取消?

javascript - 在backbonejs中获取初始数据之前Ajax throbber的设计模式