no-unused-labels
Disallow unused labels
        ✅ Recommended
        
            The "extends": "eslint:recommended" property in a configuration file enables this rule
        
        🔧 Fixable
        
            Some problems reported by this rule are automatically fixable by the --fix command line option
        
在代码的任何地方声明了而没有使用的标签,很可能是由于不完整的重构造成的错误。
OUTER_LOOP:
for (const student of students) {
    if (checkScores(student.scores)) {
        continue;
    }
    doSomething(student);
}
在这种情况下,可能是忘记了删除 OUTER_LOOP:。
这样的标签会占用代码中的空间,也会导致读者的混淆。
规则细节
这一规则旨在消除未使用的标签。
该规则报告的问题可以自动修复,除非在标签和后续语句之间有任何注释,或者删除标签会导致后续语句变成诸如 "use strict" 之类的指令。
使用此规则的错误示例:
                            
                                Open in Playground
                            
/*eslint no-unused-labels: "error"*/
A: var foo = 0;
B: {
    foo();
}
C:
for (let i = 0; i < 10; ++i) {
    foo();
}
使用此规则的正确示例:
                            
                                Open in Playground
                            
/*eslint no-unused-labels: "error"*/
A: {
    if (foo()) {
        break A;
    }
    bar();
}
B:
for (let i = 0; i < 10; ++i) {
    if (foo()) {
        break B;
    }
    bar();
}
何时不用
如果你不想被通知有未使用的标签,你可以安全地禁用此规则。
Related Rules
Version
This rule was introduced in ESLint v2.0.0-rc.0.