src/content/docs/linter/rules/no-useless-switch-case.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/complexity/noUselessSwitchCase`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`unicorn/no-useless-switch-case`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-switch-case.md){
"linter": {
"rules": {
"complexity": {
"noUselessSwitchCase": "error"
}
}
}
}
Disallow useless case in switch statements.
A switch statement can optionally have a default clause.
The default clause will be still executed only if there is no match in the case clauses.
An empty case clause that precedes the default clause is thus useless.
switch (foo) {
case 0:
default:
break;
case 1:
break;
}
switch (foo) {
default:
case 0:
break;
case 1:
break;
}
switch (foo) {
case 0:
break;
default:
break;
}
switch (foo) {
case 0:
break;
}