bpmnlint-plugin-camunda-compat 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +1 -1
- package/index.js +31 -7
- package/package.json +13 -5
- package/rules/camunda-cloud-1-0-checks.js +80 -37
- package/rules/camunda-cloud-1-0.js +1 -1
- package/rules/camunda-cloud-1-1-checks.js +17 -18
- package/rules/camunda-cloud-1-1.js +1 -1
- package/rules/camunda-cloud-1-2-checks.js +43 -15
- package/rules/camunda-cloud-1-2.js +1 -1
- package/rules/camunda-cloud-1-3-checks.js +18 -1
- package/rules/camunda-cloud-1-3.js +1 -1
- package/rules/camunda-cloud-8-0-checks.js +5 -0
- package/rules/camunda-cloud-8-0.js +5 -0
- package/rules/camunda-platform-7-15.js +3 -0
- package/rules/camunda-platform-7-16.js +3 -0
- package/rules/camunda-platform-7-17.js +3 -0
- package/rules/utils/cloud/element.js +111 -0
- package/rules/utils/element.js +635 -0
- package/rules/utils/engine-profile.js +1 -1
- package/rules/utils/rule.js +156 -94
package/rules/utils/rule.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
const {
|
2
|
+
every,
|
2
3
|
isArray,
|
3
|
-
|
4
|
+
isObject,
|
4
5
|
isString,
|
6
|
+
some
|
5
7
|
} = require('min-dash');
|
6
8
|
|
7
9
|
const {
|
@@ -11,13 +13,26 @@ const {
|
|
11
13
|
|
12
14
|
const { toSemverMinor } = require('./engine-profile');
|
13
15
|
|
14
|
-
|
16
|
+
/**
|
17
|
+
* Factory function for rules. Returns a rule for a given execution platform,
|
18
|
+
* execution platform version and an array of checks. Must be run on
|
19
|
+
* bpmn:Definitions node. Returns early without traversing further if execution
|
20
|
+
* platform or execution platform version doesn't match. Returns early if node
|
21
|
+
* is not a bpmn:FlowElement or bpmn:FlowElementContainer.
|
22
|
+
*
|
23
|
+
* @param {string} ruleExecutionPlatform
|
24
|
+
* @param {string} ruleExecutionPlatformVersion
|
25
|
+
* @param {(Object|string)[]} checks
|
26
|
+
*
|
27
|
+
* @returns {Function}
|
28
|
+
*/
|
29
|
+
module.exports.createRule = function(ruleExecutionPlatform, ruleExecutionPlatformVersion, checks, executionPlatformLabel) {
|
15
30
|
return () => {
|
16
31
|
return {
|
17
32
|
check: (node, reporter) => {
|
18
33
|
if (is(node, 'bpmn:Definitions')) {
|
19
|
-
executionPlatform = node.get('modeler:executionPlatform');
|
20
|
-
executionPlatformVersion = node.get('modeler:executionPlatformVersion');
|
34
|
+
const executionPlatform = node.get('modeler:executionPlatform');
|
35
|
+
const executionPlatformVersion = node.get('modeler:executionPlatformVersion');
|
21
36
|
|
22
37
|
if (!executionPlatform
|
23
38
|
|| executionPlatform !== ruleExecutionPlatform
|
@@ -29,161 +44,208 @@ module.exports.createRule = function(ruleExecutionPlatform, ruleExecutionPlatfor
|
|
29
44
|
return;
|
30
45
|
}
|
31
46
|
|
32
|
-
|
47
|
+
let results = checkNode(node, checks);
|
33
48
|
|
34
|
-
if (
|
35
|
-
|
49
|
+
if (results === true) {
|
50
|
+
return;
|
36
51
|
}
|
37
52
|
|
38
|
-
|
39
|
-
|
53
|
+
const id = node.get('id') || '';
|
54
|
+
|
55
|
+
if (results === false) {
|
56
|
+
reporter.report(id, `Element of type <${ node.$type }> not supported by ${ executionPlatformLabel || ruleExecutionPlatform } ${ toSemverMinor(ruleExecutionPlatformVersion) }`);
|
57
|
+
} else {
|
58
|
+
if (!isArray(results)) {
|
59
|
+
results = [ results ];
|
60
|
+
}
|
61
|
+
|
62
|
+
results.forEach((result) => {
|
63
|
+
if (isString(result)) {
|
64
|
+
result = { message: result };
|
65
|
+
}
|
66
|
+
|
67
|
+
let {
|
68
|
+
message,
|
69
|
+
...rest
|
70
|
+
} = result;
|
71
|
+
|
72
|
+
message = addExecutionPlatform(message, executionPlatformLabel || ruleExecutionPlatform, toSemverMinor(ruleExecutionPlatformVersion));
|
73
|
+
|
74
|
+
reporter.report(id, message, rest);
|
75
|
+
});
|
40
76
|
}
|
41
77
|
}
|
42
78
|
};
|
43
79
|
};
|
44
|
-
}
|
80
|
+
};
|
45
81
|
|
46
82
|
/**
|
83
|
+
* Create no-op rule that always returns false resulting in early return.
|
84
|
+
*
|
85
|
+
* @returns {Function}
|
86
|
+
*/
|
87
|
+
module.exports.createNoopRule = function() {
|
88
|
+
return () => {
|
89
|
+
return {
|
90
|
+
check: () => false
|
91
|
+
};
|
92
|
+
};
|
93
|
+
};
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Run checks on a node. Return true if at least one of the checks returns true.
|
97
|
+
* Otherwise return all errors or false.
|
98
|
+
*
|
47
99
|
* @param {ModdleElement} node
|
48
100
|
* @param {Array<Function>} checks
|
49
101
|
*
|
50
|
-
* @returns boolean|
|
102
|
+
* @returns {boolean|Object|Object[]|string|string[]}
|
51
103
|
*/
|
52
104
|
function checkNode(node, checks) {
|
53
|
-
|
54
|
-
if (previousResult === true) {
|
55
|
-
return previousResult;
|
56
|
-
}
|
105
|
+
const results = checks.map((check) => {
|
57
106
|
|
58
107
|
// (1) check using type only
|
59
108
|
if (isString(check)) {
|
60
|
-
return is(node, check)
|
109
|
+
return is(node, check);
|
61
110
|
}
|
62
111
|
|
63
112
|
const { type } = check;
|
64
113
|
|
65
114
|
// (2) check using function only
|
66
115
|
if (!type) {
|
67
|
-
return check.check(node)
|
116
|
+
return check.check(node);
|
68
117
|
}
|
69
118
|
|
70
119
|
// (3) check using type and function
|
71
120
|
if (!is(node, type)) {
|
72
|
-
return
|
121
|
+
return false;
|
73
122
|
}
|
74
123
|
|
75
|
-
return check.check(node)
|
76
|
-
}
|
124
|
+
return check.check(node);
|
125
|
+
});
|
126
|
+
|
127
|
+
return results.find((result) => result === true) || getErrors(results);
|
77
128
|
}
|
78
129
|
|
130
|
+
module.exports.checkNode = checkNode;
|
131
|
+
|
79
132
|
/**
|
80
|
-
*
|
81
|
-
* Otherwise return
|
133
|
+
* Create function that runs checks on a node. Return true if all checks return
|
134
|
+
* true. Otherwise return all errors or false.
|
82
135
|
*
|
83
136
|
* @param {Array<Function>} checks
|
84
137
|
*
|
85
|
-
* @returns {boolean|
|
138
|
+
* @returns {boolean|Object|Object[]|string|string[]}
|
86
139
|
*/
|
87
140
|
module.exports.checkEvery = function(...checks) {
|
88
141
|
return function(node) {
|
89
|
-
|
90
|
-
if (!isNil(previousResult) && previousResult !== true) {
|
91
|
-
return previousResult;
|
92
|
-
}
|
93
|
-
|
94
|
-
const result = check(node);
|
142
|
+
const results = checks.map((check) => check(node));
|
95
143
|
|
96
|
-
|
97
|
-
}, null);
|
144
|
+
return every(results, result => result === true) || getErrors(results);
|
98
145
|
};
|
99
|
-
}
|
146
|
+
};
|
100
147
|
|
101
148
|
/**
|
102
|
-
*
|
103
|
-
*
|
149
|
+
* Create function that runs checks on a node. Return true if at least one of
|
150
|
+
* the checks returns true. Otherwise return all errors or false.
|
104
151
|
*
|
105
152
|
* @param {Array<Function>} checks
|
106
153
|
*
|
107
|
-
* @returns {boolean|
|
154
|
+
* @returns {boolean|Object|Object[]|string|string[]}
|
108
155
|
*/
|
109
156
|
module.exports.checkSome = function(...checks) {
|
110
157
|
return function(node) {
|
111
|
-
|
112
|
-
if (previousResult === true) {
|
113
|
-
return previousResult;
|
114
|
-
}
|
158
|
+
const results = checks.map((check) => check(node));
|
115
159
|
|
116
|
-
|
117
|
-
|
118
|
-
if (isNil(previousResult) || result === true) {
|
119
|
-
return result;
|
120
|
-
}
|
121
|
-
|
122
|
-
return previousResult;
|
123
|
-
}, null);
|
160
|
+
return some(results, result => result === true) || getErrors(results);
|
124
161
|
};
|
125
|
-
}
|
162
|
+
};
|
126
163
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
if (!isArray(types)) {
|
142
|
-
types = [ types ];
|
164
|
+
/**
|
165
|
+
* Replace check for element of type.
|
166
|
+
*
|
167
|
+
* @param {(Object|string)[]} checks
|
168
|
+
* @param {string} type
|
169
|
+
* @param {Function} check
|
170
|
+
*
|
171
|
+
* @returns {(Object|string)[]}
|
172
|
+
*/
|
173
|
+
module.exports.replaceCheck = function(checks, type, check) {
|
174
|
+
return replaceChecks(checks, [
|
175
|
+
{
|
176
|
+
type,
|
177
|
+
check
|
143
178
|
}
|
179
|
+
]);
|
180
|
+
};
|
144
181
|
|
145
|
-
|
182
|
+
function replaceChecks(checks, replacements) {
|
183
|
+
return checks.map((check) => {
|
184
|
+
if (isString(check)) {
|
185
|
+
const replacement = replacements.find((replacement) => check === replacement.type);
|
146
186
|
|
147
|
-
|
148
|
-
|
187
|
+
if (replacement) {
|
188
|
+
return {
|
189
|
+
check: replacement.check,
|
190
|
+
type: check
|
191
|
+
};
|
192
|
+
}
|
149
193
|
}
|
150
194
|
|
151
|
-
|
152
|
-
|
153
|
-
return isAny(eventDefinition, types) || `${ node.$type} (${ eventDefinition.$type })`;
|
154
|
-
};
|
155
|
-
}
|
156
|
-
|
157
|
-
module.exports.hasLoopCharacteristics = function(node) {
|
158
|
-
const loopCharacteristics = node.get('loopCharacteristics');
|
159
|
-
|
160
|
-
return !!loopCharacteristics;
|
161
|
-
}
|
195
|
+
if (check.type) {
|
196
|
+
const replacement = replacements.find((replacement) => check.type === replacement.type);
|
162
197
|
|
163
|
-
|
164
|
-
|
198
|
+
if (replacement) {
|
199
|
+
return {
|
200
|
+
...check,
|
201
|
+
check: replacement.check
|
202
|
+
};
|
203
|
+
}
|
204
|
+
}
|
165
205
|
|
166
|
-
|
206
|
+
return check;
|
207
|
+
});
|
167
208
|
}
|
168
209
|
|
169
|
-
module.exports.
|
170
|
-
const laneSets = node.get('laneSets');
|
210
|
+
module.exports.replaceChecks = replaceChecks;
|
171
211
|
|
172
|
-
|
212
|
+
function addExecutionPlatform(string, executionPlatform, executionPlatformVersion) {
|
213
|
+
return string
|
214
|
+
.replace('{{ executionPlatform }}', executionPlatform)
|
215
|
+
.replace('{{ executionPlatformVersion }}', executionPlatformVersion);
|
173
216
|
}
|
174
217
|
|
175
|
-
|
176
|
-
|
177
|
-
|
218
|
+
/**
|
219
|
+
* Return all errors or false.
|
220
|
+
*
|
221
|
+
* @param {(boolean|Object|string)[]} result
|
222
|
+
*
|
223
|
+
* @returns {boolean|(Object|string)[]}
|
224
|
+
*/
|
225
|
+
function getErrors(results) {
|
226
|
+
const errors = results.reduce((errors, result) => {
|
227
|
+
if (isArray(result)) {
|
228
|
+
return [
|
229
|
+
...errors,
|
230
|
+
...result
|
231
|
+
];
|
232
|
+
}
|
178
233
|
|
179
|
-
if (
|
180
|
-
return
|
234
|
+
if (isObject(result) || isString(result)) {
|
235
|
+
return [
|
236
|
+
...errors,
|
237
|
+
result
|
238
|
+
];
|
181
239
|
}
|
182
240
|
|
183
|
-
return
|
184
|
-
};
|
185
|
-
|
241
|
+
return errors;
|
242
|
+
}, []);
|
243
|
+
|
244
|
+
if (errors.length === 1) {
|
245
|
+
return errors[ 0 ];
|
246
|
+
} else if (errors.length > 1) {
|
247
|
+
return errors;
|
248
|
+
}
|
186
249
|
|
187
|
-
|
188
|
-
return !is(node, 'bpmn:BaseElement');
|
250
|
+
return false;
|
189
251
|
}
|