Skip to content
You are currently reading docs for v1.x. Go to the latest docs if you are using newer version.

noUnreachable

Diagnostic Category: lint/correctness/noUnreachable

Since: v1.0.0

Sources:

Disallow unreachable code

function example() {
return;
neverCalled();
}
code-block.js:3:5 lint/correctness/noUnreachable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ This code will never be reached …

1 │ function example() {
2 │ return;
> 3 │ neverCalled();
│ ^^^^^^^^^^^^^^
4 │ }
5 │

ℹ … because this statement will return from the function beforehand

1 │ function example() {
> 2 │ return;
│ ^^^^^^^
3 │ neverCalled();
4 │ }

function example() {
for(let i = 0; i < 10; ++i) {
break;
}
}
code-block.js:2:28 lint/correctness/noUnreachable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ This code will never be reached …

1 │ function example() {
> 2 │ for(let i = 0; i < 10; ++i) {
│ ^^^
3 │ break;
4 │ }

ℹ … because this statement will break the flow of the code beforehand

1 │ function example() {
2 │ for(let i = 0; i < 10; ++i) {
> 3 │ break;
│ ^^^^^^
4 │ }
5 │ }

function example() {
for(const key in value) {
continue;
neverCalled();
}
}
code-block.js:4:9 lint/correctness/noUnreachable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ This code will never be reached …

2 │ for(const key in value) {
3 │ continue;
> 4 │ neverCalled();
│ ^^^^^^^^^^^^^^
5 │ }
6 │ }

ℹ … because this statement will continue the loop beforehand

1 │ function example() {
2 │ for(const key in value) {
> 3 │ continue;
│ ^^^^^^^^^
4 │ neverCalled();
5 │ }

biome.json
{
"linter": {
"rules": {
"correctness": {
"noUnreachable": "error"
}
}
}
}