简体   繁体   English

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

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

I am writing a React app in WebStorm using the standard React setup.我正在使用标准 React 设置在 WebStorm 中编写 React 应用程序。 I have never previously explicitly set up any linting, so whatever error/warning messages are showing up are from some sort of default configuration.我以前从未明确设置任何 linting,因此显示的任何错误/警告消息都来自某种默认配置。 When I run npm start I get the following 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.

The last two lines make it explicitly clear that the warnings are from ESLint (as opposed to, say, JSHint or some custom React linting, etc.).最后两行明确表明警告来自 ESLint(而不是 JSHint 或一些自定义 React linting 等)。

I want to keep ESLint running, ie I don't just want to globally disable all linting.我想保持 ESLint 运行,即我不只是想全局禁用所有 linting。 However, I want to turn the "no-whitespace-before-property" warning off everywhere, not just on one line or in one file.但是,我想在任何地方都关闭“属性前无空格”警告,而不仅仅是在一行或一个文件中。 How do I do that?我怎么做?

My package.json shows the following for npm start (which is what I run when the warnings appear):我的package.jsonnpm start显示了以下内容(这是我在出现警告时运行的内容):

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

I am developing in WebStorm.我正在 WebStorm 中开发。 The ESLint preferences panel has the "Enable" checkbox unchecked, so all of the ESLint configuration options in the IDE are grayed-out and presumably irrelevant, so presumably also the configuration and invocation of ESLint are happening elsewhere (eg built into React?). ESLint 首选项面板的“启用”复选框未选中,因此 IDE 中的所有 ESLint 配置选项都是灰色的并且可能无关紧要,因此可能 ESLint 的配置和调用也发生在其他地方(例如内置于 React 中?)。

I tried putting the following .eslintrc.json file into my project home directory:我尝试将以下.eslintrc.json文件放入我的项目主目录中:

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

alone as well as with "extends": "eslint:recommended" .单独以及"extends": "eslint:recommended"

I tried adding the following to my project's package.json file:我尝试将以下内容添加到我的项目的package.json文件中:

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

I've also tried setting the value to 0 instead of to "off" .我也试过将值设置为0而不是"off"

It may or may not be relevant that I'm writing a React app, and it may or may not be relevant that I'm developing in WebStorm, but I include those facts just in case.我正在编写 React 应用程序可能相关也可能不相关,我在 WebStorm 中开发可能相关也可能不相关,但我包括这些事实以防万一。

I've checked around on StackOverflow and can't find an answer.我已经在 StackOverflow 上检查过,但找不到答案。

The note below the errors is not coming from ESLint (error is).错误下方的注释不是来自 ESLint(错误是)。 So I'm assuming you are using some sort of wrapper, like github.com/facebookincubator/create-react-app Those wrappers do not use .eslintrc file and can't be configured directly.所以我假设你正在使用某种包装器,比如 github.com/facebookincubator/create-react-app 这些包装器不使用 .eslintrc 文件并且不能直接配置。 You will have to read through documentation of your wrapper to figure out how to disable this rule.您必须通读包装器的文档才能弄清楚如何禁用此规则。

In general ESLint wrappers like create-react-app, standard, xo, etc. are specifically designed to "just work", and hence remove ability to configure and fine tune styles/rules.一般来说,像 create-react-app、standard、xo 等 ESLint 包装器专门设计为“正常工作”,因此删除了配置和微调样式/规则的能力。

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

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