# no-labels

> Disallow labeled statements

A label lets `break` and `continue` jump out of more than one loop at a time. Few people use labels, so readers have to stop and work out where the jump lands. Moving the loops into a function and using `return` does the same thing without a label.

The labeled statement is reported, and so is each `break` or `continue` that names a label.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"no-labels" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-labels" = ["error", {
  allowLoop = false,
  allowSwitch = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
let found;

search: for (const row of rows) {
  for (const cell of row.cells) {
    if (cell.value === target) {
      found = cell;
      break search;
    }
  }
}
```

Not reported:

{/* good */}
```js
function findCell(rows, target) {
  for (const row of rows) {
    for (const cell of row.cells) {
      if (cell.value === target) return cell;
    }
  }
}

const found = findCell(rows, target);
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowLoop` | `false` | Allow labels on loops. |
| `allowSwitch` | `false` | Allow labels on `switch` statements. |

{/* good {"options": [{"allowLoop": true}]} */}
```js
eachRow: for (const row of rows) {
  for (const cell of row.cells) {
    if (cell.isEmpty) continue eachRow;
  }
  print(row);
}
```

{/* good {"options": [{"allowSwitch": true}]} */}
```js
command: switch (input.type) {
  case "batch":
    for (const item of input.items) {
      if (item.stop) break command;
      run(item);
    }
    break;
}
```

A label on anything else, such as a block, is reported no matter what the options are:

{/* bad {"options": [{"allowLoop": true, "allowSwitch": true}], "count": 2} */}
```js
setup: {
  if (!config) break setup;
  apply(config);
}
```
