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

Turn off ESLint rule (in React app, using WebStorm)

我正在使用标准 React 设置在 WebStorm 中编写 React 应用程序。我以前从未明确设置过任何 linting,因此显示的任何 error/warning 消息都来自某种默认配置。当我 运行 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 运行ning,即我不只是想全局禁用所有 linting。但是,我想在所有地方关闭 "no-whitespace-before-property" 警告,而不仅仅是在一行或一个文件中。我该怎么做?

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

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

我正在 WebStorm 中开发。 ESLint 首选项面板未选中 "Enable" 复选框,因此 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 中开发可能相关也可能不相关,但我包含这些事实以防万一。

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

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

一般的 ESLint 包装器,如 create-react-app、standard、xo 等,是专门为 "just work" 设计的,因此删除了配置和微调的能力 styles/rules。