refactor: improve TS code quality across modules#847
Conversation
|
Claude finished @carlos-alm's task —— View job PR Review: TypeScript Quality ImprovementsReviewing PR #847 following comprehensive 5-phase analysis: Todo List
Phase 2: Configuration Change Detection ✅No Configuration Changes: No biome.json, tsconfig.json, or package.json changes detected. No linting rules were relaxed or disabled. No TODO/FIXME comments indicating workarounds. Phase 3: Test Integrity ✅No Test Modifications: Zero test files were modified in this PR. Only formatting changes found (whitespace/indentation adjustments). No test expectations were weakened or removed. Phase 4: Code Quality Assessment ✅Excellent Refactoring Quality - Each file shows clear improvements: 1.
2.
3.
4.
5.
6.
7.
8.
9.
Security & Performance: No security issues introduced. Performance unchanged or slightly improved due to better code organization. No new dependencies added. Maintainability: Significant improvement across all files. Functions are now focused, testable, and follow consistent patterns throughout the codebase. Phase 5: Backlog Compliance ✅Zero-dep: ✅ — No new runtime dependencies added. Pure refactoring within existing codebase using tree-sitter/SQLite/existing AST infrastructure. Foundation-aligned: ✅ — Fully compliant with all principles:
Problem-fit: 3/5 — Indirectly supports the core problem by:
Breaking: No — All public APIs maintained. CLI output format unchanged. No DB schema changes. MCP tool contracts preserved. Tier: 1 (zero-dep ✅ + foundation-aligned ✅) Root Cause AnalysisProblem Being Solved: Technical debt reduction targeting specific complexity hotspots (watchProject cog=59, bugs=1.30) and general maintainability issues across presentation, extraction, and analysis modules. Backlog Compliance
Critical ConcernsNone identified. This is exemplary refactoring work. Final Recommendation
|
Greptile SummaryThis PR is a quality-focused refactor that splits monolithic formatter and extractor functions into focused sub-renderers and helper functions across presentation, domain, extractor, and AST-analysis modules. The complexity reductions are real and the extracted logic is faithful to the original in all files except one.
Confidence Score: 4/5Safe to merge after fixing the unhandled rejection in the watcher debounce callback. One P1 issue remains: an unhandled async rejection in scheduleDebouncedProcess that can crash the watcher process under Node >= 22.6. All other files are clean refactors with no logic changes. The prior SIGINT concern from the previous review round was resolved. src/domain/graph/watcher.ts — the scheduleDebouncedProcess setTimeout callback needs a .catch() or try/catch wrapper around processPendingFiles. Important Files Changed
Reviews (2): Last reviewed commit: "fix: address Greptile review feedback (#..." | Re-trigger Greptile |
src/domain/graph/watcher.ts
Outdated
|
|
||
| /** Register SIGINT handler to flush journal and clean up. */ | ||
| function setupShutdownHandler(ctx: WatcherContext, cleanup: () => void): void { | ||
| process.on('SIGINT', () => { |
There was a problem hiding this comment.
Consider
process.once instead of process.on for SIGINT
process.on accumulates a new listener every time setupShutdownHandler is called. In the current code watchProject is intended to be called once per process, so this is fine in production, but test runners or future callers that invoke watchProject more than once will accumulate handlers and eventually trigger Node's MaxListenersExceededWarning. process.once avoids the leak without any functional change.
| process.on('SIGINT', () => { | |
| process.once('SIGINT', () => { |
There was a problem hiding this comment.
Fixed in 03015d9 — changed process.on to process.once as suggested.
There was a problem hiding this comment.
Fixed in 03015d9 — changed process.on to process.once as suggested.
Codegraph Impact Analysis51 functions changed → 53 callers affected across 19 files
|
Use process.once instead of process.on for SIGINT handler in watcher to prevent listener accumulation on repeated calls. Replace nullish coalescing (??) with logical OR (||) in engine.ts native analysis check to better communicate "any method exists" intent.
|
Both Greptile suggestions addressed in 03015d9:
|
Summary
watchProject(cog=59, bugs=1.30)Titan Audit Context
Changes
src/presentation/manifesto.ts-- split into sub-rendererssrc/presentation/communities.ts-- split into sub-rendererssrc/presentation/queries-cli/inspect.ts-- split into sub-rendererssrc/domain/graph/watcher.ts-- extract debounce and journal logicsrc/extractors/javascript.ts-- split dispatchQueryMatch into sub-handlerssrc/extractors/go.ts-- split inferShortVarType into sub-handlerssrc/shared/file-utils.ts-- split extractSummary into sub-functionssrc/ast-analysis/visitors/ast-store-visitor.ts-- lookup table for dispatchsrc/ast-analysis/engine.ts-- extract per-analysis setup helpersMetrics Impact
Test plan