0%

Vscode Prettier 诡异的格式化换行修正

问题

Prettier 格式化后的效果不符合要求,如图所示

1
2
3
<van-button block native-type="submit" color="rgba(170, 170, 170, 1)"
>确认注册</van-button
>

期望的效果如下:

1
2
3
<van-button block native-type="submit" color="rgba(170, 170, 170, 1)">
确认注册
</van-button>

解决

看官方文档:https://prettier.io/docs/en/options.html#html-whitespace-sensitivity

添加下面的配置就可以解决问题了

1
htmlWhitespaceSensitivity: 'ignore'

项目下添加 .prettierrc.js

1
2
3
4
5
6
7
8
module.exports = {
bracketSpacing: true,
jsxBracketSameLine: true,
singleQuote: true,
arrowParens: 'avoid',
trailingComma: 'none',
htmlWhitespaceSensitivity: 'ignore',
};

后记

参考文章:Make prettier less uglier - prevent split tags