Skip to content

Commit

Permalink
feat(enforce-system-id): detect duplicate system IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaffers committed Oct 5, 2023
1 parent 128d239 commit fbc914c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/rules/enforce-system-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ module.exports = {
invalidSystemId: 'Property "systemId" should be a non-empty string.',
systemIdNotAllowedBeforeVersion5:
'Property "systemId" is not supported in xstate < 5.',
duplicateSystemId: 'The systemId "{{systemId}}" is not unique.',
},
},

create(context) {
const { version } = getSettings(context)
const prefix = getSelectorPrefix(context.sourceCode)
const systemIds = new Set()

return {
[`${prefix}Property[key.name='invoke'] > ObjectExpression`]: (node) => {
Expand Down Expand Up @@ -79,8 +81,20 @@ module.exports = {
}
},

// TODO another check should make sure that the systemId is unique
// code here
[`${prefix}Property[key.name='invoke'] > ObjectExpression > Property[key.name="systemId"]`]:
(node) => {
if (systemIds.has(node.value.value)) {
context.report({
node,
messageId: 'duplicateSystemId',
data: { systemId: node.value.value },
})
} else {
systemIds.add(node.value.value)
}
},

// TODO check use of systemId in spawns
}
},
}

0 comments on commit fbc914c

Please sign in to comment.