ESLint 引入 prettier 后 html 文件报错 Parsing error: Unexpected token(prettier/prettier)

问题原因
没有正确配置 prettier 的 parser(解析器)。(不知道为什么需要单独配置一下,按理应该对应文件类型都有默认配置)
解决方案
修改 .prettierrc.json ,增加 overides,配置 html 的 parser。可配置项:参考
{
"printWidth": 120,
"singleQuote": true,
"bracketSpacing": true,
"jsxBracketSameLine": true,
"htmlWhitespaceSensitivity": "ignore",
"overrides": [
{
"files": "*.html",
"options": {
"parser": "html"
}
}
]
}

本文介绍了如何在使用ESLint和Prettier时,遇到HTML文件解析错误的问题。通过修改.prettierrc.json文件,添加针对HTML文件的parser配置,解决了Unexpected token错误。详细步骤包括配置printWidth、singleQuote等,并提供了一个示例配置。
1万+

被折叠的 条评论
为什么被折叠?



