Skip to content

Commit

Permalink
fix: prevent entry-exit-action matching state nodes of such names
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaffers committed May 12, 2021
1 parent bdf7cb1 commit e362d66
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/rules/entry-exit-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'),
}
},
}

0 comments on commit e362d66

Please sign in to comment.