Skip to content

Commit

Permalink
feat: lint zeebe:VersionTag extension and zeebe:versionTag attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Aug 26, 2024
1 parent 0c22fc2 commit 84a48e8
Show file tree
Hide file tree
Showing 7 changed files with 524 additions and 8 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const camundaCloud10Rules = withConfig({
'no-propagate-all-parent-variables': 'error',
'no-task-schedule': 'error',
'no-template': 'error',
'no-version-tag': 'error',
'no-zeebe-properties': 'error',
'no-zeebe-user-task': 'error',
'sequence-flow-condition': 'error',
Expand Down Expand Up @@ -83,7 +84,8 @@ const camundaCloud86Rules = withConfig({
'inclusive-gateway',
'no-binding-type',
'no-execution-listeners',
'no-priority-definition'
'no-priority-definition',
'no-version-tag'
]),
'duplicate-execution-listeners': 'error',
'execution-listener': 'error',
Expand Down Expand Up @@ -143,6 +145,7 @@ const rules = {
'no-signal-event-sub-process': './rules/camunda-cloud/no-signal-event-sub-process',
'no-task-schedule': './rules/camunda-cloud/no-task-schedule',
'no-template': './rules/camunda-cloud/no-template',
'no-version-tag': './rules/camunda-cloud/no-version-tag',
'no-zeebe-properties': './rules/camunda-cloud/no-zeebe-properties',
'no-zeebe-user-task': './rules/camunda-cloud/no-zeebe-user-task',
'priority-definition': './rules/camunda-cloud/priority-definition',
Expand Down
63 changes: 63 additions & 0 deletions rules/camunda-cloud/no-version-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const { is } = require('bpmnlint-utils');

const { hasProperties, findExtensionElement, hasNoExtensionElement } = require('../utils/element');

const { reportErrors } = require('../utils/reporter');

const { skipInNonExecutableProcess } = require('../utils/rule');

const allowedVersion = '8.6';

module.exports = skipInNonExecutableProcess(function() {
function check(node, reporter) {
if (is(node, 'bpmn:Process')) {
const errors = hasNoExtensionElement(node, 'zeebe:VersionTag', node, allowedVersion);

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

return;
}

let extensionElement;

if (is(node, 'bpmn:BusinessRuleTask')) {
extensionElement = findExtensionElement(node, 'zeebe:CalledDecision');
} else if (is(node, 'bpmn:CallActivity')) {
extensionElement = findExtensionElement(node, 'zeebe:CalledElement');
} else if (is(node, 'bpmn:UserTask')) {
extensionElement = findExtensionElement(node, 'zeebe:FormDefinition');
}

if (extensionElement) {
let errors = hasProperties(extensionElement, {
bindingType: {
allowed: (value) => value !== 'versionTag',
allowedVersion
}
}, node);

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

return;
}

errors = hasProperties(extensionElement, {
versionTag: {
allowed: false,
allowedVersion
}
}, node);

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

return {
check
};
});
36 changes: 36 additions & 0 deletions test/camunda-cloud/integration/no-version-tag-errors.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0949dru" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.26.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:extensionElements>
<zeebe:versionTag value="v1.0.0" />
</bpmn:extensionElements>
<bpmn:callActivity id="CallActivity_1">
<bpmn:extensionElements>
<zeebe:calledElement processId="foo" propagateAllChildVariables="false" bindingType="versionTag" versionTag="v1.0.0" />
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:businessRuleTask id="BusinessRuleTask_1">
<bpmn:extensionElements>
<zeebe:calledDecision decisionId="foo" resultVariable="foo" bindingType="versionTag" versionTag="v1.0.0" />
</bpmn:extensionElements>
</bpmn:businessRuleTask>
<bpmn:userTask id="UserTask_1">
<bpmn:extensionElements>
<zeebe:formDefinition formId="foo" bindingType="versionTag" versionTag="v1.0.0" />
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Activity_04qoo0e_di" bpmnElement="CallActivity_1">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0rpa9kq_di" bpmnElement="BusinessRuleTask_1">
<dc:Bounds x="290" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1t7eh0a_di" bpmnElement="UserTask_1">
<dc:Bounds x="420" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
77 changes: 77 additions & 0 deletions test/camunda-cloud/integration/no-version-tag-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const { expect } = require('chai');

const Linter = require('bpmnlint/lib/linter');

const NodeResolver = require('bpmnlint/lib/resolver/node-resolver');

const { readModdle } = require('../../helper');

const versions = [
'1.0',
'1.1',
'1.2',
'1.3',
'8.0',
'8.1',
'8.2',
'8.3',
'8.4',
'8.5'
];

describe('integration - no-version-tag', function() {

versions.forEach(function(version) {

let linter;

beforeEach(function() {
linter = new Linter({
config: {
extends: `plugin:camunda-compat/camunda-cloud-${ version.replace('.', '-') }`
},
resolver: new NodeResolver()
});
});


describe(`Camunda Cloud ${ version }`, function() {

describe('no errors', function() {

it('should not have errors', async function() {

// given
const { root } = await readModdle('test/camunda-cloud/integration/no-version-tag.bpmn');

// when
const reports = await linter.lint(root);

// then
expect(reports[ 'camunda-compat/no-version-tag' ]).not.to.exist;
});

});


describe('errors', function() {

it('should have errors', async function() {

// given
const { root } = await readModdle('test/camunda-cloud/integration/no-version-tag-errors.bpmn');

// when
const reports = await linter.lint(root);

// then
expect(reports[ 'camunda-compat/no-version-tag' ]).to.exist;
});

});

});

});

});
33 changes: 33 additions & 0 deletions test/camunda-cloud/integration/no-version-tag.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0949dru" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.26.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:callActivity id="CallActivity_1">
<bpmn:extensionElements>
<zeebe:calledElement processId="foo" propagateAllChildVariables="false" bindingType="deployment" />
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:businessRuleTask id="BusinessRuleTask_1">
<bpmn:extensionElements>
<zeebe:calledDecision decisionId="foo" resultVariable="foo" bindingType="deployment" />
</bpmn:extensionElements>
</bpmn:businessRuleTask>
<bpmn:userTask id="UserTask_1">
<bpmn:extensionElements>
<zeebe:formDefinition formId="foo" bindingType="deployment" />
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Activity_04qoo0e_di" bpmnElement="CallActivity_1">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0rpa9kq_di" bpmnElement="BusinessRuleTask_1">
<dc:Bounds x="290" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1t7eh0a_di" bpmnElement="UserTask_1">
<dc:Bounds x="420" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Loading

0 comments on commit 84a48e8

Please sign in to comment.