Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ESLint plugin to check for common mistakes and enforce good practices when using XState.

License

NotificationsYou must be signed in to change notification settings

rlaffers/eslint-plugin-xstate

Repository files navigation

ESLint plugin to check for common mistakes and enforce good practices when usingXState library.

npm versionbuild statuscode style: prettierPRs Welcome

Installation

You'll first need to installESLint:

$ npm i eslint --save-dev

Next, installeslint-plugin-xstate:

$ npm install eslint-plugin-xstate --save-dev

Usage

Addxstate 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/prefer-predictable-action-arguments":"error","xstate/no-misplaced-on-transition":"error","xstate/no-invalid-transition-props":"error","xstate/no-invalid-state-props":"error","xstate/no-invalid-conditional-action":"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","xstate/system-id":"warn"  }}

Shareable Configurations

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"]}

XState Version

The default shareable configurations are for XState v5. If you use XState version 4, append_v4 to the name of the configuration you want to use.

{"extends": ["plugin:xstate/recommended_v4"]}
{"extends": ["plugin:xstate/all_v4"]}

If you do not use shareable configs, you need to manually specify the XState version in the ESLint config (defaults to 5):

{"settings": {"xstate": {"version":4    }  }}

Supported Rules

Possible Errors

RuleDescriptionRecommended
spawn-usageEnforce correct usage ofspawn.Only for XState v4!✔️
no-infinite-loopDetect infinite loops with eventless transitions✔️
no-imperative-actionForbid using action creators imperatively✔️
no-ondone-outside-compound-stateForbid onDone transitions onatomic,history andfinal nodes✔️
invoke-usageEnforce correct invocation of services✔️
entry-exit-actionForbid invalid declarations of entry/exit actions✔️
no-misplaced-on-transitionForbid invalid declarations ofon transitions✔️
no-invalid-transition-propsForbid invalid properties in transition declarations✔️
no-invalid-state-propsForbid invalid properties in state node declarations✔️
no-async-guardForbid asynchronous guard functions✔️
no-invalid-conditional-actionForbid invalid declarations inside thechoose action creator✔️

Best Practices

RuleDescriptionRecommended
no-inline-implementationSuggest refactoring guards, actions and services into machine options
prefer-alwaysSuggest using thealways syntax for transient (eventless) transitions✔️
prefer-predictable-action-argumentsSuggest turning on thepredictableActionArguments option✔️
no-auto-forwardForbid auto-forwarding events to invoked services or spawned actors
system-idSuggest using systemId for invoked or spawned actors

Stylistic Issues

RuleDescriptionRecommended
event-namesSuggest consistent formatting of event names
state-namesSuggest consistent formatting of state names and prevent confusing names

Comment Directives

By default, the plugin lints only code within thecreateMachine orMachine calls. However, if your machine configuration is imported from another file, you will need to enable this plugin's rules by adding a comment directive to the top of the file:

/* eslint-plugin-xstate-include */// 💡 This machine config will now be linted too.exportconstmachine={initial:'active',context:{},// etc}

About

ESLint plugin to check for common mistakes and enforce good practices when using XState.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp