npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-xstate

v3.2.1

Published

ESLint rules for XState

Downloads

25,742

Readme

eslint-plugin-xstate

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

npm version build status 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/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 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"]
}

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

| Rule | Description | Recommended | | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------ | ------------------ | | spawn-usage | Enforce correct usage of spawn. Only for XState v4! | :heavy_check_mark: | | no-infinite-loop | Detect infinite loops with eventless transitions | :heavy_check_mark: | | no-imperative-action | Forbid using action creators imperatively | :heavy_check_mark: | | no-ondone-outside-compound-state | Forbid onDone transitions on atomic, history and final nodes | :heavy_check_mark: | | invoke-usage | Enforce correct invocation of services | :heavy_check_mark: | | entry-exit-action | Forbid invalid declarations of entry/exit actions | :heavy_check_mark: | | no-misplaced-on-transition | Forbid invalid declarations of on transitions | :heavy_check_mark: | | no-invalid-transition-props | Forbid invalid properties in transition declarations | :heavy_check_mark: | | no-invalid-state-props | Forbid invalid properties in state node declarations | :heavy_check_mark: | | no-async-guard | Forbid asynchronous guard functions | :heavy_check_mark: | | no-invalid-conditional-action | Forbid invalid declarations inside the choose action creator | :heavy_check_mark: |

Best Practices

| Rule | Description | Recommended | | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------ | | no-inline-implementation | Suggest refactoring guards, actions and services into machine options | | | prefer-always | Suggest using the always syntax for transient (eventless) transitions | :heavy_check_mark: | | prefer-predictable-action-arguments | Suggest turning on the predictableActionArguments option | :heavy_check_mark: | | no-auto-forward | Forbid auto-forwarding events to invoked services or spawned actors | | | system-id | Suggest using systemId for invoked or spawned actors | |

Stylistic Issues

| Rule | Description | Recommended | | ---------------------------------------- | ------------------------------------------------------------------------ | ----------- | | event-names | Suggest consistent formatting of event names | | | state-names | Suggest consistent formatting of state names and prevent confusing names | |

Comment Directives

By default, the plugin lints only code within the createMachine or Machine 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.
export const machine = {
  initial: 'active',
  context: {},
  // etc
}