Skip to content

Commit

Permalink
feat(no-imperative-actions): add support for xstate v5 action creators
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaffers committed Aug 16, 2023
1 parent feb763c commit 409fd67
Show file tree
Hide file tree
Showing 2 changed files with 363 additions and 81 deletions.
10 changes: 6 additions & 4 deletions lib/rules/no-imperative-action.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const getDocsUrl = require('../utils/getDocsUrl')
const getSettings = require('../utils/getSettings')

const {
isKnownActionCreatorCall,
Expand Down Expand Up @@ -59,11 +60,12 @@ module.exports = {
},

create: function (context) {
const { version } = getSettings(context)
return {
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name=/^entry$|^exit$/] ArrowFunctionExpression CallExpression':
function (node) {
if (
isKnownActionCreatorCall(node) &&
isKnownActionCreatorCall(node, version) &&
!isWithinPureActionCreator(node)
) {
context.report({
Expand All @@ -77,7 +79,7 @@ module.exports = {
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name=/^entry$|^exit$/] FunctionExpression CallExpression':
function (node) {
if (
isKnownActionCreatorCall(node) &&
isKnownActionCreatorCall(node, version) &&
!isWithinPureActionCreator(node)
) {
context.report({
Expand All @@ -91,7 +93,7 @@ module.exports = {
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="actions"] ArrowFunctionExpression CallExpression':
function (node) {
if (
isKnownActionCreatorCall(node) &&
isKnownActionCreatorCall(node, version) &&
!isWithinPureActionCreator(node)
) {
context.report({
Expand All @@ -105,7 +107,7 @@ module.exports = {
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="actions"] FunctionExpression CallExpression':
function (node) {
if (
isKnownActionCreatorCall(node) &&
isKnownActionCreatorCall(node, version) &&
!isWithinPureActionCreator(node)
) {
context.report({
Expand Down
Loading

0 comments on commit 409fd67

Please sign in to comment.