diff --git a/.eslintignore b/.eslintignore index b512c09..253ce2d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +lib/compiled-config.js \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 529a64f..a344211 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,11 +1,11 @@ { "extends": "plugin:bpmn-io/browser", - "globals": { - "require": false + "parserOptions": { + "ecmaVersion": "latest" }, "overrides": [ { - "files": "karma.conf.js", + "files": ["karma.conf.js", "tasks/*.js"], "extends": "plugin:bpmn-io/node" } ] diff --git a/lib/Linter.js b/lib/Linter.js index 682dbf3..dc3b49b 100644 --- a/lib/Linter.js +++ b/lib/Linter.js @@ -7,6 +7,8 @@ import Resolver from './Resolver'; import { isString } from 'min-dash'; +import { resolver as RulesResolver } from './compiled-config'; + import modelerModdle from 'modeler-moddle/resources/modeler.json'; import zeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe.json'; @@ -70,6 +72,8 @@ export class Linter { return { ...report, + executionPlatform, + executionPlatformVersion, message: getErrorMessage( report, executionPlatform, @@ -118,10 +122,23 @@ export class Linter { } async _createResolver(configName) { - const cache = await createCache(configName); + const { configs } = await import('bpmnlint-plugin-camunda-compat'); + + let { [ configName ]: config } = configs; + + if (!config) { + config = { + rules: {} + }; + } + + const ConfigResolver = new StaticResolver({ + [ `config:bpmnlint-plugin-camunda-compat/${ configName }` ]: config + }); return new Resolver([ - new StaticResolver(cache), + ConfigResolver, + RulesResolver, ...this._plugins.map(({ resolver }) => resolver) ]); } @@ -136,36 +153,4 @@ function getConfigName(executionPlatform, executionPlatformVersion) { function toLowerCase(string) { return string.toLowerCase(); -} - -async function createCache(configName) { - let config = require('bpmnlint-plugin-camunda-compat').configs[ configName ]; - - if (!config) { - config = { - rules: {} - }; - } - - const rules = await requireRules(config); - - return { - [ `config:bpmnlint-plugin-camunda-compat/${ configName }` ]: config, - ...rules - }; -} - -function requireRules({ rules }) { - let requiredRules = {}; - - for (let ruleName of Object.keys(rules)) { - const requiredRule = require(`bpmnlint-plugin-camunda-compat/rules/${ ruleName }`); - - requiredRules = { - ...requiredRules, - [ `rule:bpmnlint-plugin-camunda-compat/${ ruleName }` ]: requiredRule - }; - } - - return requiredRules; } \ No newline at end of file diff --git a/lib/compiled-config.js b/lib/compiled-config.js new file mode 100644 index 0000000..0902b73 --- /dev/null +++ b/lib/compiled-config.js @@ -0,0 +1,180 @@ + +const cache = {}; + +/** + * A resolver that caches rules and configuration as part of the bundle, + * making them accessible in the browser. + * + * @param {Object} cache + */ +function Resolver() {} + +Resolver.prototype.resolveRule = function(pkg, ruleName) { + + const rule = cache[pkg + '/' + ruleName]; + + if (!rule) { + throw new Error('cannot resolve rule <' + pkg + '/' + ruleName + '>: not bundled'); + } + + return rule; +}; + +Resolver.prototype.resolveConfig = function(pkg, configName) { + throw new Error( + 'cannot resolve config <' + configName + '> in <' + pkg +'>: not bundled' + ); +}; + +const resolver = new Resolver(); + +const rules = { + "camunda-compat/element-type": "error", + "camunda-compat/called-element": "error", + "camunda-compat/collapsed-subprocess": "error", + "camunda-compat/duplicate-task-headers": "error", + "camunda-compat/error-reference": "error", + "camunda-compat/escalation-reference": "error", + "camunda-compat/event-based-gateway-target": "error", + "camunda-compat/executable-process": "error", + "camunda-compat/feel": "error", + "camunda-compat/history-time-to-live": "error", + "camunda-compat/implementation": "error", + "camunda-compat/inclusive-gateway": "error", + "camunda-compat/loop-characteristics": "error", + "camunda-compat/message-reference": "error", + "camunda-compat/no-candidate-users": "error", + "camunda-compat/no-expression": "error", + "camunda-compat/no-multiple-none-start-events": "error", + "camunda-compat/no-signal-event-sub-process": "error", + "camunda-compat/no-task-schedule": "error", + "camunda-compat/no-template": "error", + "camunda-compat/no-zeebe-properties": "error", + "camunda-compat/sequence-flow-condition": "error", + "camunda-compat/signal-reference": "error", + "camunda-compat/subscription": "error", + "camunda-compat/task-schedule": "error", + "camunda-compat/timer": "error", + "camunda-compat/user-task-form": "error" +}; + +const config = { + rules: rules +}; + +const bundle = { + resolver: resolver, + config: config +}; + +export { resolver, config }; + +export default bundle; + +import rule_0 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/element-type'; + +cache['bpmnlint-plugin-camunda-compat/element-type'] = rule_0; + +import rule_1 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/called-element'; + +cache['bpmnlint-plugin-camunda-compat/called-element'] = rule_1; + +import rule_2 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/collapsed-subprocess'; + +cache['bpmnlint-plugin-camunda-compat/collapsed-subprocess'] = rule_2; + +import rule_3 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/duplicate-task-headers'; + +cache['bpmnlint-plugin-camunda-compat/duplicate-task-headers'] = rule_3; + +import rule_4 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/error-reference'; + +cache['bpmnlint-plugin-camunda-compat/error-reference'] = rule_4; + +import rule_5 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/escalation-reference'; + +cache['bpmnlint-plugin-camunda-compat/escalation-reference'] = rule_5; + +import rule_6 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/event-based-gateway-target'; + +cache['bpmnlint-plugin-camunda-compat/event-based-gateway-target'] = rule_6; + +import rule_7 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/executable-process'; + +cache['bpmnlint-plugin-camunda-compat/executable-process'] = rule_7; + +import rule_8 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/feel'; + +cache['bpmnlint-plugin-camunda-compat/feel'] = rule_8; + +import rule_9 from 'bpmnlint-plugin-camunda-compat/rules/camunda-platform/history-time-to-live'; + +cache['bpmnlint-plugin-camunda-compat/history-time-to-live'] = rule_9; + +import rule_10 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/implementation'; + +cache['bpmnlint-plugin-camunda-compat/implementation'] = rule_10; + +import rule_11 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/inclusive-gateway'; + +cache['bpmnlint-plugin-camunda-compat/inclusive-gateway'] = rule_11; + +import rule_12 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/loop-characteristics'; + +cache['bpmnlint-plugin-camunda-compat/loop-characteristics'] = rule_12; + +import rule_13 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/message-reference'; + +cache['bpmnlint-plugin-camunda-compat/message-reference'] = rule_13; + +import rule_14 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-candidate-users'; + +cache['bpmnlint-plugin-camunda-compat/no-candidate-users'] = rule_14; + +import rule_15 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-expression'; + +cache['bpmnlint-plugin-camunda-compat/no-expression'] = rule_15; + +import rule_16 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-multiple-none-start-events'; + +cache['bpmnlint-plugin-camunda-compat/no-multiple-none-start-events'] = rule_16; + +import rule_17 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-signal-event-sub-process'; + +cache['bpmnlint-plugin-camunda-compat/no-signal-event-sub-process'] = rule_17; + +import rule_18 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-task-schedule'; + +cache['bpmnlint-plugin-camunda-compat/no-task-schedule'] = rule_18; + +import rule_19 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-template'; + +cache['bpmnlint-plugin-camunda-compat/no-template'] = rule_19; + +import rule_20 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/no-zeebe-properties'; + +cache['bpmnlint-plugin-camunda-compat/no-zeebe-properties'] = rule_20; + +import rule_21 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/sequence-flow-condition'; + +cache['bpmnlint-plugin-camunda-compat/sequence-flow-condition'] = rule_21; + +import rule_22 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/signal-reference'; + +cache['bpmnlint-plugin-camunda-compat/signal-reference'] = rule_22; + +import rule_23 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/subscription'; + +cache['bpmnlint-plugin-camunda-compat/subscription'] = rule_23; + +import rule_24 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/task-schedule'; + +cache['bpmnlint-plugin-camunda-compat/task-schedule'] = rule_24; + +import rule_25 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer'; + +cache['bpmnlint-plugin-camunda-compat/timer'] = rule_25; + +import rule_26 from 'bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form'; + +cache['bpmnlint-plugin-camunda-compat/user-task-form'] = rule_26; \ No newline at end of file diff --git a/lib/utils/error-messages.js b/lib/utils/error-messages.js index a155767..d689eb3 100644 --- a/lib/utils/error-messages.js +++ b/lib/utils/error-messages.js @@ -9,7 +9,10 @@ import { import { getTypeString } from './types'; -import { toSemverMinor } from './version'; +import { + greaterOrEqual, + toSemverMinor +} from './version'; const TIMER_PROPERTIES = [ 'timeCycle', @@ -122,7 +125,7 @@ export function getErrorMessage(report, executionPlatform, executionPlatformVers } if (type === ERROR_TYPES.EXPRESSION_VALUE_NOT_ALLOWED) { - return getExpressionValueNotAllowedErrorMessage(report); + return getExpressionValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion); } if (type === ERROR_TYPES.EXPRESSION_NOT_ALLOWED) { @@ -507,7 +510,7 @@ function getExpressionRequiredErrorMessage(report) { return message; } -function getExpressionValueNotAllowedErrorMessage(report) { +function getExpressionValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) { const { data, message @@ -522,7 +525,11 @@ function getExpressionValueNotAllowedErrorMessage(report) { const typeString = getTypeString(parentNode || node); if (is(node, 'bpmn:FormalExpression') && property === 'timeCycle') { - return `${ getIndefiniteArticle(typeString) } <${ typeString }>