Skip to content

Commit b3e49f2

Browse files
authored
added cross-link detection
1 parent d400e51 commit b3e49f2

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

lib/rules/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ module.exports = {
66
"no-overlapping-nodes": require("./no-overlapping-nodes"),
77
"no-unconnected-http-nodes": require("./no-unconnected-http-nodes"),
88
"no-unnamed-functions": require("./no-unnamed-functions"),
9-
"no-unnamed-links": require("./no-unnamed-links")
9+
"no-unnamed-links": require("./no-unnamed-links"),
10+
"no-cross-links": require("./no-cross-links")
1011
}

lib/rules/no-cross-links.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module.exports = {
2+
meta: {
3+
type: "problem",
4+
severity: "warn",
5+
docs: {
6+
description: "Detect link nodes that cross tabs"
7+
},
8+
options: {
9+
crossTabLinks: { type: "boolean", default: true }
10+
}
11+
},
12+
create: function(context, ruleConfig) {
13+
const crossTabLinksEnabled = ruleConfig?.crossTabLinks !== false;
14+
15+
if (!crossTabLinksEnabled) {
16+
return {}; // Rule is disabled, no-op
17+
}
18+
19+
let linkInNodes = [];
20+
let linkOutNodes = [];
21+
let tabs = [];
22+
let tabLabels = {};
23+
24+
return {
25+
"start": function(flow) {
26+
linkInNodes = flow.filter(n => n.type === "link in");
27+
linkOutNodes = flow.filter(n => n.type === "link out");
28+
tabs = flow.filter(n => n.type === "tab");
29+
tabLabels = Object.fromEntries(tabs.map(tab => [tab.id, tab.label]));
30+
},
31+
"node": function(node) {
32+
if (node.type === "link out" && Array.isArray(node.links)) {
33+
node.links.forEach(linkId => {
34+
const targetNode = linkInNodes.find(inNode => inNode.id === linkId);
35+
if (targetNode && node.z !== targetNode.z) {
36+
context.report({
37+
location: [node.id],
38+
message: `Cross-tab link from '${node.name || node.id}' (tab: '${tabLabels[node.z] || node.z}') to '${targetNode.name || targetNode.id}' (tab: '${tabLabels[targetNode.z] || targetNode.z}')`
39+
});
40+
}
41+
});
42+
}
43+
}
44+
};
45+
}
46+
};

0 commit comments

Comments
 (0)