---
# 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: useDefaultSwitchClauseLast
description: Learn more about useDefaultSwitchClauseLast
---
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/suspicious/useDefaultSwitchClauseLast`](/reference/diagnostics#diagnostic-category)
- This rule is **recommended**, meaning it is enabled by default.
- This rule doesn't have a fix.
- The default severity of this rule is [**warning**](/reference/diagnostics#warning).
- Sources: 
  - Same as [`default-case-last`](https://eslint.org/docs/latest/rules/default-case-last)

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

```
## Description
Enforce default clauses in switch statements to be last

A switch statement can optionally have a default clause.

If present, it’s usually the last clause, but it doesn’t need to be. It is also allowed to put the default clause before all case clauses, or anywhere between.
The behavior is mostly the same as if it was the last clause.

The default block will be still executed only if there is no match in the case clauses (including those defined after the default),
but there is also the ability to “fall through” from the default clause to the following clause in the list.
However, such flow is not common and it would be confusing to the readers.

Even if there is no "fall through" logic, it’s still unexpected to see the default clause before or between the case clauses. By convention, it is expected to be the last clause.

## Examples

### Invalid

```js
switch (foo) {
    default:
        break;
    case 0:
        break;
}
```

<pre class="language-text"><code class="language-text">code-block.js:2:5 <a href="https://biomejs.dev/linter/rules/use-default-switch-clause-last">lint/suspicious/useDefaultSwitchClauseLast</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">The </span><span style="color: Orange;"><strong>default</strong></span><span style="color: Orange;"> clause should be the last </span><span style="color: Orange;"><strong>switch</strong></span><span style="color: Orange;"> clause.</span><br />  <br />    <strong>1 │ </strong>switch (foo) &#123;<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>    default:<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><br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong>        break;<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><br />    <strong>4 │ </strong>    case 0:<br />    <strong>5 │ </strong>        break;<br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The following </span><span style="color: lightgreen;"><strong>case</strong></span><span style="color: lightgreen;"> clause is here:</span><br />  <br />    <strong>2 │ </strong>    default:<br />    <strong>3 │ </strong>        break;<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong>    case 0:<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><br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong>        break;<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><br />    <strong>6 │ </strong>&#125;<br />    <strong>7 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Regardless its position, the </span><span style="color: lightgreen;"><strong>default</strong></span><span style="color: lightgreen;"> clause is always executed when there is no match. To avoid confusion, the </span><span style="color: lightgreen;"><strong>default</strong></span><span style="color: lightgreen;"> clause should be the last </span><span style="color: lightgreen;"><strong>switch</strong></span><span style="color: lightgreen;"> clause.</span><br />  <br /></code></pre>

```js
switch (foo) {
    default:
        f();
    case 0:
        break;
}
```

<pre class="language-text"><code class="language-text">code-block.js:2:5 <a href="https://biomejs.dev/linter/rules/use-default-switch-clause-last">lint/suspicious/useDefaultSwitchClauseLast</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">The </span><span style="color: Orange;"><strong>default</strong></span><span style="color: Orange;"> clause should be the last </span><span style="color: Orange;"><strong>switch</strong></span><span style="color: Orange;"> clause.</span><br />  <br />    <strong>1 │ </strong>switch (foo) &#123;<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>    default:<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><br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong>        f();<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><br />    <strong>4 │ </strong>    case 0:<br />    <strong>5 │ </strong>        break;<br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The following </span><span style="color: lightgreen;"><strong>case</strong></span><span style="color: lightgreen;"> clause is here:</span><br />  <br />    <strong>2 │ </strong>    default:<br />    <strong>3 │ </strong>        f();<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong>    case 0:<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><br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong>        break;<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><br />    <strong>6 │ </strong>&#125;<br />    <strong>7 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Regardless its position, the </span><span style="color: lightgreen;"><strong>default</strong></span><span style="color: lightgreen;"> clause is always executed when there is no match. To avoid confusion, the </span><span style="color: lightgreen;"><strong>default</strong></span><span style="color: lightgreen;"> clause should be the last </span><span style="color: lightgreen;"><strong>switch</strong></span><span style="color: lightgreen;"> clause.</span><br />  <br /></code></pre>

```js
switch (foo) {
    case 0:
        break;
    default:
    case 1:
        break;
}
```

<pre class="language-text"><code class="language-text">code-block.js:4:5 <a href="https://biomejs.dev/linter/rules/use-default-switch-clause-last">lint/suspicious/useDefaultSwitchClauseLast</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">The </span><span style="color: Orange;"><strong>default</strong></span><span style="color: Orange;"> clause should be the last </span><span style="color: Orange;"><strong>switch</strong></span><span style="color: Orange;"> clause.</span><br />  <br />    <strong>2 │ </strong>    case 0:<br />    <strong>3 │ </strong>        break;<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong>    default:<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><br />    <strong>5 │ </strong>    case 1:<br />    <strong>6 │ </strong>        break;<br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The following </span><span style="color: lightgreen;"><strong>case</strong></span><span style="color: lightgreen;"> clause is here:</span><br />  <br />    <strong>3 │ </strong>        break;<br />    <strong>4 │ </strong>    default:<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong>    case 1:<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><br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>6 │ </strong>        break;<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><br />    <strong>7 │ </strong>&#125;<br />    <strong>8 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Regardless its position, the </span><span style="color: lightgreen;"><strong>default</strong></span><span style="color: lightgreen;"> clause is always executed when there is no match. To avoid confusion, the </span><span style="color: lightgreen;"><strong>default</strong></span><span style="color: lightgreen;"> clause should be the last </span><span style="color: lightgreen;"><strong>switch</strong></span><span style="color: lightgreen;"> clause.</span><br />  <br /></code></pre>

### Valid

```js
switch (foo) {
    case 0:
        break;
    case 1:
    default:
        break;
}
```

```js
switch (foo) {
    case 0:
        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/suspicious/use_default_switch_clause_last.rs)
- [Test Cases](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/tests/specs/suspicious/useDefaultSwitchClauseLast)

</TabItem>
</Tabs>