简体   繁体   English

如何在 Visual Studio Code 中获取 eslint 以允许双引号?

[英]How to get eslint in Visual Studio Code to allow double quotes?

  • I created a vue-js CLI project我创建了一个 vue-js CLI 项目
  • I want to be able to use double-quotes instead of single quotes我希望能够使用双引号而不是单引号
  • when I use double quotes, npm run dev reports eslint errors当我使用双引号时, npm run dev报告 eslint 错误
  • Where do I tell eslint to allow double quotes?我在哪里告诉 eslint 允许双引号?

在此处输入图片说明

Check your .eslintrc.js file, you can either set the value of the quotes rule to double or set the error level to warning or disable it altogether.检查您的.eslintrc.js文件,您可以将quotes规则的值设置为double或将错误级别设置为warning或完全禁用它。 Have a look at the docs .看看文档 This would be an example:这将是一个例子:

"rules": {
    "quotes": ["error", "double"]
}

quotes: [0, "double"]对我有用

Sometimes it is cumbersome to find a specific syntax to disallow a specific eslint rule.有时要找到一个特定的语法来禁止特定的 eslint 规则是很麻烦的。 In this situations you can use "global" disabling for a code block as the following:在这种情况下,您可以对代码块使用“全局”禁用,如下所示:

/*eslint-disable */

//suppress all warnings between comments
console.info("foo");

/*eslint-enable */

If you use the ESLint extension https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint .如果您使用 ESLint 扩展https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint

It comes with a command to initialize the .eslintrc file :它带有一个初始化 .eslintrc 文件的命令:

Run Ctrl+Maj+P then ESLint : Create ESLint configuration运行Ctrl+Maj+P然后ESLint : Create ESLint configuration

In the resulting .eslintrc.js file that has been generated at the root of your Workspace add the quotes: [0, "double"] line as stated by others.在工作区根目录生成的结果 .eslintrc.js 文件中,添加quotes: [0, "double"]行,如其他人所述。

File should look something like this文件应该是这样的

module.exports = {
  quotes: [0, "double"]
}

另一种更简单的方法是进入 .eslintignore 文件并在文件末尾添加 * 将为您带来魔力

The following rule will get rid of the double quotes error however then you will start getting single quotes error:以下规则将消除双引号错误,但是您将开始收到单引号错误:

"rules": {
   "quotes": ["error", "double"]
}

And if you want to disable the quotes rule then add this:如果您想禁用引号规则,请添加以下内容:

rules: {
    quotes: "off"  
}

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

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