Comparing version 6.2.0 to 6.3.0
@@ -9,2 +9,7 @@ # Changelog | ||
## 6.3.0 | ||
* `FEAT`: support rules and configuration provided by scoped packages ([#35](https://github.com/bpmn-io/bpmnlint/issues/35)) | ||
* `CHORE`: improve `Node >= 12.20` compatibility ([#37](https://github.com/bpmn-io/bpmnlint/pull/37)) | ||
## 6.2.0 | ||
@@ -54,3 +59,3 @@ | ||
* `FIX`: make `nyc` a development dependency | ||
* `CHORE`: update to `bpmn-modddle@6` | ||
* `CHORE`: update to `bpmn-moddle@6` | ||
@@ -57,0 +62,0 @@ ## 5.0.0 |
@@ -128,3 +128,3 @@ const testRule = require('./test-rule'); | ||
const actualConfig = this.cachedConfigs[id] = normalizeConfig(config, pkg); | ||
const actualConfig = this.cachedConfigs[id] = this.normalizeConfig(config, pkg); | ||
@@ -203,3 +203,3 @@ return actualConfig; | ||
const overrideRules = normalizeConfig(config, 'bpmnlint').rules; | ||
const overrideRules = this.normalizeConfig(config, 'bpmnlint').rules; | ||
@@ -280,28 +280,41 @@ const rules = [ ...inheritedRules, overrideRules ].reduce((rules, currentRules) => { | ||
Linter.prototype.parseRuleName = function(name) { | ||
Linter.prototype.parseRuleName = function(name, localPackage = 'bpmnlint') { | ||
const slashIdx = name.indexOf('/'); | ||
/** | ||
* We recognize the following rule name patterns: | ||
* | ||
* {RULE_NAME} => PKG = 'bpmnlint' | ||
* bpmnlint/{RULE_NAME} => PKG = 'bpmnlint' | ||
* {PACKAGE_SHORTCUT}/{RULE_NAME} => PKG = 'bpmnlint-plugin-{PACKAGE_SHORTCUT}' | ||
* bpmnlint-plugin-{PACKAGE_SHORTCUT}/{RULE_NAME} => PKG = 'bpmnlint-plugin-{PACKAGE_SHORTCUT}' | ||
* @scope/{PACKAGE_SHORTCUT}/{RULE_NAME} => PKG = '@scope/bpmnlint-plugin-{PACKAGE_SHORTCUT}' | ||
* @scope/bpmnlint-plugin-{PACKAGE_SHORTCUT}/{RULE_NAME} => PKG = '@scope/bpmnlint-plugin-{PACKAGE_SHORTCUT}' | ||
*/ | ||
// resolve rule as built-in, if unprefixed | ||
if (slashIdx === -1) { | ||
return { | ||
pkg: 'bpmnlint', | ||
ruleName: name | ||
}; | ||
const match = /^(?:(?:(@[^/]+)\/)?([^@]{1}[^/]*)\/)?([^/]+)$/.exec(name); | ||
if (!match) { | ||
throw new Error(`unparseable rule name <${name}>`); | ||
} | ||
const pkg = name.substring(0, slashIdx); | ||
const ruleName = name.substring(slashIdx + 1); | ||
const [ | ||
_, | ||
ns, | ||
packageName, | ||
ruleName | ||
] = match; | ||
if (pkg === 'bpmnlint') { | ||
if (!packageName) { | ||
return { | ||
pkg: 'bpmnlint', | ||
pkg: localPackage, | ||
ruleName | ||
}; | ||
} else { | ||
return { | ||
pkg: 'bpmnlint-plugin-' + pkg, | ||
ruleName | ||
}; | ||
} | ||
const pkg = `${ns ? ns + '/' : '' }${prefixPackage(packageName)}`; | ||
return { | ||
pkg, | ||
ruleName | ||
}; | ||
}; | ||
@@ -312,20 +325,37 @@ | ||
const localMatch = /^bpmnlint:(.*)$/.exec(name); | ||
/** | ||
* We recognize the following config name patterns: | ||
* | ||
* bpmnlint:{CONFIG_NAME} => PKG = 'bpmnlint' | ||
* plugin:{PACKAGE_SHORTCUT}/{CONFIG_NAME} => PKG = 'bpmnlint-plugin-{PACKAGE_SHORTCUT}' | ||
* plugin:bpmnlint-plugin-{PACKAGE_SHORTCUT}/{CONFIG_NAME} => PKG = 'bpmnlint-plugin-{PACKAGE_SHORTCUT}' | ||
* plugin:@scope/{PACKAGE_SHORTCUT}/{CONFIG_NAME} => PKG = '@scope/bpmnlint-plugin-{PACKAGE_SHORTCUT}' | ||
* plugin:@scope/bpmnlint-plugin-{PACKAGE_SHORTCUT}/{CONFIG_NAME} => PKG = '@scope/bpmnlint-plugin-{PACKAGE_SHORTCUT}' | ||
*/ | ||
if (localMatch) { | ||
const match = /^(?:(?:plugin:(?:(@[^/]+)\/)?([^@]{1}[^/]*)\/)|bpmnlint:)([^/]+)$/.exec(name); | ||
if (!match) { | ||
throw new Error(`unparseable config name <${name}>`); | ||
} | ||
const [ | ||
_, | ||
ns, | ||
packageName, | ||
configName | ||
] = match; | ||
if (!packageName) { | ||
return { | ||
pkg: 'bpmnlint', | ||
configName: localMatch[1] | ||
configName | ||
}; | ||
} | ||
const pluginMatch = /^plugin:([^/]+)\/(.+)$/.exec(name); | ||
const pkg = `${ns ? ns + '/' : '' }${prefixPackage(packageName)}`; | ||
if (!pluginMatch) { | ||
throw new Error(`invalid config name <${ name }>`); | ||
} | ||
return { | ||
pkg: 'bpmnlint-plugin-' + pluginMatch[1], | ||
configName: pluginMatch[2] | ||
pkg, | ||
configName | ||
}; | ||
@@ -335,4 +365,30 @@ }; | ||
// helpers /////////////////////////// | ||
Linter.prototype.getSimplePackageName = function(name) { | ||
/** | ||
* We recognize the following package name patterns: | ||
* | ||
* bpmnlint => PKG = 'bpmnlint' | ||
* {PACKAGE_SHORTCUT} => PKG = PACKAGE_SHORTCUT | ||
* bpmnlint-plugin-{PACKAGE_SHORTCUT}' => PKG = PACKAGE_SHORTCUT | ||
* @scope/{PACKAGE_SHORTCUT} => PKG = '@scope/{PACKAGE_SHORTCUT}' | ||
* @scope/bpmnlint-plugin-{PACKAGE_SHORTCUT}' => PKG = '@scope/PACKAGE_SHORTCUT' | ||
*/ | ||
const match = /^(?:(@[^/]+)\/)?([^/]+)$/.exec(name); | ||
if (!match) { | ||
throw new Error(`unparseable package name <${name}>`); | ||
} | ||
const [ | ||
_, | ||
ns, | ||
packageName | ||
] = match; | ||
return `${ns ? ns + '/' : '' }${unprefixPackage(packageName)}`; | ||
}; | ||
/** | ||
@@ -342,12 +398,10 @@ * Validate and return validated config. | ||
* @param {Object} config | ||
* @param {String} pkg | ||
* @param {String} localPackage | ||
* | ||
* @return {Object} validated config | ||
*/ | ||
function normalizeConfig(config, pkg) { | ||
Linter.prototype.normalizeConfig = function(config, localPackage) { | ||
const rules = config.rules || {}; | ||
const rulePrefix = pkg.startsWith('bpmnlint-plugin-') && pkg.replace('bpmnlint-plugin-', ''); | ||
const validatedRules = Object.keys(rules).reduce((normalizedRules, name) => { | ||
@@ -357,17 +411,15 @@ | ||
// drop bpmnlint prefix, if existing | ||
if (name.startsWith('bpmnlint/')) { | ||
name = name.replace('bpmnlint/', ''); | ||
} else | ||
const { | ||
pkg, | ||
ruleName | ||
} = this.parseRuleName(name, localPackage); | ||
if (rulePrefix) { | ||
const normalizedName = ( | ||
pkg === 'bpmnlint' | ||
? ruleName | ||
: `${this.getSimplePackageName(pkg)}/${ruleName}` | ||
); | ||
// prefix local rule definition | ||
if (!name.startsWith(rulePrefix)) { | ||
name = `${rulePrefix}/${name}`; | ||
} | ||
} | ||
normalizedRules[normalizedName] = value; | ||
normalizedRules[name] = value; | ||
return normalizedRules; | ||
@@ -380,2 +432,28 @@ }, {}); | ||
}; | ||
}; | ||
// helpers /////////////////////////// | ||
function prefixPackage(pkg) { | ||
if (pkg === 'bpmnlint') { | ||
return 'bpmnlint'; | ||
} | ||
if (pkg.startsWith('bpmnlint-plugin-')) { | ||
return pkg; | ||
} | ||
return `bpmnlint-plugin-${pkg}`; | ||
} | ||
function unprefixPackage(pkg) { | ||
if (pkg.startsWith('bpmnlint-plugin-')) { | ||
return pkg.substring('bpmnlint-plugin-'.length); | ||
} | ||
return pkg; | ||
} |
@@ -65,3 +65,4 @@ const Module = require('module'); | ||
// shim createRequireFromPath for Node < 10.12 | ||
const createRequireFromPath = Module.createRequireFromPath || (filename => { | ||
// shim createRequireFromPath for Node < 12.2.0 | ||
const createRequireFromPath = Module.createRequire || Module.createRequireFromPath || (filename => { | ||
const mod = new Module(filename, null); | ||
@@ -68,0 +69,0 @@ |
{ | ||
"name": "bpmnlint", | ||
"description": "Validate your BPMN diagrams based on configurable lint rules", | ||
"version": "6.2.0", | ||
"version": "6.3.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -35,5 +35,7 @@ # bpmnlint | ||
Checkout the [`./rules` folder](https://github.com/bpmn-io/bpmnlint/tree/master/rules) for the list of existing rules. | ||
Our [documentation](https://github.com/bpmn-io/bpmnlint/tree/master/docs/rules#rules) lists all currenty implemented rules, the [`./rules` folder](https://github.com/bpmn-io/bpmnlint/tree/master/rules) contains each rules implementation. | ||
Do you miss a rule that should be included? [Propose a new rule](https://github.com/bpmn-io/bpmnlint/issues/new?template=NEW_RULE.md). | ||
## Configuration | ||
@@ -40,0 +42,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46128
1364
79