我是eslint的新手,它正在喷出大量错误告诉我使用双引号:
error Strings must use doublequote
Run Code Online (Sandbox Code Playgroud)
那不是我的偏好.我有一个基本的.eslintrc文件设置:
{
"env": {
"node": 1
}
}
Run Code Online (Sandbox Code Playgroud)
我想为单引号配置它.
Ant*_*och 30
http://eslint.org/docs/rules/quotes.html
{
"env": {
"node": 1
},
"rules": {
"quotes": [2, "single", { "avoidEscape": true }]
}
}
Run Code Online (Sandbox Code Playgroud)
rules: {
'prettier/prettier': [
'warn',
{
singleQuote: true,
semi: true,
}
],
},
Run Code Online (Sandbox Code Playgroud)
在版本 "eslint": "^7.21.0"
对于 jsx 字符串,如果您想为所有文件设置此规则,请在 eslint 配置文件中创建该规则。
rules: {
'jsx-quotes': [2, 'prefer-single'],
}
Run Code Online (Sandbox Code Playgroud)
或者用“prefer-double”表示双引号。
如果您使用的是 TypeScript/ES6,您可能需要包含模板文字(反引号)。此规则更喜欢单引号,并允许使用模板文字。
打字稿示例
"@typescript-eslint/quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
]
Run Code Online (Sandbox Code Playgroud)
另一个有用的选项是允许单引号或双引号,只要字符串包含可转义的引号,如"lorem ipsum 'donor' eta"
或'lorem ipsum "donor" eta'
。
"@typescript-eslint/quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
]
Run Code Online (Sandbox Code Playgroud)
参考:
ESLint
https://eslint.org/docs/rules/quotes
打字稿 ESLint
归档时间: |
|
查看次数: |
16566 次 |
最近记录: |