原因
由于行尾风格配置导致,endOfLine配置有以下四个选项:
lf
– 仅换行 ( \n),常见于 Linux 和 macOS 以及 git repos 内部
crlf
- 回车 + 换行字符 ( \r\n),常见于 Windows
cr
- 仅回车字符 ( \r),很少使用
auto
- 保持现有的行尾(一个文件中的混合值通过查看第一行之后使用的内容进行标准化)
解决办法
在 prettier.config.js 中配置 endOfLine: ‘auto’
module.exports = {
semi: false, // 未尾分号
singleQuote: true, // 单引号
quoteProps: 'as-needed',
trailingComma: 'none', // 末尾逗号
// 重点是这一个要配置为auto
endOfLine: 'auto'
}