Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4811713

Browse files
committedMar 6, 2025·
feat: add linting for ad-hoc subprocess completion condition & cancelRemainingInstances only supported from camunda 8.8
1 parent 9594d50 commit 4811713

File tree

2 files changed

+106
-13
lines changed

2 files changed

+106
-13
lines changed
 

‎rules/camunda-cloud/ad-hoc-sub-process.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,41 @@ const { is, isAny } = require('bpmnlint-utils');
33
const { reportErrors } = require('../utils/reporter');
44

55
const { skipInNonExecutableProcess } = require('../utils/rule');
6+
const { hasProperties } = require('../utils/element');
7+
const { greaterOrEqual } = require('../utils/version');
68

7-
module.exports = skipInNonExecutableProcess(function() {
9+
module.exports = skipInNonExecutableProcess(function({ version }) {
810
function check(node, reporter) {
911
if (!is(node, 'bpmn:AdHocSubProcess')) {
1012
return;
1113
}
1214

1315
// Ad-Hoc Sub-Process must contain at least one activity
14-
if (node.get('flowElements').some(isActivity)) {
15-
return;
16+
if (!node.get('flowElements').some(isActivity)) {
17+
reportErrors(node, reporter, {
18+
message: 'Element of type <bpmn:AdHocSubProcess> must contain at least one activity',
19+
data: {
20+
node,
21+
parentNode: null
22+
}
23+
});
1624
}
1725

18-
reportErrors(node, reporter, {
19-
message: 'Element of type <bpmn:AdHocSubProcess> must contain at least one activity',
20-
data: {
21-
node,
22-
parentNode: null
26+
// cancelRemainingInstances attribute is only allowed in version 8.8 or greater
27+
reportErrors(node, reporter, hasProperties(node, {
28+
cancelRemainingInstances: {
29+
allowedVersion: '8.8',
30+
allowed: () => {
31+
if (greaterOrEqual(version, '8.8')) {
32+
return true;
33+
}
34+
35+
return !Object.prototype.hasOwnProperty.call(node, 'cancelRemainingInstances');
36+
},
2337
}
24-
});
38+
}));
39+
40+
// TODO check completion condition not allowed in version < 8.8
2541
}
2642

2743
return {
@@ -31,4 +47,4 @@ module.exports = skipInNonExecutableProcess(function() {
3147

3248
function isActivity(element) {
3349
return isAny(element, [ 'bpmn:Task', 'bpmn:SubProcess' ]);
34-
}
50+
}

‎test/camunda-cloud/ad-hoc-sub-process.spec.js

+80-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,48 @@ const {
1010
const valid = [
1111
{
1212
name: 'ad hoc sub process (with task)',
13+
config: { version: '8.7' },
1314
moddleElement: createModdle(createProcess(`
1415
<bpmn:adHocSubProcess id="Subprocess_1">
1516
<bpmn:task id="Task_1" />
1617
</bpmn:adHocSubProcess>
1718
`))
18-
}
19+
},
20+
{
21+
name: 'ad hoc sub process (with completion condition)',
22+
config: { version: '8.8' },
23+
moddleElement: createModdle(createProcess(`
24+
<bpmn:adHocSubProcess id="Subprocess_1">
25+
<bpmn:task id="Task_1" />
26+
<bpmn:completionCondition xsi:type="tFormalExpression">=myCondition</bpmn:completionCondition>
27+
</bpmn:adHocSubProcess>
28+
`))
29+
},
30+
{
31+
name: 'ad hoc sub process (with cancelRemainingInstances attribute)',
32+
config: { version: '8.8' },
33+
moddleElement: createModdle(createProcess(`
34+
<bpmn:adHocSubProcess id="Subprocess_1" cancelRemainingInstances="false">
35+
<bpmn:task id="Task_1" />
36+
</bpmn:adHocSubProcess>
37+
`))
38+
},
39+
{
40+
name: 'ad hoc sub process (with completion condition and cancelRemainingInstances attribute)',
41+
config: { version: '8.8' },
42+
moddleElement: createModdle(createProcess(`
43+
<bpmn:adHocSubProcess id="Subprocess_1" cancelRemainingInstances="false">
44+
<bpmn:task id="Task_1" />
45+
<bpmn:completionCondition xsi:type="tFormalExpression">=myCondition</bpmn:completionCondition>
46+
</bpmn:adHocSubProcess>
47+
`))
48+
},
1949
];
2050

2151
const invalid = [
2252
{
2353
name: 'ad hoc sub process (empty)',
54+
config: { version: '8.7' },
2455
moddleElement: createModdle(createProcess(`
2556
<bpmn:adHocSubProcess id="Subprocess_1">
2657
</bpmn:adHocSubProcess>
@@ -36,6 +67,7 @@ const invalid = [
3667
},
3768
{
3869
name: 'ad hoc sub process (no activity)',
70+
config: { version: '8.7' },
3971
moddleElement: createModdle(createProcess(`
4072
<bpmn:adHocSubProcess id="Subprocess_1">
4173
<bpmn:exclusiveGateway id="Gateway_1" />
@@ -50,10 +82,55 @@ const invalid = [
5082
parentNode: null
5183
}
5284
}
53-
}
85+
},
86+
{
87+
name: 'ad hoc sub process (with completion condition)',
88+
config: { version: '8.7' },
89+
moddleElement: createModdle(createProcess(`
90+
<bpmn:adHocSubProcess id="Subprocess_1">
91+
<bpmn:task id="Task_1" />
92+
<bpmn:completionCondition xsi:type="tFormalExpression">=myCondition</bpmn:completionCondition>
93+
</bpmn:adHocSubProcess>
94+
`)),
95+
report: {
96+
id: 'Subprocess_1',
97+
message: 'Element of type <bpmn:completionCondition> within <bpmn:AdHocSubProcess> only allowed by Camunda 8.8 or newer',
98+
data: {
99+
node: 'Subprocess_1',
100+
parentNode: null
101+
}
102+
}
103+
},
104+
{
105+
name: 'ad hoc sub process (with cancelRemainingInstances attribute)',
106+
config: { version: '8.7' },
107+
moddleElement: createModdle(createProcess(`
108+
<bpmn:adHocSubProcess id="Subprocess_1" cancelRemainingInstances="false">
109+
<bpmn:task id="Task_1" />
110+
</bpmn:adHocSubProcess>
111+
`)),
112+
report: {
113+
id: 'Subprocess_1',
114+
message: 'Property value of <false> only allowed by Camunda 8.8 or newer',
115+
path: [
116+
'rootElements',
117+
0,
118+
'flowElements',
119+
0,
120+
'cancelRemainingInstances'
121+
],
122+
data: {
123+
type: 'camunda.propertyValueNotAllowed',
124+
node: 'Subprocess_1',
125+
parentNode: null,
126+
property: 'cancelRemainingInstances',
127+
allowedVersion: '8.8'
128+
}
129+
}
130+
},
54131
];
55132

56-
RuleTester.verify('called-element', rule, {
133+
RuleTester.verify('ad-hoc-sub-process', rule, {
57134
valid,
58135
invalid
59136
});

0 commit comments

Comments
 (0)
Please sign in to comment.