Skip to main content

noLabelVar (since v0.7.0)

This rule is recommended by Rome.

Disallow labels that share a name with a variable

Examples

Invalid

const x1 = "test";
x1: expr;
error[js/noLabelVar]: Do not use the x1 variable name as a label
   js/noLabelVar.js:2:1
  
1  const x1 = "test";
         -- The variable is declared here
2  x1: expr;
   ^^

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

Valid

const x = "test";
z: expr;