Skip to content

Commit

Permalink
feat(rules): attach documentation URL
Browse files Browse the repository at this point in the history
Closes #166
  • Loading branch information
nikku committed Feb 17, 2025
1 parent 3041995 commit c93f1a5
Show file tree
Hide file tree
Showing 27 changed files with 462 additions and 56 deletions.
9 changes: 7 additions & 2 deletions rules/ad-hoc-sub-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const {
isAny
} = require('bpmnlint-utils');

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


/**
* A rule that ensures that an Ad Hoc Sub Process is valid according to the BPMN spec:
*
Expand Down Expand Up @@ -40,8 +45,8 @@ module.exports = function() {
});
}

return {
return annotateRule('ad-hoc-sub-process', {
check
};
});

};
9 changes: 7 additions & 2 deletions rules/conditional-flows.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const {
annotateRule
} = require('./helper');


/**
* A rule that checks that sequence flows outgoing from a
* conditional forking gateway or activity are
Expand Down Expand Up @@ -27,9 +32,9 @@ module.exports = function() {
});
}

return {
return annotateRule('conditional-flows', {
check
};
});

};

Expand Down
8 changes: 7 additions & 1 deletion rules/end-event-required.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const {
isAny
} = require('bpmnlint-utils');

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


/**
* A rule that checks the presence of an end event per scope.
Expand Down Expand Up @@ -35,5 +39,7 @@ module.exports = function() {
}
}

return { check };
return annotateRule('end-event-required', {
check
});
};
9 changes: 7 additions & 2 deletions rules/event-sub-process-typed-start-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const {
is
} = require('bpmnlint-utils');

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


/**
* A rule that checks that start events inside an event sub-process
* are typed.
Expand Down Expand Up @@ -32,8 +37,8 @@ module.exports = function() {
});
}

return {
return annotateRule('event-sub-process-typed-start-event', {
check
};
});

};
9 changes: 7 additions & 2 deletions rules/fake-join.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const {
isAny
} = require('bpmnlint-utils');

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


/**
* A rule that checks that no fake join is modeled by attempting
* to give a task or event join semantics.
Expand Down Expand Up @@ -29,8 +34,8 @@ module.exports = function() {
}
}

return {
return annotateRule('fake-join', {
check
};
});

};
8 changes: 6 additions & 2 deletions rules/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const {
isAny
} = require('bpmnlint-utils');

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


/**
* A rule that verifies that global elements are properly used.
Expand Down Expand Up @@ -50,9 +54,9 @@ module.exports = function() {

}

return {
return annotateRule('global', {
check
};
});

// helpers /////////////////////////////

Expand Down
46 changes: 42 additions & 4 deletions rules/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
* @typedef { import('../lib/types.js').ModdleElement } ModdleElement
*
* @typedef { import('../lib/types.js').RuleFactory } RuleFactory
* @typedef { import('../lib/types.js').RuleDefinition } RuleDefinition
*/


Expand All @@ -16,7 +17,7 @@ const {
*
* @return { RuleFactory } ruleFactory
*/
function disallowNodeType(type) {
function disallowNodeType(type, ruleName) {

/**
* @type { RuleFactory }
Expand All @@ -30,9 +31,9 @@ function disallowNodeType(type) {
}
}

return {
return annotateRule(ruleName, {
check
};
});

};

Expand Down Expand Up @@ -67,4 +68,41 @@ function findParent(node, type) {
return findParent(parent, type);
}

module.exports.findParent = findParent;
module.exports.findParent = findParent;


const documentationBaseUrl = 'https://github.com/bpmn-io/bpmnlint/blob/main/docs/rules';

/**
* Annotate a rule with core information, such as the documentation url.
*
* @param {string} ruleName
* @param {RuleDefinition} options
*
* @return {RuleDefinition}
*/
function annotateRule(ruleName, options) {

const {
meta: {
documentation = {},
...restMeta
} = {},
...restOptions
} = options;

const documentationUrl = `${documentationBaseUrl}/${ruleName}.md`;

return {
meta: {
documentation: {
url: documentationUrl,
...documentation
},
...restMeta
},
...restOptions
};
}

module.exports.annotateRule = annotateRule;
8 changes: 7 additions & 1 deletion rules/label-required.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const {
isAny
} = require('bpmnlint-utils');

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


/**
* A rule that checks the presence of a label.
Expand Down Expand Up @@ -53,7 +57,9 @@ module.exports = function() {
}
}

return { check };
return annotateRule('label-required', {
check
});
};


Expand Down
8 changes: 6 additions & 2 deletions rules/link-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const {
is
} = require('bpmnlint-utils');

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


/**
* A rule that verifies that link events are properly used.
Expand Down Expand Up @@ -71,9 +75,9 @@ module.exports = function() {

}

return {
return annotateRule('link-event', {
check
};
});
};


Expand Down
9 changes: 7 additions & 2 deletions rules/no-bpmndi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ const {
flatten
} = require('min-dash');

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

/**
* @typedef { import('../lib/types.js').ModdleElement } ModdleElement
*/


/**
* A rule that checks that there is no BPMNDI information missing for elements,
* which require BPMNDI.
Expand Down Expand Up @@ -41,9 +46,9 @@ module.exports = function() {
});
}

return {
return annotateRule('no-bpmndi', {
check
};
});

};

Expand Down
2 changes: 1 addition & 1 deletion rules/no-complex-gateway.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const disallowNodeType = require('./helper').disallowNodeType;

module.exports = disallowNodeType('bpmn:ComplexGateway');
module.exports = disallowNodeType('bpmn:ComplexGateway', 'no-complex-gateway');
8 changes: 6 additions & 2 deletions rules/no-disconnected.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const {
is
} = require('bpmnlint-utils');

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


/**
* A rule that verifies that there exists no disconnected
Expand Down Expand Up @@ -38,9 +42,9 @@ module.exports = function() {
}
}

return {
return annotateRule('no-disconnected', {
check
};
});
};


Expand Down
9 changes: 7 additions & 2 deletions rules/no-duplicate-sequence-flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const {
is
} = require('bpmnlint-utils');

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


/**
* A rule that verifies that there are no disconnected
* flow elements, i.e. elements without incoming or outgoing sequence flows.
Expand Down Expand Up @@ -45,9 +50,9 @@ module.exports = function() {
}
}

return {
return annotateRule('no-duplicate-sequence-flows', {
check
};
});

};

Expand Down
8 changes: 6 additions & 2 deletions rules/no-gateway-join-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const {
is
} = require('bpmnlint-utils');

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


/**
* A rule that checks, whether a gateway forks and joins
Expand All @@ -25,8 +29,8 @@ module.exports = function() {
}
}

return {
return annotateRule('no-gateway-fork-join', {
check
};
});

};
8 changes: 6 additions & 2 deletions rules/no-implicit-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const {
} = require('bpmnlint-utils');

const {
findParent
findParent,
annotateRule
} = require('./helper');


/**
* A rule that checks that an element is not an implicit end (token sink).
*
Expand Down Expand Up @@ -87,5 +89,7 @@ module.exports = function() {
}
}

return { check };
return annotateRule('no-implicit-end', {
check
});
};
Loading

0 comments on commit c93f1a5

Please sign in to comment.