Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-xstate

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-xstate

ESLint rules for XState

  • 0.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.6K
increased by8.78%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-xstate

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

npm version code style: prettier PRs Welcome

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-xstate:

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

Usage

Add xstate to the plugins section of your .eslintrc configuration file. You can omit the eslint-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/event-names": "warn",
    "xstate/no-inline-implementation": "warn"
  }
}

Shareable Configurations

This plugin exports a recommended configuration which checks for common mistakes. To enable this configuration use the extends property in your .eslintrc.js config file:

{
  "extends": ["plugin:xstate/recommended"]
}

There is also an all configuration which includes every available rule. It enforces both correct usage and best XState practices.

{
  "extends": ["plugin:xstate/all"]
}

Supported Rules

Possible Errors

RuleDescriptionRecommended
spawn-usageEnforce correct usage of spawn:heavy_check_mark:
no-infinite-loopDetect infinite loops with eventless transitions:heavy_check_mark:
no-imperative-actionForbid using action creators imperatively:heavy_check_mark:

Best Practices

RuleDescriptionRecommended
no-inline-implementationSuggest refactoring guards, actions and services into machine options

Stylistic Issues

RuleDescriptionRecommended
event-namesSuggest using MACRO_CASE for events

TODO

  • the onDone transition should not be defined on the root node of the machine
  • detect incorrect usage of invoke
  • detect invalid usage of transition declaration for actions (guarded entry/exit actions must be done with choose)
  • onDone transition declared on a state node instead of within invoke. onDone is valid on compound state nodes only.

Keywords

FAQs

Package last updated on 19 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc