Apply Eslint rules doesn't work for the switch case statement

hey folks,

 

in our eslint config we use the rule

"indent": [ "error", 4] 

 

I applied the eslint code style rules so that I can use the webstorm formatter to format my code. Unfortunatelly, the switch case statement doesn't work well and I get an eslint error when using the ws code formatter.

 

Here is a sample of he formatted code: 

This is the error: 

 

 

This is how the code looks like after eslint --fix. Which is correct

 

Any ideas why the code formatter doesn't work in this particular case?  

```json

{
"extends": "eslint-config-airbnb-base",
"rules": {
"no-console": ["error"],
"import/no-extraneous-dependencies": {
"optionalDependencies": true
},
"quotes": [2, "single"],
"indent": [ "error", 4] ,
"arrow-parens": ["error", "as-needed"],
"max-len": [ "error", 120, 4, { "ignoreComments": true, "ignoreUrls": true} ],
"no-underscore-dangle": [2, { "allowAfterThis": true }]
},
"env": {
"jest": true,
"es6": true,
"node": true
},
"parserOptions": { "ecmaVersion": 9 }
}

```

0
2 comments

Indent rule enforces 0 indent for for case clauses in switch statements by default; but "SwitchCase" option is not considered when importing preferences (https://youtrack.jetbrains.com/issue/WEB-39398). To get rid of ESLint errors, try disabling Indent 'case' branches in Settings | Editor | Code Style | JavaScript, Wrapping and Braces/'switch' statement, or change the ESLint configuration to

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

Thank you, Elena. 

0

Please sign in to leave a comment.