Skip to content

Commit

Permalink
Updated rules
Browse files Browse the repository at this point in the history
  • Loading branch information
membro committed Oct 11, 2021
1 parent 7212ef7 commit 49e33a0
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 141 deletions.
3 changes: 2 additions & 1 deletion .bpmnlintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"plugin:custom/recommended"
],
"rules": {
"label-required": "on"
"label-required": "on",
"camunda/avoid-lanes": "off"
}
}
8 changes: 6 additions & 2 deletions bpmnlint-plugin-custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ module.exports = {
configs: {
recommended: {
rules: {
'script-task': 'error',
'service-task': 'error'
'script-task-error': 'error',
'script-task-warn': 'warn',
'service-task': 'error',
'service-task-httpRequest-error': 'error',
'service-task-httpRequest-warn': 'warn',
'service-task-onifyApiRequest-error': 'error'
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions bpmnlint-plugin-custom/rules/script-task-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { is } = require('bpmnlint-utils');


/**
* Rule that reports missing Script format on bpmn:ScriptTask.
* Script format can supports js or javascript
*/
module.exports = function () {

function check(node, reporter) {
if (is(node, 'bpmn:ScriptTask')) {
if (!node.scriptFormat) {
return reporter.report(node.id, 'Script format must be defined');
}

if (node.scriptFormat !== 'js' && node.scriptFormat !== 'javascript') {
return reporter.report(node.id, 'Only `js/javascript` are supported script formats');
}

if (!node.script) {
reporter.report(node.id, 'Script must be defined');
}
}
}

return {
check: check
};
};
21 changes: 21 additions & 0 deletions bpmnlint-plugin-custom/rules/script-task-warn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { is } = require('bpmnlint-utils');


/**
* Rule that reports missing Script format on bpmn:ScriptTask.
* Script format can supports js or javascript
*/
module.exports = function () {

function check(node, reporter) {
if (is(node, 'bpmn:ScriptTask') && (node.scriptFormat === 'js' || node.scriptFormat === 'javascript')) {
if (node.script && !node.script.includes('next()')) {
reporter.report(node.id, 'next() functions does not exist');
}
}
}

return {
check: check
};
};
25 changes: 0 additions & 25 deletions bpmnlint-plugin-custom/rules/script-task.js

This file was deleted.

34 changes: 34 additions & 0 deletions bpmnlint-plugin-custom/rules/service-task-httpRequest-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { is } = require('bpmnlint-utils');
const { findElement } = require('../utils');

/**
* Rule that reports missing responseType on bpmn:ServiceTask.
*/
module.exports = function () {

function check(node, reporter) {
if (is(node, 'bpmn:ServiceTask')) {
const connector = findElement(node.extensionElements && node.extensionElements.values, 'camunda:Connector');

if (!connector || connector.connectorId !== 'httpRequest') {
return;
}

const url = connector.inputOutput && connector.inputOutput.inputParameters && connector.inputOutput.inputParameters.find((input) => input.name === 'url');
const json = connector.inputOutput && connector.inputOutput.inputParameters && connector.inputOutput.inputParameters.find((input) => input.name === 'json');
const method = connector.inputOutput && connector.inputOutput.inputParameters && connector.inputOutput.inputParameters.find((input) => input.name === 'method');

if (!url) {
reporter.report(node.id, 'Connector input parameter `url` must be defined');
}

if (method && (method.value.toUpperCase() === 'POST' || method.value.toUpperCase() === 'PUT' || method.value.toUpperCase() === 'PATCH') && !json) {
reporter.report(node.id, 'Connector input parameter `json` must be defined when `method` is POST, PUT or PATCH');
}
}
}

return {
check: check
};
};
28 changes: 28 additions & 0 deletions bpmnlint-plugin-custom/rules/service-task-httpRequest-warn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { is } = require('bpmnlint-utils');
const { findElement } = require('../utils');

/**
* Rule that reports missing responseType on bpmn:ServiceTask.
*/
module.exports = function () {

function check(node, reporter) {
if (is(node, 'bpmn:ServiceTask')) {
const connector = findElement(node.extensionElements && node.extensionElements.values, 'camunda:Connector');

if (!connector || connector.connectorId !== 'httpRequest') {
return;
}

const responseType = connector.inputOutput && connector.inputOutput.inputParameters && connector.inputOutput.inputParameters.find((input) => input.name === 'responseType');

if (!responseType) {
reporter.report(node.id, 'Connector input parameter `responseType` is not defined');
}
}
}

return {
check: check
};
};
34 changes: 34 additions & 0 deletions bpmnlint-plugin-custom/rules/service-task-onifyApiRequest-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { is } = require('bpmnlint-utils');
const { findElement } = require('../utils');

/**
* Rule for onifyApiRequest and onifyElevatedApiRequest
*/
module.exports = function () {

function check(node, reporter) {
if (is(node, 'bpmn:ServiceTask')) {
const connector = findElement(node.extensionElements && node.extensionElements.values, 'camunda:Connector');

if (!connector || (connector.connectorId !== 'onifyApiRequest' && connector.connectorId !== 'onifyElevatedApiRequest')) {
return;
}

const url = connector.inputOutput && connector.inputOutput.inputParameters && connector.inputOutput.inputParameters.find((input) => input.name === 'url');
const payload = connector.inputOutput && connector.inputOutput.inputParameters && connector.inputOutput.inputParameters.find((input) => input.name === 'payload');
const method = connector.inputOutput && connector.inputOutput.inputParameters && connector.inputOutput.inputParameters.find((input) => input.name === 'method');

if (!url) {
reporter.report(node.id, 'Connector input parameter `url` must be defined');
}

if (method && (method.value.toUpperCase() === 'POST' || method.value.toUpperCase() === 'PUT' || method.value.toUpperCase() === 'PATCH') && !payload) {
reporter.report(node.id, 'Connector input parameter `payload` must be defined when `method` is POST, PUT or PATCH');
}
}
}

return {
check: check
};
};
34 changes: 3 additions & 31 deletions bpmnlint-plugin-custom/rules/service-task.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
const {
is
} = require('bpmnlint-utils');

const { is } = require('bpmnlint-utils');
const { findElement } = require('../utils');

/**
* Rule that reports missing Implementation on bpmn:ServiceTask.
* Implementation only supports Connector
* Connector Id only supports our service tasks (eg. httpRequest, onifyApiRequest, etc)
* Connector Id only supports our service tasks (eg. httpRequest, onifyApiRequest, onifyElevatedApiRequest, etc)
*/
module.exports = function () {

function findElement(elements, name) {
if (!elements || !elements.length) return false;
return elements.find((element) => is(element, name));
}

function check(node, reporter) {
if (is(node, 'bpmn:ServiceTask')) {
const connector = findElement(node.extensionElements && node.extensionElements.values, 'camunda:Connector');
Expand All @@ -31,27 +24,6 @@ module.exports = function () {
if (connector.connectorId !== 'httpRequest' && connector.connectorId !== 'onifyApiRequest' && connector.connectorId !== 'onifyElevatedApiRequest') {
return reporter.report(node.id, 'Connector Id only supports `httpRequest`, `onifyApiRequest` and `onifyElevatedApiRequest`');
}

if (!connector.inputOutput || !connector.inputOutput.inputParameters) {
return reporter.report(node.id, 'Connector input parameters `url` and `responseType` must be defined');
}

const url = connector.inputOutput.inputParameters.find((input) => input.name === 'url');
const responseType = connector.inputOutput.inputParameters.find((input) => input.name === 'responseType');
const method = connector.inputOutput.inputParameters.find((input) => input.name === 'method');
const json = connector.inputOutput.inputParameters.find((input) => input.name === 'json');

if (!url) {
return reporter.report(node.id, 'Connector input parameter `url` must be defined');
}

if (!responseType) {
return reporter.report(node.id, 'Connector input parameter `responseType` must be defined');
}

if (method && (method.value.toUpperCase() === 'POST' || method.value.toUpperCase() === 'PUT' || method.value.toUpperCase() === 'PATCH') && !json) {
return reporter.report(node.id, 'Connector input parameters `json` must be defined when `method` is POST, PUT or PATCH');
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions bpmnlint-plugin-custom/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {
is
} = require('bpmnlint-utils');

module.exports = {
findElement,
};

function findElement(elements, name) {
if (!elements || !elements.length) return false;
return elements.find((element) => is(element, name));
}
Loading

0 comments on commit 49e33a0

Please sign in to comment.