# switch-colon-spacing

Rule `eslint/switch-colon-spacing`. Enforce spacing around colons of switch statements

- Source: eslint
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Deprecated: yes
- Reach: 10.6M weekly downloads of presets that enable it
- Trend: +3.0% last quarter
- Rank: #875 by reach, #1549 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `switch-colon-spacing` | no | safe | package `eslint` | [docs](https://eslint.org/docs/latest/rules/switch-colon-spacing) |

## Code examples

### Incorrect: the rule reports this

```js
switch (a) {
    case 0 :break;
    default :foo();
}
```

```js
switch (a) {
    case 0: break;
    default: foo();
}
```

### Correct: the rule accepts this

```js
switch (a) {
    case 0: foo(); break;
    case 1:
        bar();
        break;
    default:
        baz();
        break;
}
```

```js
switch (a) {
    case 0 :foo(); break;
    case 1 :
        bar();
        break;
    default :
        baz();
        break;
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "switch-colon-spacing": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [Google](https://lintradar.dev/presets/google.md) | ESLint | `eslint-config-google` | 60 | 646.4K | +18.9% |

## Related rules

- [eslint/no-console](https://lintradar.dev/rules/eslint/no-console.md): Disallow the use of `console`
- [eslint/no-shadow](https://lintradar.dev/rules/eslint/no-shadow.md): Disallow variable declarations from shadowing variables declared in the outer scope
- [eslint/no-empty-function](https://lintradar.dev/rules/eslint/no-empty-function.md): Disallow empty functions
- [eslint/no-nested-ternary](https://lintradar.dev/rules/eslint/no-nested-ternary.md): Disallow nested ternary expressions
- [eslint/max-classes-per-file](https://lintradar.dev/rules/eslint/max-classes-per-file.md): Enforce a maximum number of classes per file
- [eslint/default-param-last](https://lintradar.dev/rules/eslint/default-param-last.md): Enforce default parameters to be last

---

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