简体   繁体   English

如何禁用 eslint(prettier/prettier) 单引号错误

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

I have react-native code.我有 react-native 代码。 I install ESLint.我安装 ESLint。 I use it but its show error.我用它但它显示错误。

While I use single quotes it show me error当我使用单引号时它显示错误

Replace 'react-native' with "react-native" eslint(prettier/prettier)'react-native'替换为"react-native" eslint(prettier/prettier)

And when I use double qoutes it show me another error当我使用双引号时,它会显示另一个错误

String must use singlequote.字符串必须使用单引号。 eslint(quotes) eslint(引号)

here is the screenshot:这是屏幕截图:

screenshot

What i want is, how to remove error messages about using single quotes?我想要的是,如何删除有关使用单引号的错误消息? I prefer using single quotes instead double quotes.我更喜欢使用单引号而不是双引号。

In addition to @Barmar answer, you could also use prettier configuration on a .eslintrc.js file using the following, property:除了@Barmar 的回答,您还可以使用以下属性在.eslintrc.js文件上使用更漂亮的配置:

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

The two answers here helped me get to the solution that worked for me.这里的两个答案帮助我找到了适合我的解决方案。 In my .eslintrc file, I added the following:在我的.eslintrc文件中,我添加了以下内容:

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

In your ESLint configuration you want:在您的 ESLint 配置中,您需要:

quotes: [2, "single"]

In you Pretty configuration you want:在你想要的漂亮配置中:

single-quote: true

You should also be consistent in your use of quotes, so you should use single quotes in the second import line:您还应该在使用引号时保持一致,因此您应该在第二个import行中使用单引号:

import App from './App';

In my case I needed to implement the changes suggest above AND press CMD + SHIFT + P and select "Reload Window" to reload VS Code for the changes to take effect.在我的例子中,我需要实施上面建议的更改并按 CMD + SHIFT + P 和 select“重新加载窗口”重新加载 VS 代码以使更改生效。

None of the solutions worked for me so in my .eslintrc.js file, I replaced the following line:没有一个解决方案对我有用,所以在我的.eslintrc.js文件中,我替换了以下行:

extends: "@react-native-community",

With:和:

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

This is what my .eslintrc.js file looks like now:这就是我的.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