- Notifications
You must be signed in to change notification settings - Fork4
ESLint plugin to check for common mistakes and enforce good practices when using XState.
License
rlaffers/eslint-plugin-xstate
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
ESLint plugin to check for common mistakes and enforce good practices when usingXState library.
You'll first need to installESLint:
$ npm i eslint --save-devNext, installeslint-plugin-xstate:
$ npm install eslint-plugin-xstate --save-devAddxstate to the plugins section of your.eslintrc configuration file. You can omit theeslint-plugin- prefix:
{"plugins": ["xstate"]}Then configure the rules you want to use under the rules section.
{"rules": {"xstate/spawn-usage":"error","xstate/no-infinite-loop":"error","xstate/no-imperative-action":"error","xstate/no-ondone-outside-compound-state":"error","xstate/invoke-usage":"error","xstate/entry-exit-action":"error","xstate/prefer-always":"error","xstate/no-misplaced-on-transition":"error","xstate/no-invalid-transition-props":"error","xstate/no-invalid-state-props":"error","xstate/no-async-guard":"error","xstate/event-names": ["warn","macroCase"],"xstate/state-names": ["warn","camelCase"],"xstate/no-inline-implementation":"warn","xstate/no-auto-forward":"warn" }}This plugin exports arecommended configuration which checks for common mistakes. To enable this configuration use theextends property in your.eslintrc.js config file:
{"extends": ["plugin:xstate/recommended"]}There is also anall configuration which includes every available rule. It enforces both correct usage and best XState practices.
{"extends": ["plugin:xstate/all"]}| Rule | Description | Recommended |
|---|---|---|
| spawn-usage | Enforce correct usage ofspawn | ✔️ |
| no-infinite-loop | Detect infinite loops with eventless transitions | ✔️ |
| no-imperative-action | Forbid using action creators imperatively | ✔️ |
| no-ondone-outside-compound-state | Forbid onDone transitions onatomic,history andfinal nodes | ✔️ |
| invoke-usage | Enforce correct invocation of services | ✔️ |
| entry-exit-action | Forbid invalid declarations of entry/exit actions | ✔️ |
| no-misplaced-on-transition | Forbid invalid declarations ofon transitions | ✔️ |
| no-invalid-transition-props | Forbid invalid properties in transition declarations | ✔️ |
| no-invalid-state-props | Forbid invalid properties in state node declarations | ✔️ |
| no-async-guard | Forbid asynchronous guard functions | ✔️ |
| Rule | Description | Recommended |
|---|---|---|
| no-inline-implementation | Suggest refactoring guards, actions and services into machine options | |
| prefer-always | Suggest using thealways syntax for transient (eventless) transitions | ✔️ |
| no-auto-forward | Forbid auto-forwarding events to invoked services or spawned actors |
| Rule | Description | Recommended |
|---|---|---|
| event-names | Suggest consistent formatting of event names | |
| state-names | Suggest consistent formatting of state names and prevent confusing names |
About
ESLint plugin to check for common mistakes and enforce good practices when using XState.
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.