Search code examples
javascripthtmlvisual-studio-codeprettier

Prettier - Config for HTML and JS


I want to specify string lengths for HTML and JS in one config file .prettierrc.

 module.exports = {
  singleQuote: true,
  printWidth: 80,
  [HTML]: {
    printWidth: 150,
  },
};

But in log i got:

ReferenceError: HTML is not defined

Solution

  • You should be using the .prettierrc format instead, visual studio code will also provide intellisense when you use this format.

    You are getting the error because:

    • The file needs to be in the JSON format,
    • Any overrides need to be specified under the overrides JSON key

    In your case the file should look like this:

    .prettierrc

    {
      "singleQuote": true,
      "printWidth": 80,
      "overrides": [
        {
          "files": ["**/*.html"],
          "options": {
            "printWidth": 150
          }
        }
      ]
    }