---
# Don't modify this file manually. This file is auto generated from source, and you will lose your changes next time the website is built.
# Head to the `biomejs/biome` repository, and modify the source code in there.

title: useDefaultSwitchClause
description: Learn more about useDefaultSwitchClause
---
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)

## How to configure
```json title="biome.json"
{
	"linter": {
		"rules": {
			"style": {
				"useDefaultSwitchClause": "error"
			}
		}
	}
}

```
## Description
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.

## Examples

### Invalid

```js
switch (a) {
    case 1:
        /* code */
        break;
}
```

<pre class="language-text"><code class="language-text">code-block.js:1:1 <a href="https://biomejs.dev/linter/rules/use-default-switch-clause">lint/style/useDefaultSwitchClause</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Expected a default switch clause.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>switch (a) &#123;<br />   <strong>   │ </strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>    case 1:<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong>        /&#42; code &#42;/<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong>        break;<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong>&#125;<br />   <strong>   │ </strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>6 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The lack of a default clause can be a possible omission.</span><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider adding a default clause.</span><br />  <br /></code></pre>

### Valid

```js
switch (a) {
    case 1:
        /* code */
        break;
    default:
        /* code */
        break;
}
```

## Related links

- [Disable a rule](/linter/#disable-a-rule)
- [Configure the code fix](/linter#configure-the-code-fix)
- [Rule options](/linter/#rule-options)
- [Source Code](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/src/lint/style/use_default_switch_clause.rs)
- [Test Cases](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/tests/specs/style/useDefaultSwitchClause)

</TabItem>
</Tabs>