Search code examples
angulartypescripteslintindentation

eslint indent error "Expected indentation of 2 spaces but found 4.", angular 14


I'm using "eslint": "^8.23.0" in angular 14
Everything was OK when I used "eslint": "^8.22.0", after update to 8.23.0 I'm getting the following error:

eslint indent error

eslint indent error

My eslint config:

{
  "root": true,
  "ignorePatterns": [
    "projects/**/*"
  ],
  "overrides": [
    {
      "files": [
        "*.ts",
        "*.js",
        "*.tsx"
      ],
      "parserOptions": {
        "project": [
          "tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@angular-eslint/recommended",
        "plugin:@angular-eslint/template/process-inline-templates"
      ],
      "rules": {
        "@angular-eslint/directive-selector": [
          "error",
          {
            "type": "attribute",
            "prefix": "app",
            "style": "camelCase"
          }
        ],
        "@angular-eslint/component-selector": [
          "error",
          {
            "type": "element",
            "prefix": "app",
            "style": "kebab-case"
          }
        ],
        "indent": [
          "error",
          2,
          {
            "SwitchCase": 1,
            "ArrayExpression": "first"
          }
        ],
        "@angular-eslint/template/eqeqeq": "off",
        "@typescript-eslint/naming-convention": "error",
        "quotes": "error",
        "semi": "error",
        "no-multiple-empty-lines": "error",
        "comma-dangle": "error"
      }
    },
    {
      "files": [
        "*.html",
        "*.css"
      ],
      "extends": [
        "plugin:@angular-eslint/template/recommended"
      ],
      "rules": {
        "@angular-eslint/template/eqeqeq": "off",
        "@angular-eslint/template/accessibility-elements-content": "error",
        "no-multiple-empty-lines": "error"
      }
    }
  ]
}

as you can see this is indent config:

"indent": [
 "error",
 2,
 {
  "SwitchCase": 1  
 }
]

I tested the following config

"indent": [
 "error",
 2,
 {
   "SwitchCase": 1,
   "ArrayExpression": "first"
 }
]

I also change eslint config to the following:

"indent": "off",
"@typescript-eslint/indent": [
  "error",
  2,
  {
    "SwitchCase": 1
  }
],

but nothing changed!


Solution

  • After update the following package, the problem gone!

    @typescript-eslint/eslint-plugin  5.36.0  →  5.36.1
    @typescript-eslint/parser         5.36.0  →  5.36.1