refactor: DRY shared abstractions in TS features#843
Conversation
Extract buildRoleSummary() and batchUpdateRoles() helpers shared between classifyNodeRolesFull and classifyNodeRolesIncremental, eliminating ~80 lines of near-identical code.
Extract RawDataflowEdges interface and buildDataflowResult() as the shared core between buildNodeDataflowResult (SQL path) and buildNativeDataflowResult (native path), eliminating ~45 lines of duplicated filter/assembly logic.
|
Claude finished @carlos-alm's task —— View job Reviewing PR: refactor: DRY shared abstractions in TS featuresTodo List:
Root Cause AnalysisProblem Being Solved: Technical debt from code duplication in two critical areas:
Why This Approach: ✓ The refactoring extracts shared logic into parameterized helper functions while preserving the existing APIs. This is a proper abstraction that reduces cognitive complexity from 27→4 and eliminates duplicate code without changing behavior. Risk Assessment: Low risk - pure refactoring with no API changes, no configuration modifications, and only internal helper function extraction. Backlog Compliance
Code Quality Assessment ✓Abstraction Quality: Excellent - both extractions follow clean abstraction principles:
Type Safety: Strong - new interfaces Performance: Neutral/positive - eliminates code duplication without performance overhead Maintainability: Major improvement - single source of truth for complex logic, cognitive complexity reduced from 27→4 per function Final Recommendation
|
Greptile SummaryThis PR DRYs up two pairs of near-duplicate functions: Confidence Score: 5/5Safe to merge — a clean structural refactor with no behaviour changes. Both extractions are faithful: closure-captured variables resolve correctly in the No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph structure.ts
CNR[classifyNodeRoles] -->|full| CNRF[classifyNodeRolesFull]
CNR -->|incremental| CNRI[classifyNodeRolesIncremental]
CNRF --> BRS[buildRoleSummary]
CNRI --> BRS
CNRF --> BUR[batchUpdateRoles]
CNRI --> BUR
BUR -->|resetFn callback| RESET_FULL["reset: UPDATE nodes SET role = NULL"]
BUR -->|resetFn callback| RESET_INC["reset: UPDATE nodes SET role = NULL WHERE file IN (...)"]
end
subgraph dataflow.ts
DD[dataflowData] -->|native path| BNDR[buildNativeDataflowResult]
DD -->|SQL path| BNDR2[buildNodeDataflowResult]
BNDR --> BDR[buildDataflowResult]
BNDR2 --> BDR
BDR -->|noTests=true| FILTERED[filtered result]
BDR -->|noTests=false| UNFILTERED[unfiltered result]
end
Reviews (1): Last reviewed commit: "refactor: unify duplicate dataflow resul..." | Re-trigger Greptile |
Codegraph Impact Analysis13 functions changed → 9 callers affected across 5 files
|
Summary
classifyNodeRolesFullandclassifyNodeRolesIncremental(near-duplicates, both cog=27) into a singleclassifyNodeRolefunctionbuildNodeDataflowResultandbuildNativeDataflowResult(near-duplicate result builders) into a single parameterizedbuildDataflowResultfunctionTitan Audit Context
Changes
src/features/structure.ts-- extract shared classifyNodeRole, reducing duplication between Full and Incremental variantssrc/features/dataflow.ts-- unify duplicate dataflow result builders into parameterized functionMetrics Impact
Test plan