Conversation
…lyzers The JavaScriptMetricsAnalyzer and TypeScriptMetricsAnalyzer classes were nearly identical (~400 lines of duplicated logic). Extract the common analysis algorithm into a new JsLikeMetricsAnalyzer base class in jsLikeAnalyzer.ts. Both analyzers now extend this base, providing only the language-specific Tree-sitter parser instance. No behaviour changes — the public API and analysis output are identical. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot resolve the merge conflicts in this pull request |
… class Merge origin/main into PR branch. Conflicts in javascriptAnalyzer.ts and typescriptAnalyzer.ts resolved by keeping the thin-wrapper versions from this branch. The for_of_statement bug fix from PR #267 is ported into the shared base class jsLikeAnalyzer.ts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #266 +/- ##
==========================================
- Coverage 68.81% 66.92% -1.89%
==========================================
Files 8 9 +1
Lines 2937 2561 -376
Branches 279 222 -57
==========================================
- Hits 2021 1714 -307
+ Misses 914 846 -68
+ Partials 2 1 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add dedicated test suite for the shared base class exercising:
- Nested method_definition and function_declaration reason strings
- Anonymous function expression naming ('(anonymous)')
- Unlabeled continue (no complexity)
- for...in vs for...of detection
- Deep nesting with mixed control flow
- Catch clause nesting
- do...while inside for loop
- Nested ternary expressions
- Logical operator combinations inside control flow
- Nested function complexity isolation
- Empty/edge cases (empty body, empty source, positions)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
function_declaration is not in isNestedFunction(), so it is analyzed as part of the outer function body rather than collected as a separate function. Fix the test to assert 1 result instead of 2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the JS/TS cognitive complexity analyzers by extracting their shared Tree-sitter traversal and scoring logic into a new JsLikeMetricsAnalyzer base class, leaving JavaScriptMetricsAnalyzer and TypeScriptMetricsAnalyzer as thin parser-configuring wrappers.
Changes:
- Added
JsLikeMetricsAnalyzer(and shared metric interfaces) to centralize JS-like analysis logic. - Updated
JavaScriptMetricsAnalyzerandTypeScriptMetricsAnalyzerto extend the shared base class. - Simplified wrapper analyzers’
analyzeFileimplementations to delegate directly to the base implementation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/metricsAnalyzer/languages/jsLikeAnalyzer.ts | Introduces the shared JS/TS analysis implementation and shared metric types. |
| src/metricsAnalyzer/languages/javascriptAnalyzer.ts | Refactored into a thin wrapper that configures the JS parser and delegates to the base class. |
| src/metricsAnalyzer/languages/typescriptAnalyzer.ts | Refactored into a thin wrapper that configures the TS parser and delegates to the base class. |
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
JavaScriptMetricsAnalyzerandTypeScriptMetricsAnalyzerwere nearly identical — ~400 lines of duplicated analysis logic. This PR extracts the shared algorithm into a newJsLikeMetricsAnalyzerbase class, reducing the two files to thin wrappers that only supply the language-specific Tree-sitter parser.What Changed
src/metricsAnalyzer/languages/jsLikeAnalyzer.tssrc/metricsAnalyzer/languages/javascriptAnalyzer.tssrc/metricsAnalyzer/languages/typescriptAnalyzer.tsNet change: -821 lines added, +444 lines (saves ~380 lines of duplication).
No Behaviour Changes
analyzeFile()API of both classes is unchangedJsLikeFunctionMetricsis identical in shape to the previous privateJavaScriptFunctionMetrics/TypeScriptFunctionMetricsinterfacesMetricsAnalyzerFactoryregisters both analyzers identically — no changes needed thereonLanguage:javascript,onLanguage:typescript, etc.) remain unchangedTrade-offs
JsLikeMetricsAnalyzerand setting up a parser — the analysis logic is inherited automaticallyJsLikeMetricsDetail,JsLikeFunctionMetrics) are now exported, making them available for future test files without duplicationTest Status
npm run compile— no errorsnpm run lint— no warningsnpm test(vscode-test) — requires VS Code download; not available in this sandboxed environment (known infrastructure limitation). Tests run correctly in Codespaces/local environments.