UNPKG

bpmnlint

Version:

Validate your BPMN diagrams based on configurable lint rules

58 lines (42 loc) 1.16 kB
const { annotateRule } = require('./helper'); /** * A rule that checks that sequence flows outgoing from a * conditional forking gateway or activity are * either default flows _or_ have a condition attached * * @type { import('../lib/types.js').RuleFactory } */ module.exports = function() { function check(node, reporter) { if (!isConditionalForking(node)) { return; } const outgoing = node.outgoing || []; outgoing.forEach((flow) => { const missingCondition = ( !hasCondition(flow) && !isDefaultFlow(node, flow) ); if (missingCondition) { reporter.report(flow.id, 'Sequence flow is missing condition', [ 'conditionExpression' ]); } }); } return annotateRule('conditional-flows', { check }); }; // helpers ///////////////////////////// function isConditionalForking(node) { const defaultFlow = node['default']; const outgoing = node.outgoing || []; return defaultFlow || outgoing.find(hasCondition); } function hasCondition(flow) { return !!flow.conditionExpression; } function isDefaultFlow(node, flow) { return node['default'] === flow; }