@camunda/linting 3.37.0 → 3.38.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/LICENSE +21 -21
- package/README.md +75 -75
- package/assets/linting.css +37 -37
- package/lib/Linter.js +202 -202
- package/lib/Resolver.js +31 -31
- package/lib/compiled-config.js +7 -2
- package/lib/modeler/Linting.js +124 -124
- package/lib/modeler/LintingAnnotations.js +95 -95
- package/lib/modeler/OverlayComponent.js +60 -60
- package/lib/modeler/index.js +10 -10
- package/lib/plugins/bpmnLintPlugin.js +10 -10
- package/lib/plugins/index.js +4 -4
- package/lib/utils/error-messages.js +828 -828
- package/lib/utils/properties-panel.js +712 -712
- package/lib/utils/types.js +46 -46
- package/lib/utils/version.js +8 -8
- package/package.json +85 -85
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022-present Camunda Services GmbH
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-present Camunda Services GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
# @camunda/linting
|
|
2
|
-
|
|
3
|
-
[](https://github.com/camunda/linting/actions/workflows/CI.yml)
|
|
4
|
-
|
|
5
|
-
The BPMN linter used by the Camunda Desktop and Web Modeler. Batteries included. 🔋
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
* bundles [bpmnlint](https://github.com/bpmn-io/bpmnlint) and [bpmnlint-plugin-camunda-compat](https://github.com/camunda/bpmnlint-plugin-camunda-compat/)
|
|
10
|
-
* configures linter based on `modeler:executionPlatform` and `modeler:executionPlatformVersion`
|
|
11
|
-
* creates error messages to be shown in desktop and web modeler
|
|
12
|
-
* creates errors to be shown in properties panel
|
|
13
|
-
* creates error overlays to be shown on canvas
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
import Modeler from 'bpmn-js/lib/Modeler';
|
|
19
|
-
|
|
20
|
-
import { Linter } from '@camunda/linting';
|
|
21
|
-
|
|
22
|
-
import lintingModule from '@camunda/linting/modeler';
|
|
23
|
-
|
|
24
|
-
import '@camunda/linting/assets/linting.css';
|
|
25
|
-
|
|
26
|
-
const modeler = new Modeler({
|
|
27
|
-
additionalModules: [
|
|
28
|
-
lintingModule
|
|
29
|
-
]
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// configure to be used with desktop or web modeler
|
|
33
|
-
const linter = new Linter({
|
|
34
|
-
modeler: 'web', // `desktop` or `web` modeler, defaults to `desktop`
|
|
35
|
-
type: 'cloud' // `cloud` or `platform` diagrams, defaults to `cloud`
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// lint by passing definitions
|
|
39
|
-
const reports = await linter.lint(definitions);
|
|
40
|
-
|
|
41
|
-
// or passing XML
|
|
42
|
-
const reports = await linter.lint(xml);
|
|
43
|
-
|
|
44
|
-
...
|
|
45
|
-
|
|
46
|
-
// update errors on canvas and in properties panel (requires bpmn-js-properties-panel >= 1.3.0)
|
|
47
|
-
modeler.get('linting').setErrors(reports);
|
|
48
|
-
|
|
49
|
-
// show error by selecting element and properties panel entry
|
|
50
|
-
modeler.get('linting').showError(report);
|
|
51
|
-
|
|
52
|
-
// activate and deactivate errors on canvas
|
|
53
|
-
modeler.get('linting').activate();
|
|
54
|
-
modeler.get('linting').deactivate();
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Development
|
|
58
|
-
|
|
59
|
-
```sh
|
|
60
|
-
# install
|
|
61
|
-
npm i
|
|
62
|
-
|
|
63
|
-
# run tests
|
|
64
|
-
npm t
|
|
65
|
-
|
|
66
|
-
# run tests in watch mode
|
|
67
|
-
npm run test:watch
|
|
68
|
-
|
|
69
|
-
# run example
|
|
70
|
-
npm start
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## License
|
|
74
|
-
|
|
75
|
-
MIT
|
|
1
|
+
# @camunda/linting
|
|
2
|
+
|
|
3
|
+
[](https://github.com/camunda/linting/actions/workflows/CI.yml)
|
|
4
|
+
|
|
5
|
+
The BPMN linter used by the Camunda Desktop and Web Modeler. Batteries included. 🔋
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
* bundles [bpmnlint](https://github.com/bpmn-io/bpmnlint) and [bpmnlint-plugin-camunda-compat](https://github.com/camunda/bpmnlint-plugin-camunda-compat/)
|
|
10
|
+
* configures linter based on `modeler:executionPlatform` and `modeler:executionPlatformVersion`
|
|
11
|
+
* creates error messages to be shown in desktop and web modeler
|
|
12
|
+
* creates errors to be shown in properties panel
|
|
13
|
+
* creates error overlays to be shown on canvas
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import Modeler from 'bpmn-js/lib/Modeler';
|
|
19
|
+
|
|
20
|
+
import { Linter } from '@camunda/linting';
|
|
21
|
+
|
|
22
|
+
import lintingModule from '@camunda/linting/modeler';
|
|
23
|
+
|
|
24
|
+
import '@camunda/linting/assets/linting.css';
|
|
25
|
+
|
|
26
|
+
const modeler = new Modeler({
|
|
27
|
+
additionalModules: [
|
|
28
|
+
lintingModule
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// configure to be used with desktop or web modeler
|
|
33
|
+
const linter = new Linter({
|
|
34
|
+
modeler: 'web', // `desktop` or `web` modeler, defaults to `desktop`
|
|
35
|
+
type: 'cloud' // `cloud` or `platform` diagrams, defaults to `cloud`
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// lint by passing definitions
|
|
39
|
+
const reports = await linter.lint(definitions);
|
|
40
|
+
|
|
41
|
+
// or passing XML
|
|
42
|
+
const reports = await linter.lint(xml);
|
|
43
|
+
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
// update errors on canvas and in properties panel (requires bpmn-js-properties-panel >= 1.3.0)
|
|
47
|
+
modeler.get('linting').setErrors(reports);
|
|
48
|
+
|
|
49
|
+
// show error by selecting element and properties panel entry
|
|
50
|
+
modeler.get('linting').showError(report);
|
|
51
|
+
|
|
52
|
+
// activate and deactivate errors on canvas
|
|
53
|
+
modeler.get('linting').activate();
|
|
54
|
+
modeler.get('linting').deactivate();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Development
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
# install
|
|
61
|
+
npm i
|
|
62
|
+
|
|
63
|
+
# run tests
|
|
64
|
+
npm t
|
|
65
|
+
|
|
66
|
+
# run tests in watch mode
|
|
67
|
+
npm run test:watch
|
|
68
|
+
|
|
69
|
+
# run example
|
|
70
|
+
npm start
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
package/assets/linting.css
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
:root {
|
|
2
|
-
--cl-color-white: hsl(0, 0%, 100%);
|
|
3
|
-
|
|
4
|
-
--cl-color-info: #0f62fe;
|
|
5
|
-
--cl-color-warning: #ff832b;
|
|
6
|
-
--cl-color-error: #da1e26;
|
|
7
|
-
--cl-color-success: #52b415;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.cl-icon, .cl-icon * {
|
|
11
|
-
box-sizing: border-box;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.cl-icon {
|
|
15
|
-
--icon-color: white;
|
|
16
|
-
--icon-bg-color: #333;
|
|
17
|
-
background: var(--icon-bg-color);
|
|
18
|
-
color: var(--icon-color);
|
|
19
|
-
border-radius: 100%;
|
|
20
|
-
height: 20px;
|
|
21
|
-
width: 20px;
|
|
22
|
-
border: solid 4px var(--icon-bg-color);
|
|
23
|
-
display: flex;
|
|
24
|
-
align-items: center;
|
|
25
|
-
justify-content: center;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.cl-icon-error {
|
|
29
|
-
--icon-bg-color: var(--cl-color-error);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.cl-icon-warn {
|
|
33
|
-
--icon-bg-color: var(--cl-color-warning);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.cl-icon-info {
|
|
37
|
-
--icon-bg-color: var(--cl-color-info);
|
|
1
|
+
:root {
|
|
2
|
+
--cl-color-white: hsl(0, 0%, 100%);
|
|
3
|
+
|
|
4
|
+
--cl-color-info: #0f62fe;
|
|
5
|
+
--cl-color-warning: #ff832b;
|
|
6
|
+
--cl-color-error: #da1e26;
|
|
7
|
+
--cl-color-success: #52b415;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.cl-icon, .cl-icon * {
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.cl-icon {
|
|
15
|
+
--icon-color: white;
|
|
16
|
+
--icon-bg-color: #333;
|
|
17
|
+
background: var(--icon-bg-color);
|
|
18
|
+
color: var(--icon-color);
|
|
19
|
+
border-radius: 100%;
|
|
20
|
+
height: 20px;
|
|
21
|
+
width: 20px;
|
|
22
|
+
border: solid 4px var(--icon-bg-color);
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.cl-icon-error {
|
|
29
|
+
--icon-bg-color: var(--cl-color-error);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.cl-icon-warn {
|
|
33
|
+
--icon-bg-color: var(--cl-color-warning);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.cl-icon-info {
|
|
37
|
+
--icon-bg-color: var(--cl-color-info);
|
|
38
38
|
}
|
package/lib/Linter.js
CHANGED
|
@@ -1,203 +1,203 @@
|
|
|
1
|
-
import BpmnModdle from 'bpmn-moddle';
|
|
2
|
-
|
|
3
|
-
import { Linter as BpmnLinter } from 'bpmnlint';
|
|
4
|
-
import StaticResolver from 'bpmnlint/lib/resolver/static-resolver';
|
|
5
|
-
|
|
6
|
-
import Resolver from './Resolver';
|
|
7
|
-
|
|
8
|
-
import { isString } from 'min-dash';
|
|
9
|
-
|
|
10
|
-
import { resolver as RulesResolver } from './compiled-config';
|
|
11
|
-
|
|
12
|
-
import modelerModdle from 'modeler-moddle/resources/modeler.json';
|
|
13
|
-
import zeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe.json';
|
|
14
|
-
import camundaModdle from 'camunda-bpmn-moddle/resources/camunda.json';
|
|
15
|
-
|
|
16
|
-
import { getErrorMessage } from './utils/error-messages';
|
|
17
|
-
import { getEntryIds } from './utils/properties-panel';
|
|
18
|
-
|
|
19
|
-
import { toSemverMinor } from './utils/version';
|
|
20
|
-
|
|
21
|
-
import defaultPlugins from './plugins';
|
|
22
|
-
|
|
23
|
-
import bpmnlintConfig from 'bpmnlint/config/correctness';
|
|
24
|
-
|
|
25
|
-
const NoopResolver = new StaticResolver({});
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {Object} [options]
|
|
29
|
-
* @param {string} [options.modeler='desktop']
|
|
30
|
-
* @param {Array<Object>} [options.plugins=[]]
|
|
31
|
-
* @param {string} [options.type='cloud']
|
|
32
|
-
*/
|
|
33
|
-
export class Linter {
|
|
34
|
-
constructor(options = {}) {
|
|
35
|
-
const {
|
|
36
|
-
modeler = 'desktop',
|
|
37
|
-
plugins = [],
|
|
38
|
-
type = 'cloud'
|
|
39
|
-
} = options;
|
|
40
|
-
|
|
41
|
-
this._moddle = new BpmnModdle({
|
|
42
|
-
modeler: modelerModdle,
|
|
43
|
-
|
|
44
|
-
// Zeebe and Camunda moddle extensions can't be used together
|
|
45
|
-
// cf. https://github.com/camunda/camunda-modeler/issues/3853#issuecomment-1731145100
|
|
46
|
-
...(type === 'cloud' ?
|
|
47
|
-
{ zeebe: zeebeModdle } :
|
|
48
|
-
{ camunda: camundaModdle })
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
this._modeler = modeler;
|
|
52
|
-
this._plugins = [ ...defaultPlugins, ...plugins ];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async lint(contents) {
|
|
56
|
-
let rootElement;
|
|
57
|
-
|
|
58
|
-
if (isString(contents)) {
|
|
59
|
-
({ rootElement } = await this._moddle.fromXML(contents));
|
|
60
|
-
} else {
|
|
61
|
-
rootElement = contents;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const executionPlatform = rootElement.get('modeler:executionPlatform'),
|
|
65
|
-
executionPlatformVersion = rootElement.get('modeler:executionPlatformVersion');
|
|
66
|
-
|
|
67
|
-
if (!executionPlatform || !executionPlatformVersion) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const configName = getConfigName(executionPlatform, executionPlatformVersion);
|
|
72
|
-
|
|
73
|
-
const config = this._createConfig(configName);
|
|
74
|
-
|
|
75
|
-
const resolver = await this._createResolver(configName);
|
|
76
|
-
|
|
77
|
-
const linter = new BpmnLinter({
|
|
78
|
-
config,
|
|
79
|
-
resolver
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const reportsByRule = await linter.lint(rootElement);
|
|
83
|
-
|
|
84
|
-
return Object.entries(reportsByRule).reduce((allReports, entry) => {
|
|
85
|
-
const [ rule, reports ] = entry;
|
|
86
|
-
|
|
87
|
-
return [
|
|
88
|
-
...allReports,
|
|
89
|
-
...reports.map(report => {
|
|
90
|
-
const entryIds = getEntryIds(report);
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
...report,
|
|
94
|
-
executionPlatform,
|
|
95
|
-
executionPlatformVersion,
|
|
96
|
-
message: getErrorMessage(
|
|
97
|
-
report,
|
|
98
|
-
executionPlatform,
|
|
99
|
-
executionPlatformVersion,
|
|
100
|
-
this._modeler
|
|
101
|
-
),
|
|
102
|
-
propertiesPanel: {
|
|
103
|
-
entryIds
|
|
104
|
-
},
|
|
105
|
-
rule
|
|
106
|
-
};
|
|
107
|
-
})
|
|
108
|
-
];
|
|
109
|
-
}, []);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
_createConfig(configName) {
|
|
113
|
-
const configs = [
|
|
114
|
-
{
|
|
115
|
-
extends: `plugin:bpmnlint-plugin-camunda-compat/${ configName }`
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
extends: 'bpmnlint:correctness'
|
|
119
|
-
},
|
|
120
|
-
...this._plugins.map(({ config = {} }) => config)
|
|
121
|
-
];
|
|
122
|
-
|
|
123
|
-
return configs.reduce(
|
|
124
|
-
(config, _config) => {
|
|
125
|
-
let { extends: _extends = [], rules = {} } = _config;
|
|
126
|
-
|
|
127
|
-
if (isString(_extends)) {
|
|
128
|
-
_extends = [ _extends ];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
extends: [ ...config.extends, ..._extends ],
|
|
133
|
-
rules: {
|
|
134
|
-
...config.rules,
|
|
135
|
-
...rules
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
extends: [],
|
|
141
|
-
rules: {}
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async _createResolver(configName) {
|
|
147
|
-
const { configs } = await import('bpmnlint-plugin-camunda-compat');
|
|
148
|
-
|
|
149
|
-
let { [ configName ]: config } = configs;
|
|
150
|
-
|
|
151
|
-
if (!config) {
|
|
152
|
-
config = {
|
|
153
|
-
rules: {}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
config.rules = addConfig(config.rules, {
|
|
158
|
-
modeler: this._modeler
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const ConfigResolver = new StaticResolver({
|
|
162
|
-
[ `config:bpmnlint-plugin-camunda-compat/${ configName }` ]: config,
|
|
163
|
-
'config:bpmnlint/correctness': bpmnlintConfig
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
return new Resolver([
|
|
167
|
-
ConfigResolver,
|
|
168
|
-
RulesResolver,
|
|
169
|
-
...this._plugins.map(({ resolver = NoopResolver }) => resolver)
|
|
170
|
-
]);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function getConfigName(executionPlatform, executionPlatformVersion) {
|
|
175
|
-
return [
|
|
176
|
-
...executionPlatform.split(' ').map(toLowerCase),
|
|
177
|
-
...toSemverMinor(executionPlatformVersion).split('.')
|
|
178
|
-
].join('-');
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function toLowerCase(string) {
|
|
182
|
-
return string.toLowerCase();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function addConfig(rules, configToAdd) {
|
|
186
|
-
let rulesWithConfig = {};
|
|
187
|
-
|
|
188
|
-
for (let name in rules) {
|
|
189
|
-
let type, config;
|
|
190
|
-
|
|
191
|
-
if (Array.isArray(rules[ name ])) {
|
|
192
|
-
type = rules[ name ][0];
|
|
193
|
-
config = rules[ name ][1] || {};
|
|
194
|
-
} else {
|
|
195
|
-
type = rules[ name ];
|
|
196
|
-
config = {};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
rulesWithConfig[ name ] = [ type, { ...config, ...configToAdd } ];
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return rulesWithConfig;
|
|
1
|
+
import BpmnModdle from 'bpmn-moddle';
|
|
2
|
+
|
|
3
|
+
import { Linter as BpmnLinter } from 'bpmnlint';
|
|
4
|
+
import StaticResolver from 'bpmnlint/lib/resolver/static-resolver';
|
|
5
|
+
|
|
6
|
+
import Resolver from './Resolver';
|
|
7
|
+
|
|
8
|
+
import { isString } from 'min-dash';
|
|
9
|
+
|
|
10
|
+
import { resolver as RulesResolver } from './compiled-config';
|
|
11
|
+
|
|
12
|
+
import modelerModdle from 'modeler-moddle/resources/modeler.json';
|
|
13
|
+
import zeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe.json';
|
|
14
|
+
import camundaModdle from 'camunda-bpmn-moddle/resources/camunda.json';
|
|
15
|
+
|
|
16
|
+
import { getErrorMessage } from './utils/error-messages';
|
|
17
|
+
import { getEntryIds } from './utils/properties-panel';
|
|
18
|
+
|
|
19
|
+
import { toSemverMinor } from './utils/version';
|
|
20
|
+
|
|
21
|
+
import defaultPlugins from './plugins';
|
|
22
|
+
|
|
23
|
+
import bpmnlintConfig from 'bpmnlint/config/correctness';
|
|
24
|
+
|
|
25
|
+
const NoopResolver = new StaticResolver({});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Object} [options]
|
|
29
|
+
* @param {string} [options.modeler='desktop']
|
|
30
|
+
* @param {Array<Object>} [options.plugins=[]]
|
|
31
|
+
* @param {string} [options.type='cloud']
|
|
32
|
+
*/
|
|
33
|
+
export class Linter {
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
const {
|
|
36
|
+
modeler = 'desktop',
|
|
37
|
+
plugins = [],
|
|
38
|
+
type = 'cloud'
|
|
39
|
+
} = options;
|
|
40
|
+
|
|
41
|
+
this._moddle = new BpmnModdle({
|
|
42
|
+
modeler: modelerModdle,
|
|
43
|
+
|
|
44
|
+
// Zeebe and Camunda moddle extensions can't be used together
|
|
45
|
+
// cf. https://github.com/camunda/camunda-modeler/issues/3853#issuecomment-1731145100
|
|
46
|
+
...(type === 'cloud' ?
|
|
47
|
+
{ zeebe: zeebeModdle } :
|
|
48
|
+
{ camunda: camundaModdle })
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
this._modeler = modeler;
|
|
52
|
+
this._plugins = [ ...defaultPlugins, ...plugins ];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async lint(contents) {
|
|
56
|
+
let rootElement;
|
|
57
|
+
|
|
58
|
+
if (isString(contents)) {
|
|
59
|
+
({ rootElement } = await this._moddle.fromXML(contents));
|
|
60
|
+
} else {
|
|
61
|
+
rootElement = contents;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const executionPlatform = rootElement.get('modeler:executionPlatform'),
|
|
65
|
+
executionPlatformVersion = rootElement.get('modeler:executionPlatformVersion');
|
|
66
|
+
|
|
67
|
+
if (!executionPlatform || !executionPlatformVersion) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const configName = getConfigName(executionPlatform, executionPlatformVersion);
|
|
72
|
+
|
|
73
|
+
const config = this._createConfig(configName);
|
|
74
|
+
|
|
75
|
+
const resolver = await this._createResolver(configName);
|
|
76
|
+
|
|
77
|
+
const linter = new BpmnLinter({
|
|
78
|
+
config,
|
|
79
|
+
resolver
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const reportsByRule = await linter.lint(rootElement);
|
|
83
|
+
|
|
84
|
+
return Object.entries(reportsByRule).reduce((allReports, entry) => {
|
|
85
|
+
const [ rule, reports ] = entry;
|
|
86
|
+
|
|
87
|
+
return [
|
|
88
|
+
...allReports,
|
|
89
|
+
...reports.map(report => {
|
|
90
|
+
const entryIds = getEntryIds(report);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
...report,
|
|
94
|
+
executionPlatform,
|
|
95
|
+
executionPlatformVersion,
|
|
96
|
+
message: getErrorMessage(
|
|
97
|
+
report,
|
|
98
|
+
executionPlatform,
|
|
99
|
+
executionPlatformVersion,
|
|
100
|
+
this._modeler
|
|
101
|
+
),
|
|
102
|
+
propertiesPanel: {
|
|
103
|
+
entryIds
|
|
104
|
+
},
|
|
105
|
+
rule
|
|
106
|
+
};
|
|
107
|
+
})
|
|
108
|
+
];
|
|
109
|
+
}, []);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_createConfig(configName) {
|
|
113
|
+
const configs = [
|
|
114
|
+
{
|
|
115
|
+
extends: `plugin:bpmnlint-plugin-camunda-compat/${ configName }`
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
extends: 'bpmnlint:correctness'
|
|
119
|
+
},
|
|
120
|
+
...this._plugins.map(({ config = {} }) => config)
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
return configs.reduce(
|
|
124
|
+
(config, _config) => {
|
|
125
|
+
let { extends: _extends = [], rules = {} } = _config;
|
|
126
|
+
|
|
127
|
+
if (isString(_extends)) {
|
|
128
|
+
_extends = [ _extends ];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
extends: [ ...config.extends, ..._extends ],
|
|
133
|
+
rules: {
|
|
134
|
+
...config.rules,
|
|
135
|
+
...rules
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
extends: [],
|
|
141
|
+
rules: {}
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async _createResolver(configName) {
|
|
147
|
+
const { configs } = await import('bpmnlint-plugin-camunda-compat');
|
|
148
|
+
|
|
149
|
+
let { [ configName ]: config } = configs;
|
|
150
|
+
|
|
151
|
+
if (!config) {
|
|
152
|
+
config = {
|
|
153
|
+
rules: {}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
config.rules = addConfig(config.rules, {
|
|
158
|
+
modeler: this._modeler
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const ConfigResolver = new StaticResolver({
|
|
162
|
+
[ `config:bpmnlint-plugin-camunda-compat/${ configName }` ]: config,
|
|
163
|
+
'config:bpmnlint/correctness': bpmnlintConfig
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return new Resolver([
|
|
167
|
+
ConfigResolver,
|
|
168
|
+
RulesResolver,
|
|
169
|
+
...this._plugins.map(({ resolver = NoopResolver }) => resolver)
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getConfigName(executionPlatform, executionPlatformVersion) {
|
|
175
|
+
return [
|
|
176
|
+
...executionPlatform.split(' ').map(toLowerCase),
|
|
177
|
+
...toSemverMinor(executionPlatformVersion).split('.')
|
|
178
|
+
].join('-');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function toLowerCase(string) {
|
|
182
|
+
return string.toLowerCase();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function addConfig(rules, configToAdd) {
|
|
186
|
+
let rulesWithConfig = {};
|
|
187
|
+
|
|
188
|
+
for (let name in rules) {
|
|
189
|
+
let type, config;
|
|
190
|
+
|
|
191
|
+
if (Array.isArray(rules[ name ])) {
|
|
192
|
+
type = rules[ name ][0];
|
|
193
|
+
config = rules[ name ][1] || {};
|
|
194
|
+
} else {
|
|
195
|
+
type = rules[ name ];
|
|
196
|
+
config = {};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
rulesWithConfig[ name ] = [ type, { ...config, ...configToAdd } ];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return rulesWithConfig;
|
|
203
203
|
}
|