eslint-plugin-switch-statement
Version:
Rules for properly handling switch statements, including ensuring that appropriate exhaustive case handling.
49 lines (34 loc) ⢠1.41 kB
Markdown
# eslint-plugin-switch-statement
Rules for making switch/case expressions for union type values exhaustively checkable at compile time.
## Installation
Install `eslint-plugin-switch-statement`. If you want to use the included `assertUnreachable` in your source
code, make sure to save it as a `dependency` and not a `devDependency`.
```sh
npm install eslint-plugin-switch-statement --save-dev
```
## Usage
```ts
import exhaustiveSwitch from "eslint-plugin-switch-statement";
// in your eslint flat config
{
"plugins": { "exhaustive-switch": exhaustiveSwitch }
}
```
Then configure the rule under the rules section.
```json
{
"rules": {
"exhaustive-switch/require-unreachable-default-case": [
2,
{ "unreachableDefaultCaseAssertionFunctionName": "assertNever" }
]
}
}
```
## Rules
<!-- begin auto-generated rules list -->
š§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
| Name | Description | š§ |
| :--------------------------------------------------------------------------------- | :------------------------------- | :- |
| [require-appropriate-default-case](docs/rules/require-appropriate-default-case.md) | require unreachable default case | š§ |
<!-- end auto-generated rules list -->