For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/eslint/no-label-var.md.
close

no-label-var

Added in v0.5.0

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-label-var': 'error',
    },
  },
]);

Rule Details

This rule aims to create clearer code by disallowing the bad practice of creating a label that shares a name with a variable that is in scope.

Examples of incorrect code for this rule:

var x = foo;
function bar() {
x:
  for (;;) {
    break x;
  }
}

Examples of correct code for this rule:

// The variable that has the same name as the label is not in scope.

function foo() {
  var q = t;
}

function bar() {
q:
  for (;;) {
    break q;
  }
}

Options

This rule has no options.

Differences from ESLint

  • On files without type information, only declarations written in the file plus configured globals (languageOptions.globals / /* global foo */) are checked; clashes with built-in globals (Promise, Array, …) are not reported in that case. The globals catalog exported by @rslint/core can supply runtime-specific declarations.

Original Documentation