当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。
在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。
我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)
如何定制VSCode来避免这种情况?
当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。
在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。
我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)
如何定制VSCode来避免这种情况?
当前回答
使用这个扩展。
https://marketplace.visualstudio.com/items?itemName=BriteSnow.vscode-toggle-quotes
cmd ' (ctrl '在win/Linux上)将在' ' '中循环
其他回答
安装更漂亮的扩展和粘贴下面的代码在你的VSCode设置。json文件
"prettier.useEditorConfig": false,
"prettier.singleQuote": true
这将忽略您的.editorconfig文件设置。
对我来说,这两种选择都解决了问题:
通过在。prettierrc - "singleQuote": true中添加 或者在包中添加以下内容。json - - - > "漂亮":{ “singleQuote”:真的 }
虽然我也尝试添加.prettierrc.js和有以下
module。导出= { singleQuote: true };
这并没有起作用。
我解决这个问题的方法是通过安装禁用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,
};
然后把它作为我的默认格式化器做得更漂亮
撰写本文时(2022年6月):
请考虑.editorconfig在最后覆盖所有其他配置,找到该文件(很可能在项目的根目录上),编辑它并添加以下内容:
[*]
quote_type = single
在.prettierrc中添加
{
"arrowParens": "avoid",
"semi": false,
"singleQuote": true
}