src/content/docs/linter/rules/use-default-switch-clause.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.7.2` - Diagnostic Category: [`lint/style/useDefaultSwitchClause`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`default-case`](https://eslint.org/docs/latest/rules/default-case){
"linter": {
"rules": {
"style": {
"useDefaultSwitchClause": "error"
}
}
}
}
Require the default clause in switch statements.
Some code conventions require that all switch statements have a default clause. The thinking is that it’s better to always explicitly state what the default behavior should be so that it’s clear whether or not the developer forgot to include the default behavior by mistake.
switch (a) {
case 1:
/* code */
break;
}
switch (a) {
case 1:
/* code */
break;
default:
/* code */
break;
}