Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rules): implement global rule #137

Merged
merged 1 commit into from
Jun 20, 2024
Merged

feat(rules): implement global rule #137

merged 1 commit into from
Jun 20, 2024

Conversation

strangelookingnerd
Copy link
Contributor

@strangelookingnerd strangelookingnerd commented Jun 7, 2024

Hey @nikku,

after our short discussion from yesterday I had a go at implementing a rule to validate event references:

I have provided test cases for the rules that demonstrate they actually work as intented.
I did not yet provide a documentation because I wanted to make sure that the implementation is correct before documenting it.
I was struggeling a bit with validating the usage of a reference and I'm certain that my approach could be improved (see https://github.com/strangelookingnerd/bpmnlint/blob/4e3515167c8d201088cef3a1304bc19be19ec2bb/rules/event-reference.js#L52-L103)
Further im not 100% sure that these checks only apply to Error, Escalation and Message but maybe also other elements.

This PR sure still is a little rough on the edges, but I'd be happy to further improve it in order to be merged.

@barmac barmac requested a review from nikku June 7, 2024 11:20
@nikku nikku added the needs review Review pending label Jun 11, 2024 — with bpmn-io-tasks
reporter.report(node.id, 'Event reference is missing name');
}

const rootElement = getRootElement(node);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather implement this on bpmn:Definitions and search for globals; this ensures we don't rely on the hidden $parent property to discover the elements; it also will be computationally less expensive, as we have to compute bpmnElements only once, rather than n times for n global elements.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can then return false to stop further drill-down.

Copy link
Contributor Author

@strangelookingnerd strangelookingnerd Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather implement this on bpmn:Definitions and search for globals; this ensures we don't rely on the hidden $parent property to discover the elements; it also will be computationally less expensive, as we have to compute bpmnElements only once, rather than n times for n global elements.

I hope I understood you correctly. I am now traversing from bpmn:Definitions downwards, collecting events and event definitions on the way and do the validation. See aad2302

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did understand me correctly. 🙂

@@ -2,6 +2,7 @@ module.exports = {
rules: {
'conditional-flows': 'error',
'end-event-required': 'error',
'event-reference': 'warn',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll internally discuss which name we want to give this rule.

@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Jun 11, 2024
@strangelookingnerd strangelookingnerd requested a review from nikku June 12, 2024 11:19
@nikku
Copy link
Member

nikku commented Jun 13, 2024

Found one bug related to event definitions without refs, cf. 16c1774.

image

@nikku
Copy link
Member

nikku commented Jun 13, 2024

Ensured we stop traversing early (e239e32).

@strangelookingnerd
Copy link
Contributor Author

Found one bug related to event definitions without refs, cf. 16c1774.

Good catch, did not think of that.

@nikku nikku added the needs review Review pending label Jun 13, 2024 — with bpmn-io-tasks
@nikku
Copy link
Member

nikku commented Jun 13, 2024

Further im not 100% sure that these checks only apply to Error, Escalation and Message but maybe also other elements.

I assume it should also apply for Signal? Or do you see a reason to not apply to it?

@strangelookingnerd
Copy link
Contributor Author

I assume it should also apply for Signal? Or do you see a reason to not apply to it?

Yes, it should also apply to Signal- oversight on my end. Added it in ca307d3

@nikku
Copy link
Member

nikku commented Jun 20, 2024

Decision: We'll call this rule global as it handles consistent usage of relevant global elements. We may re-consider the name in the future, once we're smarter.

@nikku
Copy link
Member

nikku commented Jun 20, 2024

Executed via c1aadc8.

A rule that verifies that global elements are properly used.

Currently recognized global elements are:

  * `bpmn:Error`
  * `bpmn:Escalation`
  * `bpmn:Signal`
  * `bpmn:Message`

For each of these elements proper usage implies:

  * element must have a name
  * element is used (referenced) from event definitions
  * there exists only a single element per type with a given name

Related to camunda/camunda-modeler#4339
@nikku
Copy link
Member

nikku commented Jun 20, 2024

Squashed via f090f86. Thanks!

@nikku nikku merged commit d1e37ff into bpmn-io:main Jun 20, 2024
6 checks passed
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Jun 20, 2024
@nikku nikku changed the title feat(rules): implement event-reference feat(rules): implement global rule Jun 20, 2024
@nikku nikku added the rules Concerning existing or missing rules label Jun 20, 2024
nikku added a commit to nikku/camunda-modeler-linter-default-rules that referenced this pull request Jun 20, 2024
Adds `global` rule to validate correct usage of global
elements (Message, Error, Signal, ...).

Cf. bpmn-io/bpmnlint#137
@strangelookingnerd
Copy link
Contributor Author

Thanks for helping me getting this merged 👍🏼

@strangelookingnerd strangelookingnerd deleted the feature/event_reference_rule branch June 20, 2024 19:59
jonathanlukas pushed a commit to jonathanlukas/camunda-modeler-linter-default-rules that referenced this pull request Jun 21, 2024
Adds `global` rule to validate correct usage of global
elements (Message, Error, Signal, ...).

Cf. bpmn-io/bpmnlint#137
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rules Concerning existing or missing rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants