Skip to content

Commit

Permalink
chore(rules/no-overlapping-elements): eagerly filter out no-DI elements
Browse files Browse the repository at this point in the history
This ensures we save some hops as we iterate over all elements.
  • Loading branch information
nikku committed May 29, 2024
1 parent 8f4da1c commit 6a2e3bd
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions rules/no-overlapping-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,29 @@ module.exports = function() {
*/
function checkProcess(node, elementsToReport, elementsOutsideToReport, diObjects, parentDi) {

// check child elements for overlap
const flowElements = node.flowElements || [];
checkElementsArray(flowElements, elementsToReport, diObjects);

// check child elements outside parent boundary
// TODO: Skipped DataSoreReferences for now
flowElements.filter(element => !is(element, 'bpmn:DataStoreReference')).forEach(element => {
const flowElementsWithDi = flowElements.filter(element => diObjects.has(element));

if (!diObjects.has(element)) {
return;
}
// check child elements for overlap
checkElementsArray(flowElementsWithDi, elementsToReport, diObjects);

if (isOutsideParentBoundary(diObjects.get(element).bounds, parentDi.bounds)) {
// check child elements outside parent boundary
//
// * data objects do not have a visual representation
// * for historical reasons data store references may be
// outside of parent boundaries
//
flowElementsWithDi.forEach(element => {
if (
!is(element, 'bpmn:DataStoreReference') &&
isOutsideParentBoundary(diObjects.get(element).bounds, parentDi.bounds)
) {
elementsOutsideToReport.add(element);
}
});

// check subprocesses
// recurse into subprocesses
const subProcesses = flowElements.filter(element => is(element, 'bpmn:SubProcess'));
subProcesses.forEach(subProcess => {
const subProcessDi = diObjects.get(subProcess) || {};
Expand All @@ -93,13 +98,10 @@ function checkProcess(node, elementsToReport, elementsOutsideToReport, diObjects
function checkElementsArray(elements, elementsToReport, diObjects) {
for (let i = 0; i < elements.length - 1; i++) {
const element = elements[i];

for (let j = i + 1; j < elements.length; j++) {
const element2 = elements[j];

if (!diObjects.has(element) || !diObjects.has(element2)) {
continue;
}

// ignore if Boundary events overlap their host
// but still check if they overlap other elements
if (element.attachedToRef === element2 || element2.attachedToRef === element) {
Expand Down

0 comments on commit 6a2e3bd

Please sign in to comment.