switch (0) {
case 0: {
break;
}
default:
}
Thanks for the report @falsandtru. For a possible workaround for now, I'd try using this style:
switch (0) {
case 0: {
//whatever code here
} break;
default:
}
Thanks for your response. But I cannot solve some cases.
switch (n) {
case 0: {
let m = n;
// ...
return n + m;
}
default:
}
Would you fix this issue?
@falsandtru Yes, this should definitely be fixed.
Also, @Think7 also encountered this problem over in #898.
Just ran into the same issue, so I am all for having it fixed :)
Thanks for making tslint :+1:
JSHint used to have the same problem, see https://github.com/jshint/jshint/issues/858.
Wanted to mention that the newest versions of the TS compiler now have a --noFallthroughCasesInSwitch flag which could lead to this rule being deprecated soon.
I agree, this rule will be needless.
Although a TSLint rule offers the advantage that you can selectively disable it, whereas as far as I know you can't do that with the compiler flag.
Then TSLint would be better to change its default(example) config to disable.
Yeah, actually the --noFallthroughCasesInSwitch - Option is even more dangerous, because you will not notice, that it does not fall through even though you expected it to. And for that case it would even not be possible to detect it, because its hard to guess programmers intension.
I would prefer to have this tslint option fixed and not use --noFallthroughCasesInSwitch.
Fix this pls!
+1
+1
Same happens with if-else-statements where both have a return.
@Jan539
I might misunderstood, but if you have an if-else statement both having a return, you shouldn't have. Since if your "if" already returns, there is no need for "else". Rest of the code is "else", and thus "else" keyword should be omitted.
@rvalimaki
if-else conditionals also fail this lint even if only one has a return. such as the following conditional:
// ...
case 'myCase':
if (typeof action.payload !== 'number') {
throw new Error('cannot access id expect from number');
} else {
return action.payload;
}
// ...
Most helpful comment
Thanks for your response. But I cannot solve some cases.
Would you fix this issue?