Skip to content

Commit

Permalink
fix: send/receive task unused global
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul99ahad committed Sep 5, 2024
1 parent 87c0b5d commit c03357a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
27 changes: 25 additions & 2 deletions rules/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ module.exports = function() {

const events = getEvents(node);
const eventDefinitions = getEventDefinitions(node);
const sendRecieveTaskDefinitions = getSendRecieveTask(node);

events.forEach(event => {
if (!hasName(event)) {
reporter.report(event.id, 'Element is missing name');
}

if (!isReferenced(event, eventDefinitions)) {
if (!isReferenced(event, eventDefinitions, sendRecieveTaskDefinitions)) {
reporter.report(event.id, 'Element is unused');
}

Expand Down Expand Up @@ -77,13 +78,34 @@ module.exports = function() {
return eventDefinitions;
}

function getSendRecieveTask(definition) {
const elements = [];

function traverse(element) {
if (element.rootElements) {
element.rootElements.forEach(traverse);
}

if (element.flowElements) {
element.flowElements.forEach(element => {
if (is(element, 'bpmn:ReceiveTask') || is(element, 'bpmn:SendTask')) {
elements.push(element);
}
});
}
}

traverse(definition);
return elements;
}

function hasName(event) {
return (
event.name?.trim() !== ''
);
}

function isReferenced(event, eventDefinitions) {
function isReferenced(event, eventDefinitions, sendRecieveTaskDefinitions) {
if (is(event, 'bpmn:Error')) {
return (
eventDefinitions.some(node => is(node, 'bpmn:ErrorEventDefinition') && event.id === node.errorRef?.id)
Expand All @@ -99,6 +121,7 @@ module.exports = function() {
if (is(event, 'bpmn:Message')) {
return (
eventDefinitions.some(node => is(node, 'bpmn:MessageEventDefinition') && event.id === node.messageRef?.id)
|| sendRecieveTaskDefinitions.some(node => event.id === node.messageRef?.id)
);
}

Expand Down
10 changes: 10 additions & 0 deletions test/rules/global/valid-message.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
<bpmn:outgoing>Flow_0zm8aj7</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_1sh8wwn" messageRef="Message" />
</bpmn:intermediateCatchEvent>
<bpmn:receiveTask id="Activity_1tqbeze" messageRef="Message_2" />
<bpmn:sendTask id="Activity_0p7h23d" messageRef="Message_3" />
</bpmn:process>
<bpmn:message id="Message" name="Message" />
<bpmn:message id="Message_2" name="Message_2" />
<bpmn:message id="Message_3" name="Message_3" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0im3pgs">
<bpmndi:BPMNShape id="Event_1ek0ibx_di" bpmnElement="Event_1ek0ibx">
Expand All @@ -27,6 +31,12 @@
<bpmndi:BPMNShape id="Event_0xrh1hk_di" bpmnElement="Event_13nvw6k">
<dc:Bounds x="242" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1tqbeze_di" bpmnElement="Activity_1tqbeze">
<dc:Bounds x="210" y="170" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0p7h23d_di" bpmnElement="Activity_0p7h23d">
<dc:Bounds x="210" y="290" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0r5ftth_di" bpmnElement="Flow_0r5ftth">
<di:waypoint x="188" y="100" />
<di:waypoint x="242" y="100" />
Expand Down

0 comments on commit c03357a

Please sign in to comment.