Mohammad Dayyan
Mohammad Dayyan

Reputation: 22408

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!

Upvotes: 2

Views: 6168

Answers (3)

Krishnamoorthy Acharya
Krishnamoorthy Acharya

Reputation: 4254

You can also Add the following at the top of the file and ignore this

/* eslint-disable no-debugger */
/* eslint-disable @typescript-eslint/indent */

Upvotes: 0

zamadaouf
zamadaouf

Reputation: 1

Solved with these dependencies (in angular 16 project) :

...
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/eslint-plugin-tslint": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.52.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
...

Upvotes: 0

Mohammad Dayyan
Mohammad Dayyan

Reputation: 22408

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

Upvotes: 3

Related Questions