Tag Archives: Eslint error

[Solved] ESLint: Parsing error: Unexpected token(prettier/prettier)

eslint HTML file error after introducing prettier: parsing error: unexpected token (prettier/prettier)

Cause of problem

The parser of prettier is not configured correctly. (I don’t know why it needs to be configured separately. It should have default configuration for all corresponding file types)

Solution

Modify .prettierrc.json , add overides , and configure the parser of HTML. Configurable item: Reference

{
  "printWidth": 120,
  "singleQuote": true,
  "bracketSpacing": true,
  "jsxBracketSameLine": true,
  "htmlWhitespaceSensitivity": "ignore",
  "overrides": [
    {
      "files": "*.html",
      "options": {
        "parser": "html"
      }
    }
  ]
}

eslint Error: Delete `␍` [How to Solve]

reason

Due to the end of line style configuration, endoofline configuration has the following four options:
lf – line feed only (\n), which is common in Linux, MacOS and git repos
CRLF – carriage return + line feed character (\r \n), and windows
CR – carriage return character only (\r), Rarely use
auto – keep the existing end of the line (the mixed values in a file are standardized by looking at the content used after the first line)


Solution:

Configure endOfLine: ‘auto’ in prettier.config.js:

module.exports = {
  semi: false, // unterminated semicolon
  singleQuote: true, // single quotes
  quoteProps: 'as-needed',
  trailingComma: 'none', // final comma
  
 // The point is that this one should be configured as auto
  endOfLine: 'auto'
}