Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/contracts/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface RuleContext {
componentDepth: number;
maxDepth: number;
path: string[];
/** Ancestor node types from root to parent (excludes current node). */
ancestorTypes: string[];
siblings?: AnalysisNode[] | undefined;
/** Per-analysis shared state. Created fresh for each analysis run, eliminating module-level mutable state. */
analysisState: Map<string, unknown>;
Expand Down
5 changes: 5 additions & 0 deletions src/core/engine/rule-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export class RuleEngine {
failedRules,
0,
[],
[],
0,
analysisState,
undefined,
Expand Down Expand Up @@ -234,6 +235,7 @@ export class RuleEngine {
failedRules: RuleFailure[],
depth: number,
path: string[],
ancestorTypes: string[],
componentDepth: number,
analysisState: Map<string, unknown>,
parent?: AnalysisNode,
Expand Down Expand Up @@ -261,6 +263,7 @@ export class RuleEngine {
componentDepth: currentComponentDepth,
maxDepth,
path: nodePath,
ancestorTypes,
siblings,
analysisState,
};
Expand Down Expand Up @@ -308,6 +311,7 @@ export class RuleEngine {

// Recurse into children
if (node.children && node.children.length > 0) {
const childAncestorTypes = [...ancestorTypes, node.type];
for (const child of node.children) {
this.traverseAndCheck(
child,
Expand All @@ -318,6 +322,7 @@ export class RuleEngine {
failedRules,
depth + 1,
nodePath,
childAncestorTypes,
currentComponentDepth + 1,
analysisState,
node,
Expand Down
8 changes: 3 additions & 5 deletions src/core/rules/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ function buildFingerprint(node: AnalysisNode, depth: number): string {

/**
* Check if the node is inside an INSTANCE subtree.
* Currently checks immediate parent only — RuleContext does not expose the full
* ancestor type chain (context.path contains names, not types).
* TODO: When the engine exposes ancestor types, extend to full chain check.
* Walks the full ancestor type chain to detect INSTANCE at any level.
*/
function isInsideInstance(context: {
parent?: AnalysisNode | undefined;
ancestorTypes: string[];
}): boolean {
return context.parent?.type === "INSTANCE";
return context.ancestorTypes.includes("INSTANCE");
}


Expand Down
12 changes: 7 additions & 5 deletions src/core/rules/component/missing-component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function makeContext(overrides?: Partial<RuleContext>): RuleContext {
componentDepth: 0,
maxDepth: 10,
path: ["Page", "Section"],
ancestorTypes: [],
analysisState,
...overrides,
};
Expand Down Expand Up @@ -321,15 +322,16 @@ describe("missing-component — Stage 3: Structure-based repetition", () => {
const frameB = makeNode({ id: "f:2", children: [childB] });
const frameC = makeNode({ id: "f:3", children: [childC] });

const instanceParent: AnalysisNode = {
id: "inst:1",
name: "MyInstance",
type: "INSTANCE",
const nestedFrameParent: AnalysisNode = {
id: "frame:1",
name: "NestedFrame",
type: "FRAME",
visible: true,
};

const ctx = makeContext({
parent: instanceParent,
parent: nestedFrameParent,
ancestorTypes: ["DOCUMENT", "INSTANCE", "FRAME"],
siblings: [frameA, frameB, frameC],
});

Expand Down
1 change: 1 addition & 0 deletions src/core/rules/rule-exceptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function makeContext(overrides: Partial<RuleContext> = {}): RuleContext {
componentDepth: 0,
maxDepth: 10,
path: ["Root", "Test"],
ancestorTypes: [],
analysisState: new Map(),
...overrides,
};
Expand Down
1 change: 1 addition & 0 deletions src/core/rules/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function makeContext(overrides?: Partial<RuleContext>): RuleContext {
componentDepth: 0,
maxDepth: 10,
path: ["Page", "Section"],
ancestorTypes: [],
analysisState: new Map(),
...overrides,
};
Expand Down
Loading