vue/script-indent false positive on switch case in methods
See original GitHub issueTell us about your environment
- ESLint Version: v4.19.1
- eslint-plugin-vue Version: 4.4.0
- Node Version: 9.11.1
Please show your full configuration:
{
"extends": [
"../.eslintrc",
"plugin:vue/base",
"plugin:vue/essential",
"plugin:vue/strongly-recommended",
"plugin:vue/recommended"
],
"parser": "vue-eslint-parser",
"parserOptions": {
"parser": "typescript-eslint-parser"
},
"plugins": [
"import",
"typescript"
],
"settings": {
"import/resolver": {
"webpack": {
"config": "./webpack.dev.js"
}
}
},
"rules": {
"no-undef": "off",
"import/extensions": ["error", "always", {
"js": "never",
"ts": "never"
}],
"vue/html-closing-bracket-newline": ["error", {
"singleline": "never",
"multiline": "always"
}],
"vue/html-closing-bracket-spacing": ["error", {
"startTag": "never",
"endTag": "never",
"selfClosingTag": "always"
}],
"vue/html-self-closing": ["error", {
"html": {
"normal": "never"
}
}],
"vue/prop-name-casing": ["error", "camelCase"],
"vue/script-indent": ["error", 2]
}
}
What did you do? Please include the actual source code causing the issue.
export default Vue.extend({
methods: {
getStarClassNamePostfix(index: number) {
let starClassNamePostfix: string = '';
switch (index) {
case 0:
starClassNamePostfix = '-lighter';
break;
case 1:
starClassNamePostfix = '-light';
break;
case 2:
starClassNamePostfix = '';
break;
case 3:
starClassNamePostfix = 'dark';
break;
case 4:
starClassNamePostfix = 'darker';
break;
default:
starClassNamePostfix = '';
}
return starClassNamePostfix;
},
},
});
When using switch case in methods with configured vue/script-indent param, eslint-plugin-vue falsely reports wrong indentation inside it as seen here:

However, when changing indentation to that considered proper one by vue/script-indent (which is actually wrong), ‘native’ indent ESLint rule comes in:

Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Switch statement for multiple cases in JavaScript
Upon a match, all subsequent case statements until 'break' fire no matter what the case says. var onlyMen = true; var onlyWomen =...
Read more >The "switch" statement - The Modern JavaScript Tutorial
A switch statement can replace multiple if checks. It gives a more descriptive way to compare a value with multiple variants.
Read more >JavaScript Switch Case – JS Switch Statement Example
In programming, a switch statement is a control-flow statement that tests the value of an expression against multiple cases. This is the basic ......
Read more >Pattern Matching for switch Expressions and Statements
A switch statement transfers control to one of several statements or expressions, depending on the value of its selector expression. In earlier releases ......
Read more >How To Use the Switch Statement in JavaScript - DigitalOcean
In this code block, we will find the current day of the week with the new Date() method, and getDay() to print a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@evenfrost adding
"switchCase": 1fixes it for me.@KaelWD thanks, but with
"switchCase": 1it still breaks when I use// no defaultcomment as ESLint recommends in case of no default case.