Skip to content

noLabelVar

¥Summary

  • 规则生效日期:v1.0.0

    ¥Rule available since: v1.0.0

  • 诊断类别:lint/suspicious/noLabelVar

    ¥Diagnostic Category: lint/suspicious/noLabelVar

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

    ¥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": {
"suspicious": {
"noLabelVar": "error"
}
}
}
}

¥Description

禁止与变量共享名称的标签

¥Disallow labels that share a name with a variable

¥Examples

¥Invalid

const x1 = "test";
x1: expr;
code-block.js:2:1 lint/suspicious/noLabelVar ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Do not use the x1 variable name as a label

1 │ const x1 = “test”;
> 2 │ x1: expr;
^^
3 │

The variable is declared here

> 1 │ const x1 = “test”;
^^
2 │ x1: expr;
3 │

Creating a label with the same name as an in-scope variable leads to confusion.

¥Valid

const x = "test";
z: expr;

¥Related links