Skip to content

noUnreachable

¥Summary

  • 规则生效日期:v1.0.0

    ¥Rule available since: v1.0.0

  • 诊断类别:lint/correctness/noUnreachable

    ¥Diagnostic Category: lint/correctness/noUnreachable

  • 此规则为推荐规则,默认启用。

    ¥This rule is recommended, which means is enabled by default.

  • 此规则没有修复方案。

    ¥This rule doesn’t have a fix.

  • 此规则的默认严重级别为 error

    ¥The default severity of this rule is error.

  • 来源:

    ¥Sources:

¥How to configure

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

¥Description

禁止无法访问的代码

¥Disallow unreachable code

¥Examples

¥Invalid

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 │ }

¥Related links