Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support zeebe:Script #68

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ All notable changes to [bpmnlint-plugin-camunda-compat](https://github.com/camun

___Note:__ Yet to be released changes appear here._

## 0.17.0

* `FEAT`: support `zeebe:Script` ([#67](https://github.com/camunda/bpmnlint-plugin-camunda-compat/issues/67))

### Breaking Changes

* Rule `called-decision-or-task-definition` was renamed to `implementation`.

## 0.16.0

* `FEAT`: add link events to `element-type` rule ([#63](https://github.com/camunda/bpmnlint-plugin-camunda-compat/pull/63))
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { omit } = require('min-dash');

const camundaCloud10Rules = {
'called-decision-or-task-definition': [ 'error', { version: '1.0' } ],
'implementation': [ 'error', { version: '1.0' } ],
'called-element': 'error',
'collapsed-subprocess': 'error',
'duplicate-task-headers': 'error',
Expand All @@ -21,43 +21,43 @@ const camundaCloud10Rules = {

const camundaCloud11Rules = {
...camundaCloud10Rules,
'called-decision-or-task-definition': [ 'error', { version: '1.1' } ],
'implementation': [ 'error', { version: '1.1' } ],
'element-type': [ 'error', { version: '1.1' } ],
'timer': [ 'error', { version: '1.1' } ]
};

const camundaCloud12Rules = {
...camundaCloud11Rules,
'called-decision-or-task-definition': [ 'error', { version: '1.2' } ],
'implementation': [ 'error', { version: '1.2' } ],
'element-type': [ 'error', { version: '1.2' } ],
'timer': [ 'error', { version: '1.2' } ]
};

const camundaCloud13Rules = {
...camundaCloud12Rules,
'called-decision-or-task-definition': [ 'error', { version: '1.3' } ],
'implementation': [ 'error', { version: '1.3' } ],
'element-type': [ 'error', { version: '1.3' } ],
'timer': [ 'error', { version: '1.3' } ]
};

const camundaCloud80Rules = {
...omit(camundaCloud13Rules, 'no-template'),
'called-decision-or-task-definition': [ 'error', { version: '8.0' } ],
'implementation': [ 'error', { version: '8.0' } ],
'element-type': [ 'error', { version: '8.0' } ],
'timer': [ 'error', { version: '8.0' } ]
};

const camundaCloud81Rules = {
...omit(camundaCloud80Rules, 'no-zeebe-properties'),
'called-decision-or-task-definition': [ 'error', { version: '8.1' } ],
'implementation': [ 'error', { version: '8.1' } ],
'element-type': [ 'error', { version: '8.1' } ],
'inclusive-gateway': 'error',
'timer': [ 'error', { version: '8.1' } ]
};

const camundaCloud82Rules = {
...camundaCloud81Rules,
'called-decision-or-task-definition': [ 'error', { version: '8.2' } ],
'implementation': [ 'error', { version: '8.2' } ],
'element-type': [ 'error', { version: '8.2' } ],
'timer': [ 'error', { version: '8.2' } ]
};
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"modeler-moddle": "^0.1.0",
"sinon": "^14.0.0",
"sinon-chai": "^3.7.0",
"zeebe-bpmn-moddle": "^0.14.0"
"zeebe-bpmn-moddle": "^0.17.0"
},
"dependencies": {
"@bpmn-io/feel-lint": "^0.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ module.exports = {
taskDefinition: {
'bpmn:BusinessRuleTask': '1.1',
'bpmn:IntermediateThrowEvent': {
'bpmn:MessageEventDefinition': '1.2',
'bpmn:MessageEventDefinition': '1.2'
},
'bpmn:ScriptTask': '1.1',
'bpmn:SendTask': '1.1',
'bpmn:ServiceTask': '1.0'
},
script: {
'bpmn:ScriptTask': '8.2'
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const { ERROR_TYPES } = require('../utils/error-types');
module.exports = function({ version }) {
function check(node, reporter) {
const calledDecisionConfig = config.calledDecision[ node.$type ];
const scriptConfig = config.script[ node.$type ];
const taskDefinitionConfig = config.taskDefinition[ node.$type ];

if (
(!calledDecisionConfig || (isString(calledDecisionConfig) && !greaterOrEqual(version, calledDecisionConfig)))
&& (!scriptConfig || (isString(scriptConfig) && !greaterOrEqual(version, scriptConfig)))
&& (!taskDefinitionConfig || (isString(taskDefinitionConfig) && !greaterOrEqual(version, taskDefinitionConfig)))) {
return;
}
Expand All @@ -37,9 +39,10 @@ module.exports = function({ version }) {
let errors;

const calledDecision = findExtensionElement(node, 'zeebe:CalledDecision'),
script = findExtensionElement(node, 'zeebe:Script'),
taskDefinition = findExtensionElement(node, 'zeebe:TaskDefinition');

if (calledDecision && !taskDefinition) {
if (calledDecision && !script && !taskDefinition) {

if (!isCalledDecisionAllowed(node, version)) {
const allowedVersion = getAllowedVersion(calledDecisionConfig, node);
Expand Down Expand Up @@ -77,7 +80,45 @@ module.exports = function({ version }) {
}
}

if (!calledDecision && taskDefinition) {
if (!calledDecision && script && !taskDefinition) {

if (!isScriptAllowed(node, version)) {
const allowedVersion = getAllowedVersion(scriptConfig, node);

reportErrors(node, reporter, {
message: allowedVersion
? `Extension element of type <zeebe:Script> only allowed by Camunda Platform ${ allowedVersion } or newer`
: 'Extension element of type <zeebe:Script> not allowed',
path: getPath(script, node),
data: {
type: ERROR_TYPES.EXTENSION_ELEMENT_NOT_ALLOWED,
node,
parentNode: null,
extensionElement: script,
allowedVersion
}
});

return;
}

errors = hasProperties(script, {
expression: {
required: true
},
resultVariable: {
required: true
}
}, node);

if (errors && errors.length) {
reportErrors(node, reporter, errors);

return;
}
}

if (!calledDecision && !script && taskDefinition) {

if (!isTaskDefinitionAllowed(node, version)) {
const allowedVersion = getAllowedVersion(taskDefinitionConfig, node);
Expand Down Expand Up @@ -110,15 +151,18 @@ module.exports = function({ version }) {
}
}

if (isCalledDecisionAllowed(node, version) && isTaskDefinitionAllowed(node, version)) {
errors = hasExtensionElement(node, [
'zeebe:CalledDecision',
'zeebe:TaskDefinition'
], node);
} else if (isCalledDecisionAllowed(node, version)) {
errors = hasExtensionElement(node, 'zeebe:CalledDecision', node);
} else if (isTaskDefinitionAllowed(node, version)) {
errors = hasExtensionElement(node, 'zeebe:TaskDefinition', node);
const allowedTypes = [
isCalledDecisionAllowed(node, version) ? 'zeebe:CalledDecision' : false,
isScriptAllowed(node, version) ? 'zeebe:Script' : false,
isTaskDefinitionAllowed(node, version) ? 'zeebe:TaskDefinition' : false
].filter(isAllowed => isAllowed);

if (allowedTypes.length === 0) {
return;
} else if (allowedTypes.length === 1) {
errors = hasExtensionElement(node, allowedTypes[0], node);
} else {
errors = hasExtensionElement(node, allowedTypes, node);
}

if (errors && errors.length) {
Expand All @@ -136,7 +180,17 @@ module.exports = function({ version }) {
function isCalledDecisionAllowed(node, version) {
const { calledDecision } = config;

return calledDecision[ node.$type ] && greaterOrEqual(version, calledDecision[ node.$type ]);
const allowedVersion = getAllowedVersion(calledDecision[ node.$type ], node);

return calledDecision[ node.$type ] && greaterOrEqual(version, allowedVersion);
}

function isScriptAllowed(node, version) {
const { script } = config;

const allowedVersion = getAllowedVersion(script[ node.$type ], node);

return allowedVersion && greaterOrEqual(version, allowedVersion);
}

function isTaskDefinitionAllowed(node, version) {
Expand All @@ -159,4 +213,4 @@ function getAllowedVersion(config, node) {
const eventDefinition = getEventDefinition(node);

return eventDefinition && config[ eventDefinition.$type ];
}
}
Loading