Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Jul 20, 2023
1 parent 7aee51a commit 788036f
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 204 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
lib/compiled-config.js
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
]
Expand Down
53 changes: 19 additions & 34 deletions lib/Linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -70,6 +72,8 @@ export class Linter {

return {
...report,
executionPlatform,
executionPlatformVersion,
message: getErrorMessage(
report,
executionPlatform,
Expand Down Expand Up @@ -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)
]);
}
Expand All @@ -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;
}
180 changes: 180 additions & 0 deletions lib/compiled-config.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 11 additions & 4 deletions lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {

import { getTypeString } from './types';

import { toSemverMinor } from './version';
import {
greaterOrEqual,
toSemverMinor
} from './version';

const TIMER_PROPERTIES = [
'timeCycle',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -507,7 +510,7 @@ function getExpressionRequiredErrorMessage(report) {
return message;
}

function getExpressionValueNotAllowedErrorMessage(report) {
function getExpressionValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) {
const {
data,
message
Expand All @@ -522,7 +525,11 @@ function getExpressionValueNotAllowedErrorMessage(report) {
const typeString = getTypeString(parentNode || node);

if (is(node, 'bpmn:FormalExpression') && property === 'timeCycle') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression (cron requires Camunda Platform 8.1 or newer)`;
if (!greaterOrEqual(executionPlatformVersion, '8.1')) {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression (cron only supported by Camunda Platform 8.1 or newer)`;
} else {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression`;
}
}

if (is(node, 'bpmn:FormalExpression') && property === 'timeDate') {
Expand Down
13 changes: 11 additions & 2 deletions lib/utils/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { is } from 'bpmnlint-utils';

import { ERROR_TYPES } from 'bpmnlint-plugin-camunda-compat/rules/utils/error-types';

import { greaterOrEqual } from './version';

const TIMER_PROPERTIES = [
'timeDate',
'timeDuration',
Expand Down Expand Up @@ -264,7 +266,10 @@ export function getEntryIds(report) {
}

export function getErrorMessage(id, report) {
const { data = {} } = report;
const {
executionPlatformVersion,
data = {}
} = report;

// do not override FEEL message
if (data.type === ERROR_TYPES.FEEL_EXPRESSION_INVALID) {
Expand Down Expand Up @@ -393,7 +398,11 @@ export function getErrorMessage(id, report) {
const { property } = data;

if (property === 'timeCycle') {
return 'Must be an expression, an ISO 8601 repeating interval, or a cron expression (cron requires Camunda Platform 8.1 or newer).';
if (!greaterOrEqual(executionPlatformVersion, '8.1')) {
return 'Must be an expression, an ISO 8601 repeating interval, or a cron expression (cron only supported by Camunda Platform 8.1 or newer).';
}

return 'Must be an expression, an ISO 8601 repeating interval, or a cron expression.';
}

if (property === 'timeDate') {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"start": "npm run start:cloud",
"start:platform": "cross-env SINGLE_START=platform npm run test:watch",
"start:cloud": "cross-env SINGLE_START=cloud npm run test:watch",
"test": "karma start",
"test:watch": "npm test -- --auto-watch --no-single-run"
"test": "npm run compile-config && karma start",
"test:watch": "npm test -- --auto-watch --no-single-run",
"compile-config": "node tasks/compile-config.js",
"prepublish": "npm run compile-config"
},
"keywords": [
"bpmnlint",
Expand Down
9 changes: 9 additions & 0 deletions tasks/compile-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs');

const compileConfig = require('bpmnlint/lib/support/compile-config');

const config = {
extends: 'plugin:camunda-compat/all'
};

compileConfig(config).then(code => fs.writeFileSync('lib/compiled-config.js', code));
Loading

0 comments on commit 788036f

Please sign in to comment.