Skip to content

Commit

Permalink
feat: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jarekdanielak committed Dec 10, 2024
1 parent 229eee0 commit ecd5288
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
52 changes: 51 additions & 1 deletion src/cloud-element-templates/linting/LinterPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@ export const elementTemplateLintRule = ({ templates = [] }) => {

elementTemplates.set(validTemplates);

function setEngines(engines) {
if (engines == {}) {
return;
}
if (Object.keys(elementTemplates.getEngines()).length) {
return;
}

elementTemplates.setEngines(engines);
}

function check(node, reporter) {

if (!is(node, 'bpmn:FlowElement')) {
return;
}

const { moddleRoot } = reporter;

const engines = getEnginesConfig(moddleRoot);
setEngines(engines);

let template = elementTemplates.get(node);

const templateId = elementTemplates._getTemplateId(node);
Expand All @@ -63,6 +79,19 @@ export const elementTemplateLintRule = ({ templates = [] }) => {
return;
}

// Check compatibility
if (template.engines) {
if (!elementTemplates.isCompatible(template)) {
reporter.report(
node.id,
'This version of element template is not compatible with your execution platform version.',
{
name: node.name
}
);
}
}

template = applyConditions(node, template);

// Check attributes
Expand Down Expand Up @@ -123,4 +152,25 @@ function getEntryId(property, template) {

path.push(index);
return path.join('-');
}
}

function getEnginesConfig(definitions) {
const {
executionPlatform,
executionPlatformVersion,
exporter,
exporterVersion
} = definitions;

const engines = {};

if (executionPlatform === 'Camunda Cloud' && executionPlatformVersion) {
engines.camunda = executionPlatformVersion;
}

if (exporter === 'Camunda Modeler' && exporterVersion) {
engines.camundaDesktopModeler = exporterVersion;
}

return engines;
}
24 changes: 24 additions & 0 deletions test/spec/cloud-element-templates/linting/LinterPlugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,29 @@
"feel": "optional"
}
]
},
{
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "compatible",
"id": "compatible",
"appliesTo": [
"bpmn:Task"
],
"engines": {
"camunda": ">1.0"
},
"properties": []
},
{
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "incompatible",
"id": "incompatible",
"appliesTo": [
"bpmn:Task"
],
"engines": {
"camunda": "0"
},
"properties": []
}
]
20 changes: 19 additions & 1 deletion test/spec/cloud-element-templates/linting/LinterPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ const valid = [
config: {
templates
}
}
},
{
name: 'Template Compatible',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" zeebe:modelerTemplate="compatible" />')),
config: {
templates
}
},
];


Expand All @@ -75,6 +82,17 @@ const invalid = [
message: 'Linked element template not found'
}
},
{
name: 'Template Incompatible',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" zeebe:modelerTemplate="incompatible" />')),
config: {
templates
},
report: {
id: 'Task_1',
message: 'This version of element template is not compatible with your execution platform version.'
}
},
{
name: 'Min Length',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" name="a" zeebe:modelerTemplate="constraints.minLength" />')),
Expand Down

0 comments on commit ecd5288

Please sign in to comment.