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

Add link-event rule #128

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const allRules = [
'event-sub-process-typed-start-event',
'fake-join',
'label-required',
'link-event',
'no-bpmndi',
'no-complex-gateway',
'no-disconnected',
Expand Down
1 change: 1 addition & 0 deletions config/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
'event-sub-process-typed-start-event': 'error',
'fake-join': 'warn',
'label-required': 'error',
'link-event': 'error',
'no-bpmndi': 'error',
'no-complex-gateway': 'error',
'no-disconnected': 'error',
Expand Down
51 changes: 51 additions & 0 deletions docs/rules/examples/link-event-correct.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1x7j8t1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.20.0-nightly.20240107" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.4.0">
<bpmn:process id="Process_0im3pgs" isExecutable="true">
<bpmn:intermediateThrowEvent id="Event_0fvzchs" name="LINK">
<bpmn:incoming>Flow_0w6huzu</bpmn:incoming>
<bpmn:linkEventDefinition id="LinkEventDefinition_0l1hwet" name="" />
</bpmn:intermediateThrowEvent>
<bpmn:startEvent id="Event_19sw7x6">
<bpmn:outgoing>Flow_0w6huzu</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0w6huzu" sourceRef="Event_19sw7x6" targetRef="Event_0fvzchs" />
<bpmn:endEvent id="Event_17p3a4n">
<bpmn:incoming>Flow_1yhu2w5</bpmn:incoming>
</bpmn:endEvent>
<bpmn:intermediateCatchEvent id="Event_0hnrksg" name="LINK">
<bpmn:outgoing>Flow_1yhu2w5</bpmn:outgoing>
<bpmn:linkEventDefinition id="LinkEventDefinition_08twe44" name="" />
</bpmn:intermediateCatchEvent>
<bpmn:sequenceFlow id="Flow_1yhu2w5" sourceRef="Event_0hnrksg" targetRef="Event_17p3a4n" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0im3pgs">
<bpmndi:BPMNShape id="Event_00qu043_di" bpmnElement="Event_0fvzchs">
<dc:Bounds x="232" y="82" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="238" y="125" width="25" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1w9uhf6_di" bpmnElement="Event_0hnrksg">
<dc:Bounds x="372" y="82" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="378" y="125" width="25" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_17p3a4n_di" bpmnElement="Event_17p3a4n">
<dc:Bounds x="462" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_19sw7x6_di" bpmnElement="Event_19sw7x6">
<dc:Bounds x="142" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0w6huzu_di" bpmnElement="Flow_0w6huzu">
<di:waypoint x="178" y="100" />
<di:waypoint x="232" y="100" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1yhu2w5_di" bpmnElement="Flow_1yhu2w5">
<di:waypoint x="408" y="100" />
<di:waypoint x="462" y="100" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Binary file added docs/rules/examples/link-event-correct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions docs/rules/examples/link-event-incorrect.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1x7j8t1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.20.0-nightly.20240107" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.4.0">
<bpmn:process id="Process_0im3pgs" isExecutable="true">
<bpmn:intermediateThrowEvent id="Event_0fvzchs" name="JUMP">
<bpmn:incoming>Flow_0w6huzu</bpmn:incoming>
<bpmn:linkEventDefinition id="LinkEventDefinition_0l1hwet" name="" />
</bpmn:intermediateThrowEvent>
<bpmn:startEvent id="Event_19sw7x6">
<bpmn:outgoing>Flow_0w6huzu</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0w6huzu" sourceRef="Event_19sw7x6" targetRef="Event_0fvzchs" />
<bpmn:subProcess id="Activity_0jz3rxz">
<bpmn:intermediateCatchEvent id="Event_022ctsn" name="JUMP">
<bpmn:outgoing>Flow_1v2vhxj</bpmn:outgoing>
<bpmn:linkEventDefinition id="LinkEventDefinition_0adz8q7" name="" />
</bpmn:intermediateCatchEvent>
<bpmn:intermediateThrowEvent id="Event_0q5xos0">
<bpmn:incoming>Flow_1v2vhxj</bpmn:incoming>
<bpmn:linkEventDefinition id="LinkEventDefinition_1sut9bb" name="" />
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_1v2vhxj" sourceRef="Event_022ctsn" targetRef="Event_0q5xos0" />
</bpmn:subProcess>
<bpmn:intermediateCatchEvent id="Event_0rw1f16">
<bpmn:outgoing>Flow_1m6xxsl</bpmn:outgoing>
<bpmn:linkEventDefinition id="LinkEventDefinition_00e5m7a" name="" />
</bpmn:intermediateCatchEvent>
<bpmn:endEvent id="Event_0rn7sje">
<bpmn:incoming>Flow_1m6xxsl</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1m6xxsl" sourceRef="Event_0rw1f16" targetRef="Event_0rn7sje" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0im3pgs">
<bpmndi:BPMNShape id="Event_00qu043_di" bpmnElement="Event_0fvzchs">
<dc:Bounds x="232" y="82" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="236" y="125" width="30" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_19sw7x6_di" bpmnElement="Event_19sw7x6">
<dc:Bounds x="142" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_17pzlw3_di" bpmnElement="Event_0rw1f16">
<dc:Bounds x="442" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0rn7sje_di" bpmnElement="Event_0rn7sje">
<dc:Bounds x="532" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0jz3rxz_di" bpmnElement="Activity_0jz3rxz" isExpanded="true">
<dc:Bounds x="200" y="190" width="278" height="150" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_003mg68_di" bpmnElement="Event_022ctsn">
<dc:Bounds x="262" y="242" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="265" y="285" width="30" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_0s0jw0v" bpmnElement="Event_0q5xos0">
<dc:Bounds x="372" y="242" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="466" y="315" width="30" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1v2vhxj_di" bpmnElement="Flow_1v2vhxj">
<di:waypoint x="298" y="260" />
<di:waypoint x="372" y="260" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0w6huzu_di" bpmnElement="Flow_0w6huzu">
<di:waypoint x="178" y="100" />
<di:waypoint x="232" y="100" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1m6xxsl_di" bpmnElement="Flow_1m6xxsl">
<di:waypoint x="478" y="100" />
<di:waypoint x="532" y="100" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Binary file added docs/rules/examples/link-event-incorrect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/rules/link-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Link Event (link-event)

A rule that checks that link events are used in accordance with the BPMN specification:

* A link event must be named
* For every link throw event there exists a matching catch event in the same scope


Example of __incorrect__ usage for this rule:

![Incorrect usage example](./examples/link-event-incorrect.png)

Cf. [`link-event-incorrect.bpmn`](./examples/link-event-incorrect.bpmn).


Example of __correct__ usage for this rule:

![Correct usage example](./examples/link-event-correct.png)

Cf. [`link-event-correct.bpmn`](./examples/link-event-correct.bpmn).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"license": "MIT",
"scripts": {
"all": "run-s lint test-coverage",
"lint": "eslint .",
"lint": "eslint . --ext js,mjs",
"dev": "npm test -- --watch",
"test": "mocha --exclude 'test/integration/*/**' 'test/**/*.*js'",
"test-coverage": "nyc --reporter=lcov --reporter=html npm test",
Expand Down
100 changes: 100 additions & 0 deletions rules/link-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const {
groupBy
} = require('min-dash');

const {
is
} = require('bpmnlint-utils');


/**
* A rule that verifies that link events are properly used.
*
* This implies:
*
* * for every link throw there exists a link catch within
* the same scope, and vice versa
* * there exists only a single pair of [ throw, catch ] links
* with a given name, per scope
* * link events have a name
*
*/
module.exports = function() {

function check(node, reporter) {

if (!is(node, 'bpmn:FlowElementsContainer')) {
return;
}

const links = (node.flowElements || []).filter(isLinkEvent);

for (const link of links) {
if (!link.name) {
reporter.report(link.id, 'Link event is missing name');
}
}

const names = groupBy(links, (link) => link.name);

for (const [ name, events ] of Object.entries(names)) {

// ignore unnamed (validated earlier)
if (!name) {
continue;

Check warning on line 44 in rules/link-event.js

View check run for this annotation

Codecov / codecov/patch

rules/link-event.js#L44

Added line #L44 was not covered by tests
}

// missing catch or throw event
if (events.length === 1) {
const event = events[0];

reporter.report(event.id, `Link ${isThrowEvent(event) ? 'catch' : 'throw' } event with name <${ name }> missing in scope`);
}

const throwEvents = events.filter(isThrowEvent);

if (throwEvents.length > 1) {
for (const event of throwEvents) {
reporter.report(event.id, `Duplicate link throw event with name <${name}> in scope`);
}
}

const catchEvents = events.filter(isCatchEvent);

if (catchEvents.length > 1) {
for (const event of catchEvents) {
reporter.report(event.id, `Duplicate link catch event with name <${name}> in scope`);
}
}
}

}

return {
check
};
};


// helpers /////////////////

function isLinkEvent(node) {

var eventDefinitions = node.eventDefinitions || [];

if (!is(node, 'bpmn:Event')) {
return false;
}

return eventDefinitions.some(
definition => is(definition, 'bpmn:LinkEventDefinition')
);
}

function isThrowEvent(node) {
return is(node, 'bpmn:ThrowEvent');
}

function isCatchEvent(node) {
return is(node, 'bpmn:CatchEvent');
}
Loading
Loading