diff --git a/lib/rules/entry-exit-action.js b/lib/rules/entry-exit-action.js index ff78e09..4b3fcec 100644 --- a/lib/rules/entry-exit-action.js +++ b/lib/rules/entry-exit-action.js @@ -21,6 +21,18 @@ function isValidAction(node) { ) } +const entryActionDeclaration = + 'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name!="states"] > ObjectExpression > Property[key.name="entry"]' + +const rootEntryActionDeclaration = + 'CallExpression[callee.name=/^createMachine$|^Machine$/] > ObjectExpression:nth-child(1) > Property[key.name="entry"]' + +const exitActionDeclaration = + 'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name!="states"] > ObjectExpression > Property[key.name="exit"]' + +const rootExitActionDeclaration = + 'CallExpression[callee.name=/^createMachine$|^Machine$/] > ObjectExpression:nth-child(1) > Property[key.name="exit"]' + module.exports = { meta: { type: 'problem', @@ -89,10 +101,10 @@ module.exports = { } } return { - 'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="entry"]': - validateAction('entry'), - 'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="exit"]': - validateAction('exit'), + [entryActionDeclaration]: validateAction('entry'), + [rootEntryActionDeclaration]: validateAction('entry'), + [exitActionDeclaration]: validateAction('exit'), + [rootExitActionDeclaration]: validateAction('exit'), } }, }