簡體   English   中英

關閉 ESLint 規則(在 React 應用程序中,使用 WebStorm)

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

我正在使用標准 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。 但是,我想在任何地方都關閉“屬性前無空格”警告,而不僅僅是在一行或一個文件中。 我怎么做?

我的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 文件並且不能直接配置。 您必須通讀包裝器的文檔才能弄清楚如何禁用此規則。

一般來說,像 create-react-app、standard、xo 等 ESLint 包裝器專門設計為“正常工作”,因此刪除了配置和微調樣式/規則的能力。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM