diff --git a/rules/conditional-flows.js b/rules/conditional-flows.js index f2e93ab5..c172b3c2 100644 --- a/rules/conditional-flows.js +++ b/rules/conditional-flows.js @@ -1,3 +1,7 @@ +const { + isAny +} = require('bpmnlint-utils'); + /** * A rule that checks that sequence flows outgoing from a * conditional forking gateway or activity are @@ -39,7 +43,14 @@ function isConditionalForking(node) { const defaultFlow = node['default']; const outgoing = node.outgoing || []; - return defaultFlow || outgoing.find(hasCondition); + const isConditionalGateway = isAny(node, [ + 'bpmn:ExclusiveGateway', + 'bpmn:InclusiveGateway' + ]); + + return defaultFlow + || (isConditionalGateway && outgoing.length > 1) + || outgoing.some(hasCondition); } function hasCondition(flow) { diff --git a/test/rules/conditional-flows.mjs b/test/rules/conditional-flows.mjs index 078ad6f4..e1131763 100644 --- a/test/rules/conditional-flows.mjs +++ b/test/rules/conditional-flows.mjs @@ -24,10 +24,18 @@ RuleTester.verify('conditional-flows', rule, { name: 'split after task', moddleElement: readModdle(__dirname + '/conditional-flows/valid-split-after-task.bpmn') }, + { + name: 'split after parallel gateway', + moddleElement: readModdle(__dirname + '/conditional-flows/valid-split-after-parallel-gateway.bpmn') + }, { name: 'conditional fork', moddleElement: readModdle(__dirname + '/conditional-flows/valid-conditional-fork.bpmn') }, + { + name: 'conditional fork default', + moddleElement: readModdle(__dirname + '/conditional-flows/valid-conditional-fork-default.bpmn') + }, { name: 'no condition after merge', moddleElement: readModdle(__dirname + '/conditional-flows/valid-no-condition-after-merge.bpmn') @@ -35,14 +43,32 @@ RuleTester.verify('conditional-flows', rule, { ], invalid: [ { - name: 'fork after exclusive gateway', - moddleElement: readModdle(__dirname + '/conditional-flows/invalid-fork-after-exclusive-gateway.bpmn'), + name: 'fork after exclusive gateway sibling condition', + moddleElement: readModdle(__dirname + '/conditional-flows/invalid-fork-after-exclusive-gateway-sibling-condition.bpmn'), report: { id: 'Flow_2', message: 'Sequence flow is missing condition', path: [ 'conditionExpression' ] } }, + { + name: 'fork after exclusive gateway no conditions', + moddleElement: readModdle(__dirname + '/conditional-flows/invalid-fork-after-exclusive-gateway-no-conditions.bpmn'), + report: [ + { + id: 'Flow_1', + message: 'Sequence flow is missing condition', + path: [ 'conditionExpression' ], + category: 'error' + }, + { + id: 'Flow_2', + message: 'Sequence flow is missing condition', + path: [ 'conditionExpression' ], + category: 'error' + } + ] + }, { name: 'fork after exclusive gateway default', moddleElement: readModdle(__dirname + '/conditional-flows/invalid-fork-after-exclusive-gateway-default.bpmn'), diff --git a/test/rules/conditional-flows/invalid-fork-after-exclusive-gateway-no-conditions.bpmn b/test/rules/conditional-flows/invalid-fork-after-exclusive-gateway-no-conditions.bpmn new file mode 100644 index 00000000..1e9d6432 --- /dev/null +++ b/test/rules/conditional-flows/invalid-fork-after-exclusive-gateway-no-conditions.bpmn @@ -0,0 +1,39 @@ + + + + + Flow_1 + Flow_2 + + + Flow_1 + + + + Flow_2 + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/rules/conditional-flows/invalid-fork-after-exclusive-gateway.bpmn b/test/rules/conditional-flows/invalid-fork-after-exclusive-gateway-sibling-condition.bpmn similarity index 100% rename from test/rules/conditional-flows/invalid-fork-after-exclusive-gateway.bpmn rename to test/rules/conditional-flows/invalid-fork-after-exclusive-gateway-sibling-condition.bpmn diff --git a/test/rules/conditional-flows/valid-conditional-fork-default.bpmn b/test/rules/conditional-flows/valid-conditional-fork-default.bpmn new file mode 100644 index 00000000..e71d3173 --- /dev/null +++ b/test/rules/conditional-flows/valid-conditional-fork-default.bpmn @@ -0,0 +1,41 @@ + + + + + Flow_1 + Flow_2 + + + Flow_1 + + + ${true} + + + Flow_2 + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/rules/conditional-flows/valid-conditional-fork.bpmn b/test/rules/conditional-flows/valid-conditional-fork.bpmn index e71d3173..88611dff 100644 --- a/test/rules/conditional-flows/valid-conditional-fork.bpmn +++ b/test/rules/conditional-flows/valid-conditional-fork.bpmn @@ -1,7 +1,7 @@ - + Flow_1 Flow_2 @@ -14,7 +14,9 @@ Flow_2 - + + ${false} + diff --git a/test/rules/conditional-flows/valid-split-after-parallel-gateway.bpmn b/test/rules/conditional-flows/valid-split-after-parallel-gateway.bpmn new file mode 100644 index 00000000..1c6a1585 --- /dev/null +++ b/test/rules/conditional-flows/valid-split-after-parallel-gateway.bpmn @@ -0,0 +1,39 @@ + + + + + Flow_1 + Flow_2 + + + Flow_1 + + + + Flow_2 + + + + + + + + + + + + + + + + + + + + + + + + + +