# label-position

Rule `sonarjs/label-position`. Only "while", "do", "for" and "switch" statements should be labelled

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1231 by reach, #532 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/label-position` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-1439/) |

## Code examples

### Incorrect: the rule reports this

```js
myLabel: if (i % 2 == 0) {  // Noncompliant
  if (i == 12) {
    console.log("12");
    break myLabel;
  }
  console.log("Even number, but not 12");
}
```

### Correct: the rule accepts this

```js
myLabel: for (i = 0; i < 10; i++) {   // Compliant
  console.log("Loop");
  break myLabel;
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/label-position": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/jsx-no-leaked-render](https://lintradar.dev/rules/sonarjs/jsx-no-leaked-render.md): React components should not render non-boolean condition values
- [sonarjs/link-with-target-blank](https://lintradar.dev/rules/sonarjs/link-with-target-blank.md): Opened windows should not have access to the originating page
- [sonarjs/inverted-assertion-arguments](https://lintradar.dev/rules/sonarjs/inverted-assertion-arguments.md): Assertion arguments should be passed in the correct order
- [sonarjs/links-identical-texts-different-targets](https://lintradar.dev/rules/sonarjs/links-identical-texts-different-targets.md): Links with identical accessible names should have identical targets
- [sonarjs/insecure-jwt-token](https://lintradar.dev/rules/sonarjs/insecure-jwt-token.md): JWT should be signed and verified with strong cipher algorithms
- [sonarjs/max-switch-cases](https://lintradar.dev/rules/sonarjs/max-switch-cases.md): "switch" statements should not have too many "case" clauses

---

Web page: https://lintradar.dev/rules/sonarjs/label-position. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
