bpmnlint 7.5.0 → 7.8.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 CHANGED
@@ -6,6 +6,20 @@ All notable changes to [bpmnlint](https://github.com/bpmn-io/bpmnlint) are docum
6
6
 
7
7
  ___Note:__ Yet to be released changes appear here._
8
8
 
9
+ ## 7.8.0
10
+
11
+ * `FEAT`: be able to configure rules ([#82](https://github.com/bpmn-io/bpmnlint/pull/82))
12
+ * `FEAT`: be able to configure rules when testing ([#83](https://github.com/bpmn-io/bpmnlint/pull/83))
13
+
14
+ ## 7.7.0
15
+
16
+ * `FEAT`: fuzzy test for equality of nodes when using `RuleTester#verify` ([#79](https://github.com/bpmn-io/bpmnlint/pull/79/files))
17
+
18
+ ## 7.6.0
19
+
20
+ * `FEAT`: allow passing object as third parameter to `Reporter#report` ([#75](https://github.com/bpmn-io/bpmnlint/pull/75))
21
+
22
+
9
23
  ## 7.5.0
10
24
 
11
25
  * `FEAT`: add optional `path` parameter to `Reporter#report` ([#73](https://github.com/bpmn-io/bpmnlint/pull/73))
package/lib/linter.js CHANGED
@@ -77,7 +77,7 @@ Linter.prototype.applyRule = function applyRule(moddleRoot, ruleDefinition) {
77
77
  };
78
78
 
79
79
 
80
- Linter.prototype.resolveRule = function(name) {
80
+ Linter.prototype.resolveRule = function(name, config) {
81
81
 
82
82
  const {
83
83
  pkg,
@@ -98,7 +98,7 @@ Linter.prototype.resolveRule = function(name) {
98
98
  throw new Error(`unknown rule <${name}>`);
99
99
  }
100
100
 
101
- const rule = this.cachedRules[id] = ruleFactory();
101
+ const rule = this.cachedRules[id] = ruleFactory(config);
102
102
 
103
103
  return rule;
104
104
  });
@@ -163,10 +163,11 @@ Linter.prototype.resolveRules = function(config) {
163
163
  const loaders = enabledRules.map((definition) => {
164
164
 
165
165
  const {
166
- name
166
+ name,
167
+ config
167
168
  } = definition;
168
169
 
169
- return this.resolveRule(name).then(function(rule) {
170
+ return this.resolveRule(name, config).then(function(rule) {
170
171
  return {
171
172
  ...definition,
172
173
  rule
package/lib/test-rule.js CHANGED
@@ -1,5 +1,11 @@
1
1
  const traverse = require('./traverse');
2
2
 
3
+ const {
4
+ isArray,
5
+ isObject
6
+ } = require('min-dash');
7
+
8
+
3
9
  class Reporter {
4
10
  constructor({ moddleRoot, rule }) {
5
11
  this.rule = rule;
@@ -8,19 +14,42 @@ class Reporter {
8
14
  this.report = this.report.bind(this);
9
15
  }
10
16
 
17
+ /**
18
+ * @param {string} id
19
+ * @param {string} message
20
+ * @param {string[]|Object} path
21
+ *
22
+ * @example
23
+ *
24
+ * Reporter.report('foo', 'Foo error', [ 'foo', 'bar', 'baz' ]);
25
+ *
26
+ * @example
27
+ *
28
+ * Reporter.report('foo', 'Foo error', {
29
+ * path: [ 'foo', 'bar', 'baz' ],
30
+ * foo: 'foo'
31
+ * });
32
+ */
11
33
  report(id, message, path) {
12
34
  let report = {
13
35
  id,
14
36
  message
15
37
  };
16
38
 
17
- if (path) {
39
+ if (path && isArray(path)) {
18
40
  report = {
19
41
  ...report,
20
42
  path
21
43
  };
22
44
  }
23
45
 
46
+ if (path && isObject(path)) {
47
+ report = {
48
+ ...report,
49
+ ...path
50
+ };
51
+ }
52
+
24
53
  this.messages.push(report);
25
54
  }
26
55
  }
@@ -11,14 +11,15 @@ function createResolver(rule) {
11
11
  }
12
12
 
13
13
  function expectEqual(a, b) {
14
- assert.deepStrictEqual(a, b);
14
+ assert.deepStrictEqual(JSON.stringify(a, replacer, 2), JSON.stringify(b, replacer, 2));
15
15
  }
16
16
 
17
-
18
17
  function verify(ruleName, rule, testCases) {
19
- const linterConfig = {
20
- rules: { [ruleName]: 2 }
21
- };
18
+ function createLinterConfig(config = {}) {
19
+ return {
20
+ rules: { [ruleName]: [ 2, config ] }
21
+ };
22
+ }
22
23
 
23
24
  describe(`rules/${ruleName}`, function() {
24
25
 
@@ -33,13 +34,13 @@ function verify(ruleName, rule, testCases) {
33
34
 
34
35
  describe('should lint valid', function() {
35
36
 
36
- testCases.valid.forEach(({ moddleElement, name, it: _it }, idx) => (
37
+ testCases.valid.forEach(({ config = {}, it: _it, moddleElement, name }, idx) => (
37
38
 
38
39
  (_it || it)(getTitle(idx, name), function() {
39
40
  return (
40
41
  Promise.resolve(moddleElement)
41
42
  .then(moddleRoot => {
42
- return linter.lint(moddleRoot.root, linterConfig);
43
+ return linter.lint(moddleRoot.root, createLinterConfig(config));
43
44
  })
44
45
  .then(lintResults => {
45
46
  expectEqual(lintResults, {});
@@ -54,7 +55,7 @@ function verify(ruleName, rule, testCases) {
54
55
 
55
56
  describe('should lint invalid', function() {
56
57
 
57
- testCases.invalid.forEach(({ moddleElement, name, report, it: _it }, idx) => (
58
+ testCases.invalid.forEach(({ config = {}, it: _it, moddleElement, name, report }, idx) => (
58
59
 
59
60
  (_it || it)(getTitle(idx, name), function() {
60
61
 
@@ -78,7 +79,7 @@ function verify(ruleName, rule, testCases) {
78
79
  return (
79
80
  Promise.resolve(moddleElement)
80
81
  .then(moddleRoot => {
81
- return linter.lint(moddleRoot.root, linterConfig);
82
+ return linter.lint(moddleRoot.root, createLinterConfig(config));
82
83
  })
83
84
  .then(lintResults => {
84
85
  expectEqual(lintResults, expectedLintResults);
@@ -98,7 +99,39 @@ function getTitle(idx, name) {
98
99
  return `test case #${ idx + 1 }${ name ? ` ${ name }`: '' }`;
99
100
  }
100
101
 
102
+ function replacer(_, value) {
103
+ if (!value) {
104
+ return value;
105
+ }
106
+
107
+ const { $type } = value;
108
+
109
+ if ($type) {
110
+ const { $descriptor } = value;
111
+
112
+ const { idProperty } = $descriptor;
113
+
114
+ if (idProperty) {
115
+ const { name } = idProperty;
116
+
117
+ const id = value.get(name);
118
+
119
+ if (id) {
120
+ return id;
121
+ } else {
122
+ return $type;
123
+ }
124
+ } else {
125
+ return $type;
126
+ }
127
+ }
128
+
129
+ return value;
130
+ }
131
+
101
132
  module.exports = {
133
+ expectEqual,
102
134
  verify,
103
- getTitle
135
+ getTitle,
136
+ replacer
104
137
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bpmnlint",
3
3
  "description": "Validate your BPMN diagrams based on configurable lint rules",
4
- "version": "7.5.0",
4
+ "version": "7.8.0",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [
7
7
  "bpmnlint",