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: add sequence-flow-condition rule #58

Merged
merged 1 commit into from
Nov 8, 2022
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 index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const camundaCloud10Rules = {
'message-reference': 'error',
'no-template': 'error',
'no-zeebe-properties': 'error',
'sequence-flow-condition': 'error',
'subscription': 'error',
'timer': [ 'error', { version: '1.0' } ],
'user-task-form': 'error',
Expand Down
20 changes: 1 addition & 19 deletions rules/inclusive-gateway.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { is } = require('bpmnlint-utils');

const { hasProperties, ERROR_TYPES } = require('./utils/element');
const { ERROR_TYPES } = require('./utils/element');

const { reportErrors } = require('./utils/reporter');

Expand All @@ -26,24 +26,6 @@ module.exports = function() {

reportErrors(node, reporter, error);
}

const outgoing = node.get('outgoing');

if (outgoing && outgoing.length > 1) {
for (let sequenceFlow of outgoing) {
if (node.get('default') !== sequenceFlow) {
const errors = hasProperties(sequenceFlow, {
conditionExpression: {
required: true
}
}, sequenceFlow);

if (errors.length) {
reportErrors(sequenceFlow, reporter, errors);
}
}
}
}
}

return {
Expand Down
35 changes: 35 additions & 0 deletions rules/sequence-flow-condition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { isAny } = require('bpmnlint-utils');

const { hasProperties } = require('./utils/element');

const { reportErrors } = require('./utils/reporter');

module.exports = function() {
function check(node, reporter) {
if (!isAny(node, [ 'bpmn:ExclusiveGateway', 'bpmn:InclusiveGateway' ])) {
return;
}

const outgoing = node.get('outgoing');

if (outgoing && outgoing.length > 1) {
for (let sequenceFlow of outgoing) {
if (node.get('default') !== sequenceFlow) {
const errors = hasProperties(sequenceFlow, {
conditionExpression: {
required: true
}
}, sequenceFlow);

if (errors.length) {
reportErrors(sequenceFlow, reporter, errors);
}
}
}
}
}

return {
check
};
};
125 changes: 4 additions & 121 deletions test/camunda-cloud/inclusive-gateway.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,15 @@ const { ERROR_TYPES } = require('../../rules/utils/element');

const valid = [
{
name: 'inclusive gateway (1 outgoing sequence flow)',
name: 'inclusive gateway (1 incoming sequence flow)',
moddleElement: createModdle(createProcess(`
<bpmn:inclusiveGateway id="InclusiveGateway_1">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
</bpmn:inclusiveGateway>
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="InclusiveGateway_1" targetRef="EndEvent_1" />
`))
},
{
name: 'inclusive gateway (2 outgoing sequence flows with condition)',
moddleElement: createModdle(createProcess(`
</bpmn:startEvent>
<bpmn:inclusiveGateway id="InclusiveGateway_1">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
<bpmn:outgoing>SequenceFlow_2</bpmn:outgoing>
</bpmn:inclusiveGateway>
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="InclusiveGateway_1" targetRef="EndEvent_1">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=foo</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:endEvent id="EndEvent_2">
<bpmn:incoming>SequenceFlow_2</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_2" sourceRef="InclusiveGateway_1" targetRef="EndEvent_2">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=bar</bpmn:conditionExpression>
</bpmn:sequenceFlow>
`))
},
{
name: 'inclusive gateway (2 outgoing sequence flows, 1 default, 1 with condition)',
moddleElement: createModdle(createProcess(`
<bpmn:inclusiveGateway id="InclusiveGateway_1" default="SequenceFlow_2">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
<bpmn:outgoing>SequenceFlow_2</bpmn:outgoing>
</bpmn:inclusiveGateway>
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="InclusiveGateway_1" targetRef="EndEvent_1">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=foo</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:endEvent id="EndEvent_2">
<bpmn:incoming>SequenceFlow_2</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_2" sourceRef="InclusiveGateway_1" targetRef="EndEvent_2" />
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="InclusiveGateway_1" />
`))
},
{
Expand Down Expand Up @@ -102,83 +62,6 @@ const invalid = [
property: 'incoming'
}
}
},
{
name: 'inclusive gateway (2 outgoing sequence flows, one without condition)',
moddleElement: createModdle(createProcess(`
<bpmn:inclusiveGateway id="InclusiveGateway_1">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
<bpmn:outgoing>SequenceFlow_2</bpmn:outgoing>
</bpmn:inclusiveGateway>
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="InclusiveGateway_1" targetRef="EndEvent_1">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=foo</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:endEvent id="EndEvent_2">
<bpmn:incoming>SequenceFlow_2</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_2" sourceRef="InclusiveGateway_1" targetRef="EndEvent_2" />
`)),
report: {
id: 'SequenceFlow_2',
message: 'Element of type <bpmn:SequenceFlow> must have property <conditionExpression>',
path: [
'conditionExpression'
],
data: {
type: ERROR_TYPES.PROPERTY_REQUIRED,
node: 'SequenceFlow_2',
parentNode: null,
requiredProperty: 'conditionExpression'
}
}
},
{
name: 'inclusive gateway (2 outgoing sequence flows, 2 without condition)',
moddleElement: createModdle(createProcess(`
<bpmn:inclusiveGateway id="InclusiveGateway_1">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
<bpmn:outgoing>SequenceFlow_2</bpmn:outgoing>
</bpmn:inclusiveGateway>
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="InclusiveGateway_1" targetRef="EndEvent_1" />
<bpmn:endEvent id="EndEvent_2">
<bpmn:incoming>SequenceFlow_2</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_2" sourceRef="InclusiveGateway_1" targetRef="EndEvent_2" />
`)),
report: [
{
id: 'SequenceFlow_1',
message: 'Element of type <bpmn:SequenceFlow> must have property <conditionExpression>',
path: [
'conditionExpression'
],
data: {
type: ERROR_TYPES.PROPERTY_REQUIRED,
node: 'SequenceFlow_1',
parentNode: null,
requiredProperty: 'conditionExpression'
}
},
{
id: 'SequenceFlow_2',
message: 'Element of type <bpmn:SequenceFlow> must have property <conditionExpression>',
path: [
'conditionExpression'
],
data: {
type: ERROR_TYPES.PROPERTY_REQUIRED,
node: 'SequenceFlow_2',
parentNode: null,
requiredProperty: 'conditionExpression'
}
}
]
}
];

Expand Down
Loading