Skip to content

Commit

Permalink
Merge pull request #6 from ProcessMaker/validate-empty-signal-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
chipit24 authored Apr 29, 2020
2 parents 8553a87 + 571f785 commit 18860fe
Show file tree
Hide file tree
Showing 15 changed files with 351 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'processmaker/call-activity-child-process': 'error',
'processmaker/call-activity-sequence-flow': 'error',
'processmaker/id-required': 'error',
'processmaker/signal-ref-required': 'error',
},
},
},
Expand Down
22 changes: 20 additions & 2 deletions rules/id-required.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { is } = require('bpmnlint-utils');
const { is, isAny } = require('bpmnlint-utils');

/**
* A rule that checks the presence of a node ID.
Expand All @@ -8,8 +8,26 @@ module.exports = function() {
return node.$type.startsWith('bpmndi') || node.$type.startsWith('dc');
}

function isEventDefinition(node) {
return isAny(node, [
'bpmn:CancelEventDefinition',
'bpmn:CompensateDefinition',
'bpmn:ErrorEventDefinition',
'bpmn:EscalationEventDefinition',
'bpmn:Expression',
'bpmn:LinkEventDefinition',
'bpmn:MessageEventDefinition',
'bpmn:SignalEventDefinition',
'bpmn:TerminateEventDefinition',
'bpmn:TimeCycle',
'bpmn:TimeDate',
'bpmn:TimeDuration',
'bpmn:TimerEventDefinition',
]);
}

function check(node, reporter) {
if (is(node, 'bpmn:Definitions') || isNonBpmnType(node)) {
if (is(node, 'bpmn:Definitions') || isNonBpmnType(node) || isEventDefinition(node)) {
return;
}

Expand Down
43 changes: 43 additions & 0 deletions rules/signal-ref-required.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { is, isAny } = require('bpmnlint-utils');

/**
* A rule that checks that signal events have a signal ref
*/
module.exports = function() {

function hasEventDefinitions(node) {
return Array.isArray(node.eventDefinitions)
&& node.eventDefinitions.length > 0;
}

function filterEventDefinitionsWithoutSignalRef(node) {
return node.eventDefinitions.filter(
eventDefinition => is(eventDefinition, 'bpmn:SignalEventDefinition')
&& !eventDefinition.signalRef
);
}

function check(node, reporter) {
if (!isAny(node, [
'bpmn:StartEvent',
'bpmn:EndEvent',
'bpmn:IntermediateCatchEvent',
'bpmn:IntermediateThrowEvent',
'bpmn:BoundaryEvent',
])) {
return;
}

if (!hasEventDefinitions(node)) {
return;
}

const missing = filterEventDefinitionsWithoutSignalRef(node);

if (missing.length > 0) {
reporter.report(node.id, 'Missing signal reference');
}
}

return { check };
};
20 changes: 20 additions & 0 deletions test-diagrams/boundary-event-signal-ref.invalid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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:pm="http://processmaker.com/BPMN/2.0/Schema.xsd" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:task id="node_1" name="Form Task" pm:assignment="requester" />
<bpmn:boundaryEvent id="node_2" name="out" attachedToRef="node_1">
<bpmn:signalEventDefinition signalRef="" />
</bpmn:boundaryEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_1_di" bpmnElement="node_1">
<dc:Bounds x="150" y="130" width="116" height="76" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="190" y="112" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
20 changes: 20 additions & 0 deletions test-diagrams/boundary-event-signal-ref.valid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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:pm="http://processmaker.com/BPMN/2.0/Schema.xsd" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:task id="node_1" name="Form Task" pm:assignment="requester" />
<bpmn:boundaryEvent id="node_2" name="out" attachedToRef="node_1">
<bpmn:signalEventDefinition signalRef="global_1" />
</bpmn:boundaryEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_1_di" bpmnElement="node_1">
<dc:Bounds x="150" y="130" width="116" height="76" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="190" y="112" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
16 changes: 16 additions & 0 deletions test-diagrams/end-event-signal-ref.invalid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:endEvent id="node_2" name="Signal End Event">
<bpmn:signalEventDefinition signalRef="" />
</bpmn:endEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="210" y="140" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
16 changes: 16 additions & 0 deletions test-diagrams/end-event-signal-ref.valid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:endEvent id="node_2" name="Signal End Event">
<bpmn:signalEventDefinition signalRef="global_1" />
</bpmn:endEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="210" y="140" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
58 changes: 58 additions & 0 deletions test-diagrams/event-definitions.valid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="node_2" name="Signal Start Event">
<bpmn:signalEventDefinition />
</bpmn:startEvent>
<bpmn:startEvent id="node_4" name="Start Timer Event">
<bpmn:timerEventDefinition>
<bpmn:timeCycle>2020-04-17T20:19:00.000Z|R/2020-04-17T20:19:00.000Z/P1W</bpmn:timeCycle>
</bpmn:timerEventDefinition>
</bpmn:startEvent>
<bpmn:startEvent id="node_6" name="Message Start Event">
<bpmn:messageEventDefinition />
</bpmn:startEvent>
<bpmn:intermediateCatchEvent id="node_7" name="Intermediate Timer Event">
<bpmn:timerEventDefinition>
<bpmn:timeDate>2020-04-17T20:34:00.000Z</bpmn:timeDate>
</bpmn:timerEventDefinition>
</bpmn:intermediateCatchEvent>
<bpmn:endEvent id="node_9" name="Error End Event">
<bpmn:errorEventDefinition errorRef="node_9_error" />
</bpmn:endEvent>
<bpmn:endEvent id="node_11" name="Terminate End Event">
<bpmn:terminateEventDefinition />
</bpmn:endEvent>
<bpmn:intermediateCatchEvent id="node_12" name="Intermediate Timer Event">
<bpmn:timerEventDefinition>
<bpmn:timeDuration>PT1H</bpmn:timeDuration>
</bpmn:timerEventDefinition>
</bpmn:intermediateCatchEvent>
</bpmn:process>
<bpmn:error id="node_9_error" name="node_9_error" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="210" y="90" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_4_di" bpmnElement="node_4">
<dc:Bounds x="210" y="190" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_6_di" bpmnElement="node_6">
<dc:Bounds x="360" y="90" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_7_di" bpmnElement="node_7">
<dc:Bounds x="360" y="190" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_9_di" bpmnElement="node_9">
<dc:Bounds x="510" y="90" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_11_di" bpmnElement="node_11">
<dc:Bounds x="510" y="190" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_12_di" bpmnElement="node_12">
<dc:Bounds x="360" y="310" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
16 changes: 16 additions & 0 deletions test-diagrams/intermediate-catch-event-signal-ref.invalid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:intermediateCatchEvent id="node_2" name="Intermediate Signal Throw Event">
<bpmn:signalEventDefinition signalRef="" />
</bpmn:intermediateCatchEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="230" y="120" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
16 changes: 16 additions & 0 deletions test-diagrams/intermediate-catch-event-signal-ref.valid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:intermediateCatchEvent id="node_2" name="Intermediate Signal Throw Event">
<bpmn:signalEventDefinition signalRef="global_1" />
</bpmn:intermediateCatchEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="230" y="120" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
16 changes: 16 additions & 0 deletions test-diagrams/intermediate-throw-event-signal-ref.invalid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:intermediateThrowEvent id="node_2" name="Intermediate Signal Throw Event">
<bpmn:signalEventDefinition signalRef="" />
</bpmn:intermediateThrowEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="230" y="120" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
16 changes: 16 additions & 0 deletions test-diagrams/intermediate-throw-event-signal-ref.valid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:intermediateThrowEvent id="node_2" name="Intermediate Signal Throw Event">
<bpmn:signalEventDefinition signalRef="global_1" />
</bpmn:intermediateThrowEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="230" y="120" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
16 changes: 16 additions & 0 deletions test-diagrams/start-event-signal-ref.invalid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="node_2" name="Signal Start Event">
<bpmn:signalEventDefinition signalRef="" />
</bpmn:startEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="280" y="160" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
16 changes: 16 additions & 0 deletions test-diagrams/start-event-signal-ref.valid.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" id="Definitions_03dabax" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="node_2" name="Signal Start Event">
<bpmn:signalEventDefinition signalRef="global_1" />
</bpmn:startEvent>
</bpmn:process>
<bpmn:signal id="global_1" name="global signal 1" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="280" y="160" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Loading

0 comments on commit 18860fe

Please sign in to comment.