@camunda/linting 3.11.0 → 3.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.
package/lib/Linter.js CHANGED
@@ -1,200 +1,200 @@
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 { getDocumentationUrl } from './utils/documentation';
22
-
23
- const NoopResolver = new StaticResolver({});
24
-
25
- /**
26
- * @param {Object} [options]
27
- * @param {string} [options.modeler='desktop']
28
- * @param {Array<Object>} [options.plugins=[]]
29
- * @param {string} [options.type='cloud']
30
- */
31
- export class Linter {
32
- constructor(options = {}) {
33
- const {
34
- modeler = 'desktop',
35
- plugins = [],
36
- type = 'cloud'
37
- } = options;
38
-
39
- this._moddle = new BpmnModdle({
40
- modeler: modelerModdle,
41
-
42
- // Zeebe and Camunda moddle extensions can't be used together
43
- // cf. https://github.com/camunda/camunda-modeler/issues/3853#issuecomment-1731145100
44
- ...(type === 'cloud' ?
45
- { zeebe: zeebeModdle } :
46
- { camunda: camundaModdle })
47
- });
48
-
49
- this._modeler = modeler;
50
- this._plugins = plugins;
51
- }
52
-
53
- async lint(contents) {
54
- let rootElement;
55
-
56
- if (isString(contents)) {
57
- ({ rootElement } = await this._moddle.fromXML(contents));
58
- } else {
59
- rootElement = contents;
60
- }
61
-
62
- const executionPlatform = rootElement.get('modeler:executionPlatform'),
63
- executionPlatformVersion = rootElement.get('modeler:executionPlatformVersion');
64
-
65
- if (!executionPlatform || !executionPlatformVersion) {
66
- return [];
67
- }
68
-
69
- const configName = getConfigName(executionPlatform, executionPlatformVersion);
70
-
71
- const config = this._createConfig(configName);
72
-
73
- const resolver = await this._createResolver(configName);
74
-
75
- const linter = new BpmnLinter({
76
- config,
77
- resolver
78
- });
79
-
80
- const reportsByRule = await linter.lint(rootElement);
81
-
82
- return Object.entries(reportsByRule).reduce((allReports, entry) => {
83
- const [ rule, reports ] = entry;
84
-
85
- return [
86
- ...allReports,
87
- ...reports.map(report => {
88
- const entryIds = getEntryIds(report);
89
-
90
- return {
91
- ...report,
92
- executionPlatform,
93
- executionPlatformVersion,
94
- message: getErrorMessage(
95
- report,
96
- executionPlatform,
97
- executionPlatformVersion,
98
- this._modeler
99
- ),
100
- propertiesPanel: {
101
- entryIds
102
- },
103
- documentation: {
104
- url: getDocumentationUrl(rule)
105
- },
106
- rule
107
- };
108
- })
109
- ];
110
- }, []);
111
- }
112
-
113
- _createConfig(configName) {
114
- const configs = [
115
- {
116
- extends: `plugin:bpmnlint-plugin-camunda-compat/${ configName }`
117
- },
118
- ...this._plugins.map(({ config = {} }) => config)
119
- ];
120
-
121
- return configs.reduce(
122
- (config, _config) => {
123
- let { extends: _extends = [], rules = {} } = _config;
124
-
125
- if (isString(_extends)) {
126
- _extends = [ _extends ];
127
- }
128
-
129
- return {
130
- extends: [ ...config.extends, ..._extends ],
131
- rules: {
132
- ...config.rules,
133
- ...rules
134
- }
135
- };
136
- },
137
- {
138
- extends: [],
139
- rules: {}
140
- }
141
- );
142
- }
143
-
144
- async _createResolver(configName) {
145
- const { configs } = await import('bpmnlint-plugin-camunda-compat');
146
-
147
- let { [ configName ]: config } = configs;
148
-
149
- if (!config) {
150
- config = {
151
- rules: {}
152
- };
153
- }
154
-
155
- config.rules = addConfig(config.rules, {
156
- modeler: this._modeler
157
- });
158
-
159
- const ConfigResolver = new StaticResolver({
160
- [ `config:bpmnlint-plugin-camunda-compat/${ configName }` ]: config
161
- });
162
-
163
- return new Resolver([
164
- ConfigResolver,
165
- RulesResolver,
166
- ...this._plugins.map(({ resolver = NoopResolver }) => resolver)
167
- ]);
168
- }
169
- }
170
-
171
- function getConfigName(executionPlatform, executionPlatformVersion) {
172
- return [
173
- ...executionPlatform.split(' ').map(toLowerCase),
174
- ...toSemverMinor(executionPlatformVersion).split('.')
175
- ].join('-');
176
- }
177
-
178
- function toLowerCase(string) {
179
- return string.toLowerCase();
180
- }
181
-
182
- function addConfig(rules, configToAdd) {
183
- let rulesWithConfig = {};
184
-
185
- for (let name in rules) {
186
- let type, config;
187
-
188
- if (Array.isArray(rules[ name ])) {
189
- type = rules[ name ][0];
190
- config = rules[ name ][1] || {};
191
- } else {
192
- type = rules[ name ];
193
- config = {};
194
- }
195
-
196
- rulesWithConfig[ name ] = [ type, { ...config, ...configToAdd } ];
197
- }
198
-
199
- 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 { getDocumentationUrl } from './utils/documentation';
22
+
23
+ const NoopResolver = new StaticResolver({});
24
+
25
+ /**
26
+ * @param {Object} [options]
27
+ * @param {string} [options.modeler='desktop']
28
+ * @param {Array<Object>} [options.plugins=[]]
29
+ * @param {string} [options.type='cloud']
30
+ */
31
+ export class Linter {
32
+ constructor(options = {}) {
33
+ const {
34
+ modeler = 'desktop',
35
+ plugins = [],
36
+ type = 'cloud'
37
+ } = options;
38
+
39
+ this._moddle = new BpmnModdle({
40
+ modeler: modelerModdle,
41
+
42
+ // Zeebe and Camunda moddle extensions can't be used together
43
+ // cf. https://github.com/camunda/camunda-modeler/issues/3853#issuecomment-1731145100
44
+ ...(type === 'cloud' ?
45
+ { zeebe: zeebeModdle } :
46
+ { camunda: camundaModdle })
47
+ });
48
+
49
+ this._modeler = modeler;
50
+ this._plugins = plugins;
51
+ }
52
+
53
+ async lint(contents) {
54
+ let rootElement;
55
+
56
+ if (isString(contents)) {
57
+ ({ rootElement } = await this._moddle.fromXML(contents));
58
+ } else {
59
+ rootElement = contents;
60
+ }
61
+
62
+ const executionPlatform = rootElement.get('modeler:executionPlatform'),
63
+ executionPlatformVersion = rootElement.get('modeler:executionPlatformVersion');
64
+
65
+ if (!executionPlatform || !executionPlatformVersion) {
66
+ return [];
67
+ }
68
+
69
+ const configName = getConfigName(executionPlatform, executionPlatformVersion);
70
+
71
+ const config = this._createConfig(configName);
72
+
73
+ const resolver = await this._createResolver(configName);
74
+
75
+ const linter = new BpmnLinter({
76
+ config,
77
+ resolver
78
+ });
79
+
80
+ const reportsByRule = await linter.lint(rootElement);
81
+
82
+ return Object.entries(reportsByRule).reduce((allReports, entry) => {
83
+ const [ rule, reports ] = entry;
84
+
85
+ return [
86
+ ...allReports,
87
+ ...reports.map(report => {
88
+ const entryIds = getEntryIds(report);
89
+
90
+ return {
91
+ ...report,
92
+ executionPlatform,
93
+ executionPlatformVersion,
94
+ message: getErrorMessage(
95
+ report,
96
+ executionPlatform,
97
+ executionPlatformVersion,
98
+ this._modeler
99
+ ),
100
+ propertiesPanel: {
101
+ entryIds
102
+ },
103
+ documentation: {
104
+ url: getDocumentationUrl(rule)
105
+ },
106
+ rule
107
+ };
108
+ })
109
+ ];
110
+ }, []);
111
+ }
112
+
113
+ _createConfig(configName) {
114
+ const configs = [
115
+ {
116
+ extends: `plugin:bpmnlint-plugin-camunda-compat/${ configName }`
117
+ },
118
+ ...this._plugins.map(({ config = {} }) => config)
119
+ ];
120
+
121
+ return configs.reduce(
122
+ (config, _config) => {
123
+ let { extends: _extends = [], rules = {} } = _config;
124
+
125
+ if (isString(_extends)) {
126
+ _extends = [ _extends ];
127
+ }
128
+
129
+ return {
130
+ extends: [ ...config.extends, ..._extends ],
131
+ rules: {
132
+ ...config.rules,
133
+ ...rules
134
+ }
135
+ };
136
+ },
137
+ {
138
+ extends: [],
139
+ rules: {}
140
+ }
141
+ );
142
+ }
143
+
144
+ async _createResolver(configName) {
145
+ const { configs } = await import('bpmnlint-plugin-camunda-compat');
146
+
147
+ let { [ configName ]: config } = configs;
148
+
149
+ if (!config) {
150
+ config = {
151
+ rules: {}
152
+ };
153
+ }
154
+
155
+ config.rules = addConfig(config.rules, {
156
+ modeler: this._modeler
157
+ });
158
+
159
+ const ConfigResolver = new StaticResolver({
160
+ [ `config:bpmnlint-plugin-camunda-compat/${ configName }` ]: config
161
+ });
162
+
163
+ return new Resolver([
164
+ ConfigResolver,
165
+ RulesResolver,
166
+ ...this._plugins.map(({ resolver = NoopResolver }) => resolver)
167
+ ]);
168
+ }
169
+ }
170
+
171
+ function getConfigName(executionPlatform, executionPlatformVersion) {
172
+ return [
173
+ ...executionPlatform.split(' ').map(toLowerCase),
174
+ ...toSemverMinor(executionPlatformVersion).split('.')
175
+ ].join('-');
176
+ }
177
+
178
+ function toLowerCase(string) {
179
+ return string.toLowerCase();
180
+ }
181
+
182
+ function addConfig(rules, configToAdd) {
183
+ let rulesWithConfig = {};
184
+
185
+ for (let name in rules) {
186
+ let type, config;
187
+
188
+ if (Array.isArray(rules[ name ])) {
189
+ type = rules[ name ][0];
190
+ config = rules[ name ][1] || {};
191
+ } else {
192
+ type = rules[ name ];
193
+ config = {};
194
+ }
195
+
196
+ rulesWithConfig[ name ] = [ type, { ...config, ...configToAdd } ];
197
+ }
198
+
199
+ return rulesWithConfig;
200
200
  }
@@ -86,7 +86,7 @@ export function getErrorMessage(report, executionPlatform, executionPlatformVers
86
86
  }
87
87
 
88
88
  if (type === ERROR_TYPES.ELEMENT_COLLAPSED_NOT_ALLOWED) {
89
- return getElementCollapsedNotAllowedErrorMessage(report);
89
+ return getElementCollapsedNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion);
90
90
  }
91
91
 
92
92
  if (type === ERROR_TYPES.ELEMENT_PROPERTY_VALUE_DUPLICATED) {
@@ -176,18 +176,18 @@ function getChildElementTypeNotAllowedErrorMessage(report, executionPlatform, ex
176
176
  );
177
177
  }
178
178
 
179
- function getElementCollapsedNotAllowedErrorMessage(report) {
179
+ function getElementCollapsedNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) {
180
180
  const {
181
181
  data,
182
182
  message
183
183
  } = report;
184
184
 
185
- const { node } = data;
185
+ const { allowedVersion, node } = data;
186
186
 
187
187
  const typeString = getTypeString(node);
188
188
 
189
189
  if (is(node, 'bpmn:SubProcess')) {
190
- return `${ getIndefiniteArticle(typeString) } <${ typeString }> must be expanded`;
190
+ return getSupportedMessage(`A collapsed <${typeString}>`, executionPlatform, executionPlatformVersion, allowedVersion);
191
191
  }
192
192
 
193
193
  return message;
@@ -327,6 +327,10 @@ function getExtensionElementRequiredErrorMessage(report) {
327
327
  return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a defined <Implementation>`;
328
328
  }
329
329
 
330
+ if (requiredExtensionElement === 'zeebe:FormDefinition') {
331
+ return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a defined <Form>`;
332
+ }
333
+
330
334
  return message;
331
335
  }
332
336
 
package/package.json CHANGED
@@ -1,84 +1,84 @@
1
- {
2
- "name": "@camunda/linting",
3
- "version": "3.11.0",
4
- "description": "Linting for Camunda",
5
- "main": "index.js",
6
- "scripts": {
7
- "all": "npm run lint && npm test",
8
- "dev": "npm run test:watch",
9
- "lint": "eslint .",
10
- "start": "npm run start:cloud",
11
- "start:platform": "cross-env SINGLE_START=platform npm run test:watch",
12
- "start:cloud": "cross-env SINGLE_START=cloud npm run test:watch",
13
- "test": "npm run compile-config && karma start",
14
- "test:watch": "npm test -- --auto-watch --no-single-run",
15
- "compile-config": "node tasks/compile-config.js",
16
- "prepublish": "npm run compile-config"
17
- },
18
- "keywords": [
19
- "bpmnlint",
20
- "camunda"
21
- ],
22
- "author": {
23
- "name": "Philipp Fromme",
24
- "url": "https://github.com/philippfromme"
25
- },
26
- "repository": {
27
- "type": "git",
28
- "url": "https://github.com/camunda/linting"
29
- },
30
- "license": "MIT",
31
- "dependencies": {
32
- "@bpmn-io/diagram-js-ui": "^0.2.2",
33
- "bpmn-moddle": "^8.0.0",
34
- "bpmnlint": "^9.2.0",
35
- "bpmnlint-plugin-camunda-compat": "^2.12.0",
36
- "bpmnlint-utils": "^1.0.2",
37
- "camunda-bpmn-moddle": "^7.0.1",
38
- "clsx": "^2.0.0",
39
- "min-dash": "^4.0.0",
40
- "min-dom": "^4.1.0",
41
- "modeler-moddle": "^0.2.0",
42
- "semver-compare": "^1.0.0",
43
- "zeebe-bpmn-moddle": "^1.0.0"
44
- },
45
- "devDependencies": {
46
- "bpmn-js": "^13.2.2",
47
- "bpmn-js-element-templates": "^1.3.0",
48
- "bpmn-js-properties-panel": "^5.6.1",
49
- "camunda-bpmn-js-behaviors": "^1.2.2",
50
- "chai": "^4.3.7",
51
- "cross-env": "^7.0.3",
52
- "eslint": "^8.45.0",
53
- "eslint-plugin-bpmn-io": "^1.0.0",
54
- "karma": "^6.4.2",
55
- "karma-chrome-launcher": "^3.2.0",
56
- "karma-debug-launcher": "0.0.5",
57
- "karma-env-preprocessor": "^0.1.1",
58
- "karma-mocha": "^2.0.1",
59
- "karma-sinon-chai": "^2.0.2",
60
- "karma-webpack": "^5.0.0",
61
- "mocha": "^10.2.0",
62
- "mocha-test-container-support": "^0.2.0",
63
- "puppeteer": "^20.9.0",
64
- "sinon": "^15.0.1",
65
- "sinon-chai": "^3.7.0",
66
- "webpack": "^5.75.0"
67
- },
68
- "peerDependencies": {
69
- "bpmn-js-properties-panel": ">= 2.0.0"
70
- },
71
- "peerDependenciesMeta": {
72
- "bpmn-js-properties-panel": {
73
- "optional": true
74
- }
75
- },
76
- "files": [
77
- "assets",
78
- "lib",
79
- "modeler.js"
80
- ],
81
- "publishConfig": {
82
- "access": "public"
83
- }
84
- }
1
+ {
2
+ "name": "@camunda/linting",
3
+ "version": "3.13.0",
4
+ "description": "Linting for Camunda",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "all": "npm run lint && npm test",
8
+ "dev": "npm run test:watch",
9
+ "lint": "eslint .",
10
+ "start": "npm run start:cloud",
11
+ "start:platform": "cross-env SINGLE_START=platform npm run test:watch",
12
+ "start:cloud": "cross-env SINGLE_START=cloud npm run test:watch",
13
+ "test": "npm run compile-config && karma start",
14
+ "test:watch": "npm test -- --auto-watch --no-single-run",
15
+ "compile-config": "node tasks/compile-config.js",
16
+ "prepublish": "npm run compile-config"
17
+ },
18
+ "keywords": [
19
+ "bpmnlint",
20
+ "camunda"
21
+ ],
22
+ "author": {
23
+ "name": "Philipp Fromme",
24
+ "url": "https://github.com/philippfromme"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/camunda/linting"
29
+ },
30
+ "license": "MIT",
31
+ "dependencies": {
32
+ "@bpmn-io/diagram-js-ui": "^0.2.2",
33
+ "bpmn-moddle": "^8.0.0",
34
+ "bpmnlint": "^9.2.0",
35
+ "bpmnlint-plugin-camunda-compat": "^2.14.0",
36
+ "bpmnlint-utils": "^1.0.2",
37
+ "camunda-bpmn-moddle": "^7.0.1",
38
+ "clsx": "^2.0.0",
39
+ "min-dash": "^4.0.0",
40
+ "min-dom": "^4.1.0",
41
+ "modeler-moddle": "^0.2.0",
42
+ "semver-compare": "^1.0.0",
43
+ "zeebe-bpmn-moddle": "^1.0.0"
44
+ },
45
+ "devDependencies": {
46
+ "bpmn-js": "^13.2.2",
47
+ "bpmn-js-element-templates": "^1.3.0",
48
+ "bpmn-js-properties-panel": "^5.6.1",
49
+ "camunda-bpmn-js-behaviors": "^1.2.2",
50
+ "chai": "^4.3.7",
51
+ "cross-env": "^7.0.3",
52
+ "eslint": "^8.45.0",
53
+ "eslint-plugin-bpmn-io": "^1.0.0",
54
+ "karma": "^6.4.2",
55
+ "karma-chrome-launcher": "^3.2.0",
56
+ "karma-debug-launcher": "0.0.5",
57
+ "karma-env-preprocessor": "^0.1.1",
58
+ "karma-mocha": "^2.0.1",
59
+ "karma-sinon-chai": "^2.0.2",
60
+ "karma-webpack": "^5.0.0",
61
+ "mocha": "^10.2.0",
62
+ "mocha-test-container-support": "^0.2.0",
63
+ "puppeteer": "^20.9.0",
64
+ "sinon": "^15.0.1",
65
+ "sinon-chai": "^3.7.0",
66
+ "webpack": "^5.75.0"
67
+ },
68
+ "peerDependencies": {
69
+ "bpmn-js-properties-panel": ">= 2.0.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "bpmn-js-properties-panel": {
73
+ "optional": true
74
+ }
75
+ },
76
+ "files": [
77
+ "assets",
78
+ "lib",
79
+ "modeler.js"
80
+ ],
81
+ "publishConfig": {
82
+ "access": "public"
83
+ }
84
+ }