Prettier - HTML 和 JS 的配置

Pol*_*olo 2 html javascript visual-studio-code prettier

我想在一个配置文件 .prettierrc 中指定 HTML 和 JS 的字符串长度。

 module.exports = {
  singleQuote: true,
  printWidth: 80,
  [HTML]: {
    printWidth: 150,
  },
};
Run Code Online (Sandbox Code Playgroud)

但在日志中我得到:

ReferenceError: HTML is not defined
Run Code Online (Sandbox Code Playgroud)

lej*_*lun 5

您应该使用该.prettierrc格式,visual studio code当您使用此格式时还将提供智能感知。

您收到错误是因为:

  • 该文件需要采用 JSON 格式,
  • overrides任何覆盖都需要在JSON 键下指定

在您的情况下,该文件应如下所示:

.prettierrc

{
  "singleQuote": true,
  "printWidth": 80,
  "overrides": [
    {
      "files": ["**/*.html"],
      "options": {
        "printWidth": 150
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)