Skip to content

Commit fbc914c

Browse files
committed
feat(enforce-system-id): detect duplicate system IDs
1 parent 128d239 commit fbc914c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/rules/enforce-system-id.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ module.exports = {
2020
invalidSystemId: 'Property "systemId" should be a non-empty string.',
2121
systemIdNotAllowedBeforeVersion5:
2222
'Property "systemId" is not supported in xstate < 5.',
23+
duplicateSystemId: 'The systemId "{{systemId}}" is not unique.',
2324
},
2425
},
2526

2627
create(context) {
2728
const { version } = getSettings(context)
2829
const prefix = getSelectorPrefix(context.sourceCode)
30+
const systemIds = new Set()
2931

3032
return {
3133
[`${prefix}Property[key.name='invoke'] > ObjectExpression`]: (node) => {
@@ -79,8 +81,20 @@ module.exports = {
7981
}
8082
},
8183

82-
// TODO another check should make sure that the systemId is unique
83-
// code here
84+
[`${prefix}Property[key.name='invoke'] > ObjectExpression > Property[key.name="systemId"]`]:
85+
(node) => {
86+
if (systemIds.has(node.value.value)) {
87+
context.report({
88+
node,
89+
messageId: 'duplicateSystemId',
90+
data: { systemId: node.value.value },
91+
})
92+
} else {
93+
systemIds.add(node.value.value)
94+
}
95+
},
96+
97+
// TODO check use of systemId in spawns
8498
}
8599
},
86100
}

0 commit comments

Comments
 (0)