jav*_*oob 17 visual-studio-code prettier
我为 vscode 安装了更漂亮的扩展并将标签宽度配置为 4 个空格,但它仍然用 2 个空格缩进新行。我做错了什么?
这是我格式化文件时显示的 gif:
编辑:.prettierrc文件的内容:
{
"trailingComma": "none",
"overrides": [
{
"files": "**/lwc/**/*.html",
"options": { "parser": "lwc" }
},
{
"files": "*.{cmp,page,component}",
"options": { "parser": "html" }
}
]
}
Run Code Online (Sandbox Code Playgroud)
Mah*_*lam 54
首先,.prettierrc
从工作目录中删除任何内容。因为它会覆盖用户设置并使用默认值。
第二,设置Prettier: Tab Width
为4。
三、未勾选Prettier: Use Tabs
如果您必须使用.prettierrc
文件,请指定所有选项。
{
"singleQuote": true,
"printWidth": 80,
"editor.formatOnSave": true,
"proseWrap": "always",
"tabWidth": 4,
"requireConfig": false,
"useTabs": false,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"semi": true
}
Run Code Online (Sandbox Code Playgroud)
小智 9
这些可能性都没有解决我使用Prettier的VS Code案例。
但 Prettier 网站向我展示了如何做到这一点!
本节(https://prettier.io/docs/en/options.html#tab-width)将我带到.editorconfig
网站(https://editorconfig.org/):
我.editorconfig
在项目的根文件夹中找到了这个文件,它有两个我更改的特定配置。
前
indent_style = space
indent_size = 2
Run Code Online (Sandbox Code Playgroud)
后
indent_style = tab
indent_size = 4
Run Code Online (Sandbox Code Playgroud)
终于成功了!
我认为这是因为在用户设置中指定了 tabWidth:4 。而在工作区设置中没有指定任何内容,因此它使用工作区的默认值,即 tabWidth:2 ,
如注释中所述,也添加tabWidth:2
.prettier.js 将修复它!
https://prettier.io/docs/en/options.html#tab-width
归档时间: |
|
查看次数: |
16647 次 |
最近记录: |