在 vscode 的配置文件 settings.json 将默认 html formatter 设置为 prettier
{
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
格式化 html 代码时总是将 html tag 的每个 attribute 单独放在一行
对应的配置选项没有勾选
.prettierrc.js 中添加了下面的设置
singleAttributePerLine: false,
但问题依旧,请问如何解决这个问题?
与 stackoverflow 上的这个问题是同一个问题 How do you stop Prettier in VS code splitting attributes onto multiple lines?
设置 Print Width
,问题依旧
终于在 github issue It is not possible to disable singleAttributePerLine with JSX 的评论中找到了解决方法
需要在 .prettierrc 配置文件中给 printWidth 设置一个更大的值,每个 attribute 是否单独放在一行是由 printWidth 决定的,超过 printWidth,singleAttributePerLine 的设置就不起作用
{
"overrides": [
{
"files": ["**/*.html"],
"options": {
"printWidth": 150
}
}
]
}