feat: expose ancestor type chain in RuleContext (#197)#199
Conversation
Add ancestorTypes[] to RuleContext so rules can inspect the full ancestor type chain instead of only the immediate parent. Update isInsideInstance in the component rule to walk the entire chain for accurate INSTANCE subtree detection. https://claude.ai/code/session_01QreN5CXLt6o2bbKmRFYz8x
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR adds an Changes
Sequence Diagram(s)sequenceDiagram
participant Analyzer as RuleEngine.analyze()
participant Traverser as traverseAndCheck()
participant Rule as Rule.check()
participant Children as recurse into children
Analyzer->>Traverser: call with file root, ancestorTypes = []
Traverser->>Rule: build RuleContext (ancestorTypes from param) and invoke rule checks
Rule-->>Traverser: returns findings (if any)
Traverser->>Traverser: append current node.type -> childAncestorTypes
Traverser->>Children: recurse with childAncestorTypes
Children-->>Traverser: child results
Traverser-->>Analyzer: aggregated AnalysisResult
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/core/rules/component/missing-component.test.ts`:
- Around line 332-335: The test currently sets parent: instanceParent so it
still tests immediate-parent INSTANCE behavior; change the immediate parent
passed to makeContext to a non-INSTANCE node (e.g., use an existing frame/group
node like frameB or create a new node with type "FRAME" or "GROUP") and keep
"INSTANCE" only inside ancestorTypes (ancestorTypes:
["DOCUMENT","FRAME","INSTANCE"]) so the code exercises non-immediate INSTANCE
ancestry; update any variable names (replace parent: instanceParent with parent:
frameX) and ensure the test assertions remain the same to validate the new
behavior for the rule under test (referencing makeContext, parent, and
ancestorTypes).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0a0f7320-3432-4c94-9fc3-620b9feef007
📒 Files selected for processing (6)
src/core/contracts/rule.tssrc/core/engine/rule-engine.tssrc/core/rules/component/index.tssrc/core/rules/component/missing-component.test.tssrc/core/rules/rule-exceptions.test.tssrc/core/rules/test-helpers.ts
Change the isInsideInstance test to use a FRAME parent with INSTANCE only in ancestorTypes, ensuring the test actually exercises full chain check. https://claude.ai/code/session_01QreN5CXLt6o2bbKmRFYz8x
Summary
ancestorTypes: string[]추가 — 루트부터 부모까지의 노드 타입 체인isInsideInstance()를 immediate parent 체크에서 full ancestor chain 체크로 개선Test plan
Closes #197
https://claude.ai/code/session_01QreN5CXLt6o2bbKmRFYz8x
Summary by CodeRabbit