node.js 如何告诉 eslint 你更喜欢你的字符串周围的单引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29312957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:34:26  来源:igfitidea点击:

How to tell eslint that you prefer single quotes around your strings

node.jseslint

提问by Antonius Bloch

I'm new to eslint and it's spewing out a ton of errors telling me to use doublequotes:

我是 eslint 的新手,它吐出大量错误告诉我使用双引号:

error  Strings must use doublequote

That's not my preference. I've got an .eslintrc file set up with the basics:

那不是我的偏好。我已经设置了一个 .eslintrc 文件,其中包含基础知识:

{
  "env": {
    "node": 1
  }
}

I'd like to configure it for single quotes.

我想将它配置为单引号。

回答by Antonius Bloch

http://eslint.org/docs/rules/quotes.html

http://eslint.org/docs/rules/quotes.html

{
  "env": {
    "node": 1
  },
  "rules": {
    "quotes": [2, "single", { "avoidEscape": true }]
  }
}

回答by Allan Mwesigwa

For jsx strings, if you would like to set this rule for all files, create the rule in the eslint config file.

对于 jsx 字符串,如果您想为所有文件设置此规则,请在 eslint 配置文件中创建该规则。

  rules: {
    'jsx-quotes': [2, 'prefer-single'],
  }

Or 'prefer-double' for double quotes.

或 'prefer-double' 表示双引号。