簡體   English   中英

如何禁用 eslint(prettier/prettier) 單引號錯誤

[英]How to disable eslint(prettier/prettier) single quotes error

我有 react-native 代碼。 我安裝 ESLint。 我用它但它顯示錯誤。

當我使用單引號時它顯示錯誤

'react-native'替換為"react-native" eslint(prettier/prettier)

當我使用雙引號時,它會顯示另一個錯誤

字符串必須使用單引號。 eslint(引號)

這是屏幕截圖:

screenshot

我想要的是,如何刪除有關使用單引號的錯誤消息? 我更喜歡使用單引號而不是雙引號。

除了@Barmar 的回答,您還可以使用以下屬性在.eslintrc.js文件上使用更漂亮的配置:

rules: {
    // ...
    'prettier/prettier': ['error', { singleQuote: true }]
  }

這里的兩個答案幫助我找到了適合我的解決方案。 在我的.eslintrc文件中,我添加了以下內容:

"rules": {
  "prettier/prettier": ["error", { "singleQuote": true }]
}

在您的 ESLint 配置中,您需要:

quotes: [2, "single"]

在你想要的漂亮配置中:

single-quote: true

您還應該在使用引號時保持一致,因此您應該在第二個import行中使用單引號:

import App from './App';

在我的例子中,我需要實施上面建議的更改並按 CMD + SHIFT + P 和 select“重新加載窗口”重新加載 VS 代碼以使更改生效。

沒有一個解決方案對我有用,所以在我的.eslintrc.js文件中,我替換了以下行:

extends: "@react-native-community",

和:

extends: ["@react-native-community", "prettier"],

這就是我的.eslintrc.js文件現在的樣子:

module.exports = {
  root: true,
  extends: ["@react-native-community", "prettier"],
};

暫無
暫無

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

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