> 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.

# no-case-declarations

[Added in v0.2.2](https://github.com/web-infra-dev/rslint/releases/tag/v0.2.2)
## Configuration

| Preset                   | Configured Value |
| ------------------------ | ---------------- |
| ✅ js.configs.recommended | `"error"`        |


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

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

## Rule Details

Disallow lexical declarations in case clauses. Lexical declarations (`let`, `const`, `function`, `class`) in case clauses are visible in the entire switch block but only get initialized when assigned, which can lead to unexpected behavior.

Examples of **incorrect** code for this rule:

```javascript
switch (foo) {
  case 1:
    let x = 1;
    break;
  case 2:
    const y = 2;
    break;
  case 3:
    function f() {}
    break;
  case 4:
    class C {}
    break;
}
```

Examples of **correct** code for this rule:

```javascript
switch (foo) {
  case 1: {
    let x = 1;
    break;
  }
  case 2: {
    const y = 2;
    break;
  }
  case 3: {
    function f() {}
    break;
  }
  default: {
    class C {}
  }
}
```

## Original Documentation

- [ESLint: no-case-declarations](https://eslint.org/docs/latest/rules/no-case-declarations)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/no-case-declarations.js)
