当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。
在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。
我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)
如何定制VSCode来避免这种情况?
当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。
在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。
我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)
如何定制VSCode来避免这种情况?
当前回答
在我的情况下,问题是在转义\字符内的字符串:
message = 'Error argument is not an object, it\'s ' + typeof error
打开avoidEscape选项并对该字符串使用双引号解决了问题:
message = "Error argument is not an object, it's " + typeof error
.eslintrc.js
module.exports = {
rules : {
// Other rules...
'quotes' : ['error', 'single', {'avoidEscape' : true}],
}
}
其他回答
quote_type = single
将此添加到.editorconfig中
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
quote_type = single
我解决这个问题的方法是通过安装禁用eslint中的所有格式化规则 npm i -D eslint-config-prettier,然后在eslint配置文件的extends数组的末尾添加“prettier”
module.exports = {
env: {
node: true,
},
extends: [
'airbnb-base',
'airbnb-typescript/base',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
plugins: ['@typescript-eslint'],
root: true,
};
然后把它作为我的默认格式化器做得更漂亮
我没有安装更漂亮的扩展,但在阅读可能重复的答案后,我从头开始添加在我的用户设置(用户设置。json, Ctrl+,快捷方式):
"prettier.singleQuote": true
部分有绿色警告(未知配置设置),单引号不再被替换。
我怀疑更漂亮的扩展是不可见的,但嵌入在Vetur扩展。
对于默认使用.editorconfig文件的项目。格式化程序将忽略设置中的规则并使用.editorconfig中的规则,然后您可以:
删除.editorconfig文件,并使用VSCode设置。 根据您的文件类型,在.editorconfig文件中添加quote_type = single。也可以将quote_type value设置为double或auto。
你可以在settings.json中使用它
"javascript.preferences.quoteStyle": "single"