Skip to content

[Repo Assist] feat: add JavaScript and TypeScript cognitive complexity support#164

Draft
github-actions[bot] wants to merge 9 commits intomainfrom
repo-assist/feat-javascript-typescript-support-3681e0e6dabe3d3b
Draft

[Repo Assist] feat: add JavaScript and TypeScript cognitive complexity support#164
github-actions[bot] wants to merge 9 commits intomainfrom
repo-assist/feat-javascript-typescript-support-3681e0e6dabe3d3b

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 1, 2026

🤖 This is an automated pull request from Repo Assist.

Summary

Implements JavaScript and TypeScript cognitive complexity analysis as requested in #32. This adds full CodeLens support for .js, .jsx, .ts, and .tsx files.

Changes

  • New: src/metricsAnalyzer/languages/javascriptAnalyzer.ts — JavaScript analyzer using tree-sitter-javascript
  • New: src/metricsAnalyzer/languages/typescriptAnalyzer.ts — TypeScript analyzer using tree-sitter-typescript
  • Updated: metricsAnalyzerFactory.ts — registers javascript, javascriptreact, typescript, typescriptreact
  • Updated: package.json — adds activation events and new dependencies (tree-sitter-javascript@0.21.4, tree-sitter-typescript@0.21.2)
  • Updated: src/unit/unit.test.ts — 14 new unit tests covering both analyzers
  • New: samples/Test.js and samples/Test.ts — sample files for manual testing

Complexity Constructs Detected

Construct Increment
if +1 + nesting
else if / else +1 (flat)
for, for...of, for...in +1 + nesting
while, do...while +1 + nesting
switch +1 + nesting
catch +1
Ternary ? : +1
&&, ||, ?? +1 each
Labeled break/continue +1
Nested function/arrow function +1 + nesting

Root Cause / Design

The existing factory pattern makes adding new languages straightforward. I used tree-sitter-javascript@0.21.4 and tree-sitter-typescript@0.21.2 — both compatible with the existing tree-sitter@^0.21.1. These are loaded via require() to work around TypeScript type-declaration incompatibilities in those packages.

TypeScript support reuses the same logic as JavaScript since TypeScript is a strict superset; type annotations and interfaces do not contribute to cognitive complexity.

Trade-offs

  • Adds ~6.5MB of new runtime dependencies (tree-sitter-javascript + tree-sitter-typescript)
  • else/else if are tracked separately from the if (per the SonarSource cognitive complexity spec), which differs slightly from the existing C# and Go analyzers (which don't track else explicitly). This is more spec-correct for JS/TS.

Test Status

  • npm run compile — passes
  • npm run lint — passes (0 errors, 0 warnings)
  • npm run test:unit — 33 passing, 2 pending (pre-existing skips)
  • ⚠️ npm test (VS Code integration tests) — not run; requires display/download, expected to succeed in CI

Closes #32

Generated by Repo Assist

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@442992eda2ccb11ee75a39c019ec6d38ae5a84a2

- Add JavaScriptMetricsAnalyzer using tree-sitter-javascript
- Add TypeScriptMetricsAnalyzer using tree-sitter-typescript
- Register javascript, javascriptreact, typescript, typescriptreact in factory
- Add activation events for JS/TS in package.json
- Add tree-sitter-javascript@0.21.4 and tree-sitter-typescript@0.21.2 dependencies
- Add unit tests for both new analyzers
- Add sample files Test.js and Test.ts

Closes #32

Complexity constructs detected: if/else/else-if, for/for-in/for-of,
while/do-while, switch, catch, ternary, logical operators (&&/||/??),
labeled break/continue, nested functions and arrow functions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Incorporate path filtering, concurrency control, and removal of
redundant compile step from PRs #166 and #169 merged to main.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

github-actions bot commented Mar 1, 2026

Commit pushed: 00ba09e

Generated by Repo Assist

dependabot bot and others added 5 commits March 2, 2026 16:40
The samples/Test.ts file was being picked up by the TypeScript compiler
causing a build error since it falls outside rootDir (src/). Adding
samples/ to tsconfig exclude resolves this.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

github-actions bot commented Mar 2, 2026

Commit pushed: 2f1a074

Generated by Repo Assist

…ompile)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

github-actions bot commented Mar 3, 2026

Commit pushed: e812b76

Generated by Repo Assist

…ript)

- Bump eslint devDependency from 10.0.2 to 10.0.3
- Add test:vscode script (matches main)
- Update ci.yml: pin setup-node and codecov action SHAs, restore compile+test:vscode steps
- Add timeout-minutes: 5 to validate_pr_title workflow
- Sync all .github/ workflow and agent files with main

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

github-actions bot commented Mar 9, 2026

Commit pushed: df59f7d

Generated by Repo Assist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add JavaScript/TypeScript Support

1 participant