bpmnlint 11.12.1 → 11.13.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.
Files changed (47) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +203 -203
  3. package/bin/bpmnlint.js +437 -437
  4. package/config/all.js +38 -37
  5. package/config/correctness.js +12 -12
  6. package/config/recommended.js +29 -29
  7. package/lib/index.js +4 -4
  8. package/lib/linter.js +542 -542
  9. package/lib/resolver/helper.js +12 -12
  10. package/lib/resolver/node-resolver.js +135 -135
  11. package/lib/resolver/static-resolver.js +47 -47
  12. package/lib/support/compile-config.js +200 -200
  13. package/lib/test-rule.js +107 -107
  14. package/lib/testers/helper.js +72 -72
  15. package/lib/testers/rule-tester.d.ts +36 -36
  16. package/lib/testers/rule-tester.js +146 -146
  17. package/lib/traverse.js +56 -56
  18. package/lib/types.d.ts +80 -80
  19. package/package.json +74 -73
  20. package/rules/ad-hoc-sub-process.js +43 -43
  21. package/rules/conditional-event.js +51 -51
  22. package/rules/conditional-flows.js +57 -57
  23. package/rules/end-event-required.js +45 -45
  24. package/rules/event-based-gateway.js +44 -44
  25. package/rules/event-sub-process-typed-start-event.js +43 -43
  26. package/rules/fake-join.js +40 -40
  27. package/rules/global.js +145 -145
  28. package/rules/helper.js +123 -123
  29. package/rules/label-required.js +75 -75
  30. package/rules/link-event.js +106 -106
  31. package/rules/no-bpmndi.js +157 -157
  32. package/rules/no-complex-gateway.js +2 -2
  33. package/rules/no-disconnected.js +82 -82
  34. package/rules/no-duplicate-sequence-flows.js +69 -69
  35. package/rules/no-gateway-join-fork.js +35 -35
  36. package/rules/no-implicit-end.js +98 -98
  37. package/rules/no-implicit-split.js +55 -55
  38. package/rules/no-implicit-start.js +69 -69
  39. package/rules/no-inclusive-gateway.js +2 -2
  40. package/rules/no-overlapping-elements.js +196 -196
  41. package/rules/single-blank-start-event.js +47 -47
  42. package/rules/single-event-definition.js +33 -33
  43. package/rules/standard-size.js +235 -0
  44. package/rules/start-event-required.js +45 -45
  45. package/rules/sub-process-blank-start-event.js +43 -43
  46. package/rules/superfluous-gateway.js +36 -36
  47. package/rules/superfluous-termination.js +70 -70
@@ -1,73 +1,73 @@
1
- // @ts-expect-error 'missing <bpmn-moddle> types'
2
- const { BpmnModdle } = require('bpmn-moddle');
3
-
4
- const { readFileSync } = require('node:fs');
5
-
6
- /**
7
- * @typedef { any } ModdleElement
8
- *
9
- * @typedef { {
10
- * root: ModdleElement,
11
- * moddle: BpmnModdle,
12
- * warnings: any[]
13
- * } } CreatedModdle
14
- */
15
-
16
- /**
17
- * Create moddle instance.
18
- *
19
- * @param {string} xml the XML string
20
- * @param {string} [elementType]
21
- * @param {Object} [moddleExtensions]
22
- *
23
- * @return {Promise<CreatedModdle>}
24
- */
25
- async function createModdle(xml, elementType = 'bpmn:Definitions', moddleExtensions) {
26
-
27
- if (typeof elementType !== 'string') {
28
- moddleExtensions = elementType;
29
- elementType = undefined;
30
- }
31
-
32
- if (typeof elementType === 'undefined') {
33
- elementType = 'bpmn:Definitions';
34
- }
35
-
36
- const moddle = new BpmnModdle(moddleExtensions);
37
-
38
- const {
39
- rootElement: root,
40
- warnings = []
41
- } = await moddle.fromXML(xml, elementType, { lax: true });
42
-
43
- return {
44
- root,
45
- moddle,
46
-
47
- // @ts-ignore-next-line "legacy"
48
- context: {
49
- warnings
50
- },
51
- warnings
52
- };
53
- }
54
-
55
- module.exports.createModdle = createModdle;
56
-
57
-
58
- /**
59
- * Return moddle instance, read from the given file.
60
- *
61
- * @param {string|URL} filePath
62
- * @param {string} [elementType]
63
- * @param {Object} [moddleExtensions]
64
- *
65
- * @return {Promise<CreatedModdle>}
66
- */
67
- function readModdle(filePath, elementType, moddleExtensions) {
68
- const contents = readFileSync(filePath, 'utf8');
69
-
70
- return createModdle(contents, elementType, moddleExtensions);
71
- }
72
-
1
+ // @ts-expect-error 'missing <bpmn-moddle> types'
2
+ const { BpmnModdle } = require('bpmn-moddle');
3
+
4
+ const { readFileSync } = require('node:fs');
5
+
6
+ /**
7
+ * @typedef { any } ModdleElement
8
+ *
9
+ * @typedef { {
10
+ * root: ModdleElement,
11
+ * moddle: BpmnModdle,
12
+ * warnings: any[]
13
+ * } } CreatedModdle
14
+ */
15
+
16
+ /**
17
+ * Create moddle instance.
18
+ *
19
+ * @param {string} xml the XML string
20
+ * @param {string} [elementType]
21
+ * @param {Object} [moddleExtensions]
22
+ *
23
+ * @return {Promise<CreatedModdle>}
24
+ */
25
+ async function createModdle(xml, elementType = 'bpmn:Definitions', moddleExtensions) {
26
+
27
+ if (typeof elementType !== 'string') {
28
+ moddleExtensions = elementType;
29
+ elementType = undefined;
30
+ }
31
+
32
+ if (typeof elementType === 'undefined') {
33
+ elementType = 'bpmn:Definitions';
34
+ }
35
+
36
+ const moddle = new BpmnModdle(moddleExtensions);
37
+
38
+ const {
39
+ rootElement: root,
40
+ warnings = []
41
+ } = await moddle.fromXML(xml, elementType, { lax: true });
42
+
43
+ return {
44
+ root,
45
+ moddle,
46
+
47
+ // @ts-ignore-next-line "legacy"
48
+ context: {
49
+ warnings
50
+ },
51
+ warnings
52
+ };
53
+ }
54
+
55
+ module.exports.createModdle = createModdle;
56
+
57
+
58
+ /**
59
+ * Return moddle instance, read from the given file.
60
+ *
61
+ * @param {string|URL} filePath
62
+ * @param {string} [elementType]
63
+ * @param {Object} [moddleExtensions]
64
+ *
65
+ * @return {Promise<CreatedModdle>}
66
+ */
67
+ function readModdle(filePath, elementType, moddleExtensions) {
68
+ const contents = readFileSync(filePath, 'utf8');
69
+
70
+ return createModdle(contents, elementType, moddleExtensions);
71
+ }
72
+
73
73
  module.exports.readModdle = readModdle;
@@ -1,37 +1,37 @@
1
- export type TestFn = (...any) => any;
2
-
3
- export type ModdleElement = any;
4
-
5
- export type ValidRuleTest = {
6
- config?: any,
7
- it?: TestFn,
8
- moddleElement: ModdleElement,
9
- name?: string
10
- };
11
-
12
- export type InvalidReport = {
13
- id: string,
14
- message: string
15
- };
16
-
17
- export type InvalidRuleTest = {
18
- config?: any,
19
- it?: TestFn,
20
- moddleElement: ModdleElement,
21
- name?: string,
22
- report: InvalidReport | InvalidReport[]
23
- };
24
-
25
- export type RuleTests = {
26
- valid?: ValidRuleTest[],
27
- invalid?: InvalidRuleTest[]
28
- };
29
-
30
- /**
31
- * Verify a rule.
32
- *
33
- * @param ruleName
34
- * @param rule the rule implementation
35
- * @param tests the tests to verify
36
- */
1
+ export type TestFn = (...any) => any;
2
+
3
+ export type ModdleElement = any;
4
+
5
+ export type ValidRuleTest = {
6
+ config?: any,
7
+ it?: TestFn,
8
+ moddleElement: ModdleElement,
9
+ name?: string
10
+ };
11
+
12
+ export type InvalidReport = {
13
+ id: string,
14
+ message: string
15
+ };
16
+
17
+ export type InvalidRuleTest = {
18
+ config?: any,
19
+ it?: TestFn,
20
+ moddleElement: ModdleElement,
21
+ name?: string,
22
+ report: InvalidReport | InvalidReport[]
23
+ };
24
+
25
+ export type RuleTests = {
26
+ valid?: ValidRuleTest[],
27
+ invalid?: InvalidRuleTest[]
28
+ };
29
+
30
+ /**
31
+ * Verify a rule.
32
+ *
33
+ * @param ruleName
34
+ * @param rule the rule implementation
35
+ * @param tests the tests to verify
36
+ */
37
37
  export function verify(ruleName: string, rule: any, tests: RuleTests): void;
@@ -1,147 +1,147 @@
1
- /* global it, describe, beforeEach */
2
-
3
- const assert = require('assert');
4
-
5
- const Linter = require('../linter');
6
-
7
- function createResolver(rule) {
8
-
9
- return {
10
- resolveRule: () => Promise.resolve(rule),
11
-
12
- resolveConfig: () => {
13
- throw new Error('not implemented');
14
- }
15
- };
16
- }
17
-
18
- function expectEqual(a, b) {
19
- assert.deepStrictEqual(JSON.stringify(a, replacer, 2), JSON.stringify(b, replacer, 2));
20
- }
21
-
22
- function verify(ruleName, rule, testCases) {
23
- function createLinterConfig(config = {}) {
24
- return {
25
- rules: { [ruleName]: [ 2, config ] }
26
- };
27
- }
28
-
29
- describe(`rules/${ruleName}`, function() {
30
-
31
- let linter;
32
-
33
- beforeEach(function() {
34
- linter = new Linter({
35
- resolver: createResolver(rule)
36
- });
37
- });
38
-
39
-
40
- describe('should lint valid', function() {
41
-
42
- testCases.valid.forEach(({ config = {}, it: _it, moddleElement, name }, idx) => (
43
-
44
- (_it || it)(getTitle(idx, name), function() {
45
- return (
46
- Promise.resolve(moddleElement)
47
- .then(moddleRoot => {
48
- return linter.lint(moddleRoot.root, createLinterConfig(config));
49
- })
50
- .then(lintResults => {
51
- expectEqual(lintResults, {});
52
- })
53
- );
54
- })
55
-
56
- ));
57
-
58
- });
59
-
60
-
61
- describe('should lint invalid', function() {
62
-
63
- testCases.invalid.forEach(({ config = {}, it: _it, moddleElement, name, report }, idx) => (
64
-
65
- (_it || it)(getTitle(idx, name), async function() {
66
-
67
- if (!Array.isArray(report)) {
68
- report = [
69
- report
70
- ];
71
- }
72
-
73
- const {
74
- meta
75
- } = await linter.resolveRule(name, config);
76
-
77
- const expectedResults = report.map(report => {
78
- return {
79
- ...report,
80
- meta,
81
- category: 'error'
82
- };
83
- });
84
-
85
- const expectedLintResults = {
86
- [ruleName]: expectedResults
87
- };
88
-
89
- return (
90
- Promise.resolve(moddleElement)
91
- .then(moddleRoot => {
92
- return linter.lint(moddleRoot.root, createLinterConfig(config));
93
- })
94
- .then(lintResults => {
95
- expectEqual(lintResults, expectedLintResults);
96
- })
97
- );
98
- })
99
-
100
- ));
101
-
102
- });
103
-
104
- });
105
-
106
- }
107
-
108
- function getTitle(idx, name) {
109
- return `test case #${ idx + 1 }${ name ? ` ${ name }` : '' }`;
110
- }
111
-
112
- function replacer(_, value) {
113
- if (!value) {
114
- return value;
115
- }
116
-
117
- const { $type } = value;
118
-
119
- if ($type) {
120
- const { $descriptor } = value;
121
-
122
- const { idProperty } = $descriptor;
123
-
124
- if (idProperty) {
125
- const { name } = idProperty;
126
-
127
- const id = value.get(name);
128
-
129
- if (id) {
130
- return id;
131
- } else {
132
- return $type;
133
- }
134
- } else {
135
- return $type;
136
- }
137
- }
138
-
139
- return value;
140
- }
141
-
142
- module.exports = {
143
- expectEqual,
144
- verify,
145
- getTitle,
146
- replacer
1
+ /* global it, describe, beforeEach */
2
+
3
+ const assert = require('assert');
4
+
5
+ const Linter = require('../linter');
6
+
7
+ function createResolver(rule) {
8
+
9
+ return {
10
+ resolveRule: () => Promise.resolve(rule),
11
+
12
+ resolveConfig: () => {
13
+ throw new Error('not implemented');
14
+ }
15
+ };
16
+ }
17
+
18
+ function expectEqual(a, b) {
19
+ assert.deepStrictEqual(JSON.stringify(a, replacer, 2), JSON.stringify(b, replacer, 2));
20
+ }
21
+
22
+ function verify(ruleName, rule, testCases) {
23
+ function createLinterConfig(config = {}) {
24
+ return {
25
+ rules: { [ruleName]: [ 2, config ] }
26
+ };
27
+ }
28
+
29
+ describe(`rules/${ruleName}`, function() {
30
+
31
+ let linter;
32
+
33
+ beforeEach(function() {
34
+ linter = new Linter({
35
+ resolver: createResolver(rule)
36
+ });
37
+ });
38
+
39
+
40
+ describe('should lint valid', function() {
41
+
42
+ testCases.valid.forEach(({ config = {}, it: _it, moddleElement, name }, idx) => (
43
+
44
+ (_it || it)(getTitle(idx, name), function() {
45
+ return (
46
+ Promise.resolve(moddleElement)
47
+ .then(moddleRoot => {
48
+ return linter.lint(moddleRoot.root, createLinterConfig(config));
49
+ })
50
+ .then(lintResults => {
51
+ expectEqual(lintResults, {});
52
+ })
53
+ );
54
+ })
55
+
56
+ ));
57
+
58
+ });
59
+
60
+
61
+ describe('should lint invalid', function() {
62
+
63
+ testCases.invalid.forEach(({ config = {}, it: _it, moddleElement, name, report }, idx) => (
64
+
65
+ (_it || it)(getTitle(idx, name), async function() {
66
+
67
+ if (!Array.isArray(report)) {
68
+ report = [
69
+ report
70
+ ];
71
+ }
72
+
73
+ const {
74
+ meta
75
+ } = await linter.resolveRule(name, config);
76
+
77
+ const expectedResults = report.map(report => {
78
+ return {
79
+ ...report,
80
+ meta,
81
+ category: 'error'
82
+ };
83
+ });
84
+
85
+ const expectedLintResults = {
86
+ [ruleName]: expectedResults
87
+ };
88
+
89
+ return (
90
+ Promise.resolve(moddleElement)
91
+ .then(moddleRoot => {
92
+ return linter.lint(moddleRoot.root, createLinterConfig(config));
93
+ })
94
+ .then(lintResults => {
95
+ expectEqual(lintResults, expectedLintResults);
96
+ })
97
+ );
98
+ })
99
+
100
+ ));
101
+
102
+ });
103
+
104
+ });
105
+
106
+ }
107
+
108
+ function getTitle(idx, name) {
109
+ return `test case #${ idx + 1 }${ name ? ` ${ name }` : '' }`;
110
+ }
111
+
112
+ function replacer(_, value) {
113
+ if (!value) {
114
+ return value;
115
+ }
116
+
117
+ const { $type } = value;
118
+
119
+ if ($type) {
120
+ const { $descriptor } = value;
121
+
122
+ const { idProperty } = $descriptor;
123
+
124
+ if (idProperty) {
125
+ const { name } = idProperty;
126
+
127
+ const id = value.get(name);
128
+
129
+ if (id) {
130
+ return id;
131
+ } else {
132
+ return $type;
133
+ }
134
+ } else {
135
+ return $type;
136
+ }
137
+ }
138
+
139
+ return value;
140
+ }
141
+
142
+ module.exports = {
143
+ expectEqual,
144
+ verify,
145
+ getTitle,
146
+ replacer
147
147
  };
package/lib/traverse.js CHANGED
@@ -1,56 +1,56 @@
1
- /**
2
- * @typedef { import('./types.js').ModdleElement } ModdleElement
3
- *
4
- * @typedef { (element: ModdleElement) => boolean | void } EnterFn
5
- * @typedef { (element: ModdleElement) => void } LeaveFn
6
- */
7
-
8
- /**
9
- * Check if a type is simple, primitive.
10
- *
11
- * @param {string} type
12
- * @return {boolean}
13
- */
14
- function isSimpleType(type) {
15
- return [ 'String', 'Boolean', 'Integer', 'Real' ].includes(type);
16
- }
17
-
18
- /**
19
- * Traverse a moddle tree, depth first from top to bottom
20
- * and call the passed visitor fn.
21
- *
22
- * @param { ModdleElement } element
23
- * @param { { enter?: EnterFn; leave?: LeaveFn } } options
24
- */
25
- module.exports = function traverse(element, options) {
26
-
27
- const enter = options.enter;
28
- const leave = options.leave;
29
-
30
- const enterSubTree = enter && enter(element);
31
-
32
- const descriptor = element.$descriptor;
33
-
34
- if (enterSubTree !== false && !descriptor.isGeneric) {
35
-
36
- const containedProperties = descriptor.properties.filter(p => {
37
- return !p.isAttr && !p.isReference && !isSimpleType(p.type);
38
- });
39
-
40
- containedProperties.forEach(p => {
41
- if (p.name in element) {
42
- const propertyValue = element[p.name];
43
-
44
- if (p.isMany) {
45
- propertyValue.forEach(child => {
46
- traverse(child, options);
47
- });
48
- } else {
49
- traverse(propertyValue, options);
50
- }
51
- }
52
- });
53
- }
54
-
55
- leave && leave(element);
56
- };
1
+ /**
2
+ * @typedef { import('./types.js').ModdleElement } ModdleElement
3
+ *
4
+ * @typedef { (element: ModdleElement) => boolean | void } EnterFn
5
+ * @typedef { (element: ModdleElement) => void } LeaveFn
6
+ */
7
+
8
+ /**
9
+ * Check if a type is simple, primitive.
10
+ *
11
+ * @param {string} type
12
+ * @return {boolean}
13
+ */
14
+ function isSimpleType(type) {
15
+ return [ 'String', 'Boolean', 'Integer', 'Real' ].includes(type);
16
+ }
17
+
18
+ /**
19
+ * Traverse a moddle tree, depth first from top to bottom
20
+ * and call the passed visitor fn.
21
+ *
22
+ * @param { ModdleElement } element
23
+ * @param { { enter?: EnterFn; leave?: LeaveFn } } options
24
+ */
25
+ module.exports = function traverse(element, options) {
26
+
27
+ const enter = options.enter;
28
+ const leave = options.leave;
29
+
30
+ const enterSubTree = enter && enter(element);
31
+
32
+ const descriptor = element.$descriptor;
33
+
34
+ if (enterSubTree !== false && !descriptor.isGeneric) {
35
+
36
+ const containedProperties = descriptor.properties.filter(p => {
37
+ return !p.isAttr && !p.isReference && !isSimpleType(p.type);
38
+ });
39
+
40
+ containedProperties.forEach(p => {
41
+ if (p.name in element) {
42
+ const propertyValue = element[p.name];
43
+
44
+ if (p.isMany) {
45
+ propertyValue.forEach(child => {
46
+ traverse(child, options);
47
+ });
48
+ } else {
49
+ traverse(propertyValue, options);
50
+ }
51
+ }
52
+ });
53
+ }
54
+
55
+ leave && leave(element);
56
+ };