当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。
在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。
我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)
如何定制VSCode来避免这种情况?
当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。
在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。
我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)
如何定制VSCode来避免这种情况?
当前回答
我解决这个问题的方法是通过安装禁用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,
};
然后把它作为我的默认格式化器做得更漂亮
其他回答
看起来这个问题有一个漏洞:更漂亮的漏洞
以上方法对我都没用。 唯一有效的是,在package.json中添加这行代码:
"prettier": {
"singleQuote": true
},
你可以在settings.json中使用它
"javascript.preferences.quoteStyle": "single"
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
从vuejs/vetur发行页面https://github.com/vuejs/vetur/issues/986# 这个解决方案对我很有效。
在vcodes设置中。Json文件添加此条目
"vetur.format.defaultFormatterOptions": {
"prettier": {
"singleQuote": true
}
},