bpmn-js-bpmnlint
Advanced tools
Comparing version
@@ -9,2 +9,6 @@ # Changelog | ||
## 0.10.0 | ||
* `CHORE`: support `bpmnlint@5` | ||
## 0.9.0 | ||
@@ -11,0 +15,0 @@ |
@@ -14,3 +14,9 @@ import { assign, groupBy, reduce } from 'min-dash'; | ||
var containedProperties = element.$descriptor.properties.filter(p => { | ||
var descriptor = element.$descriptor; | ||
if (descriptor.isGeneric) { | ||
return; | ||
} | ||
var containedProperties = descriptor.properties.filter(p => { | ||
return !p.isAttr && !p.isReference && p.type !== 'String'; | ||
@@ -53,43 +59,2 @@ }); | ||
/** | ||
* Checks whether node is of specific bpmn type. | ||
* | ||
* @param {ModdleElement} node | ||
* @param {String} type | ||
* | ||
* @return {Boolean} | ||
*/ | ||
function is(node, type) { | ||
if (type.indexOf(':') === -1) { | ||
type = 'bpmn:' + type; | ||
} | ||
return ( | ||
(typeof node.$instanceOf === 'function') | ||
? node.$instanceOf(type) | ||
: node.$type === type | ||
); | ||
} | ||
/** | ||
* Checks whether node has any of the specified types. | ||
* | ||
* @param {ModdleElement} node | ||
* @param {Array<String>} types | ||
* | ||
* @return {Boolean} | ||
*/ | ||
function isAny(node, types) { | ||
return types.some(function(type) { | ||
return is(node, type); | ||
}); | ||
} | ||
var utils = { | ||
is, | ||
isAny | ||
}; | ||
const categoryMap = { | ||
@@ -127,9 +92,44 @@ 0: 'off', | ||
* @param {ModdleElement} moddleRoot | ||
* @param {Rule} rule | ||
* @param {Object} ruleConfig | ||
* | ||
* @return {Array<ValidationErrors>} lint results | ||
* @param {Object} ruleDefinition.name | ||
* @param {Object} ruleDefinition.config | ||
* @param {Object} ruleDefinition.category | ||
* @param {Rule} ruleDefinition.rule | ||
* | ||
* @return {Array<ValidationErrors>} rule reports | ||
*/ | ||
Linter.prototype.applyRule = function applyRule(moddleRoot, rule, ruleConfig) { | ||
return testRule({ moddleRoot, rule, ruleConfig }); | ||
Linter.prototype.applyRule = function applyRule(moddleRoot, ruleDefinition) { | ||
const { | ||
config, | ||
rule, | ||
category, | ||
name | ||
} = ruleDefinition; | ||
try { | ||
const reports = testRule({ | ||
moddleRoot, | ||
rule, | ||
config | ||
}); | ||
return reports.map(function(report) { | ||
return { | ||
...report, | ||
category | ||
}; | ||
}); | ||
} catch (e) { | ||
console.error('rule <' + name + '> failed with error: ', e); | ||
return [ | ||
{ | ||
message: 'Rule error: ' + e.message, | ||
category: 'error' | ||
} | ||
]; | ||
} | ||
}; | ||
@@ -159,3 +159,3 @@ | ||
const rule = this.cachedRules[id] = ruleFactory(utils); | ||
const rule = this.cachedRules[id] = ruleFactory(); | ||
@@ -290,3 +290,3 @@ return rule; | ||
const finalReport = {}; | ||
const allReports = {}; | ||
@@ -296,25 +296,13 @@ ruleDefinitions.forEach((ruleDefinition) => { | ||
const { | ||
rule, | ||
name, | ||
config, | ||
category | ||
name | ||
} = ruleDefinition; | ||
const reports = this.applyRule(moddleRoot, rule, config); | ||
const reports = this.applyRule(moddleRoot, ruleDefinition); | ||
if (reports.length === 0) { | ||
return; | ||
if (reports.length) { | ||
allReports[name] = reports; | ||
} | ||
const categorizedReports = reports.map(function(report) { | ||
return { | ||
...report, | ||
category | ||
}; | ||
}); | ||
finalReport[name] = categorizedReports; | ||
}); | ||
return finalReport; | ||
return allReports; | ||
}); | ||
@@ -321,0 +309,0 @@ }; |
@@ -16,3 +16,9 @@ 'use strict'; | ||
var containedProperties = element.$descriptor.properties.filter(p => { | ||
var descriptor = element.$descriptor; | ||
if (descriptor.isGeneric) { | ||
return; | ||
} | ||
var containedProperties = descriptor.properties.filter(p => { | ||
return !p.isAttr && !p.isReference && p.type !== 'String'; | ||
@@ -55,43 +61,2 @@ }); | ||
/** | ||
* Checks whether node is of specific bpmn type. | ||
* | ||
* @param {ModdleElement} node | ||
* @param {String} type | ||
* | ||
* @return {Boolean} | ||
*/ | ||
function is(node, type) { | ||
if (type.indexOf(':') === -1) { | ||
type = 'bpmn:' + type; | ||
} | ||
return ( | ||
(typeof node.$instanceOf === 'function') | ||
? node.$instanceOf(type) | ||
: node.$type === type | ||
); | ||
} | ||
/** | ||
* Checks whether node has any of the specified types. | ||
* | ||
* @param {ModdleElement} node | ||
* @param {Array<String>} types | ||
* | ||
* @return {Boolean} | ||
*/ | ||
function isAny(node, types) { | ||
return types.some(function(type) { | ||
return is(node, type); | ||
}); | ||
} | ||
var utils = { | ||
is, | ||
isAny | ||
}; | ||
const categoryMap = { | ||
@@ -129,9 +94,44 @@ 0: 'off', | ||
* @param {ModdleElement} moddleRoot | ||
* @param {Rule} rule | ||
* @param {Object} ruleConfig | ||
* | ||
* @return {Array<ValidationErrors>} lint results | ||
* @param {Object} ruleDefinition.name | ||
* @param {Object} ruleDefinition.config | ||
* @param {Object} ruleDefinition.category | ||
* @param {Rule} ruleDefinition.rule | ||
* | ||
* @return {Array<ValidationErrors>} rule reports | ||
*/ | ||
Linter.prototype.applyRule = function applyRule(moddleRoot, rule, ruleConfig) { | ||
return testRule({ moddleRoot, rule, ruleConfig }); | ||
Linter.prototype.applyRule = function applyRule(moddleRoot, ruleDefinition) { | ||
const { | ||
config, | ||
rule, | ||
category, | ||
name | ||
} = ruleDefinition; | ||
try { | ||
const reports = testRule({ | ||
moddleRoot, | ||
rule, | ||
config | ||
}); | ||
return reports.map(function(report) { | ||
return { | ||
...report, | ||
category | ||
}; | ||
}); | ||
} catch (e) { | ||
console.error('rule <' + name + '> failed with error: ', e); | ||
return [ | ||
{ | ||
message: 'Rule error: ' + e.message, | ||
category: 'error' | ||
} | ||
]; | ||
} | ||
}; | ||
@@ -161,3 +161,3 @@ | ||
const rule = this.cachedRules[id] = ruleFactory(utils); | ||
const rule = this.cachedRules[id] = ruleFactory(); | ||
@@ -292,3 +292,3 @@ return rule; | ||
const finalReport = {}; | ||
const allReports = {}; | ||
@@ -298,25 +298,13 @@ ruleDefinitions.forEach((ruleDefinition) => { | ||
const { | ||
rule, | ||
name, | ||
config, | ||
category | ||
name | ||
} = ruleDefinition; | ||
const reports = this.applyRule(moddleRoot, rule, config); | ||
const reports = this.applyRule(moddleRoot, ruleDefinition); | ||
if (reports.length === 0) { | ||
return; | ||
if (reports.length) { | ||
allReports[name] = reports; | ||
} | ||
const categorizedReports = reports.map(function(report) { | ||
return { | ||
...report, | ||
category | ||
}; | ||
}); | ||
finalReport[name] = categorizedReports; | ||
}); | ||
return finalReport; | ||
return allReports; | ||
}); | ||
@@ -323,0 +311,0 @@ }; |
{ | ||
"name": "bpmn-js-bpmnlint", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "bpmn-js integration for bpmnlint", | ||
@@ -26,5 +26,5 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"bpmnlint": "^4.0.0", | ||
"bpmn-font": "^0.8.0", | ||
"bpmn-js": "^2.4.1", | ||
"bpmnlint": "^5.0.0", | ||
"cpx": "^1.5.0", | ||
@@ -43,4 +43,4 @@ "npm-run-all": "^4.1.3", | ||
"peerDependencies": { | ||
"bpmnlint": "^4.0.0 || ^3.2.0" | ||
"bpmnlint": "^3.2.0 || ^4.0.0 || ^5.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
246790
-0.65%1397
-1.69%