[Repo Assist] feat: add JavaScript and TypeScript cognitive complexity support#164
Draft
github-actions[bot] wants to merge 9 commits intomainfrom
Draft
Conversation
- 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>
6 tasks
Contributor
Author
|
Commit pushed:
|
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>
Contributor
Author
|
Commit pushed:
|
…ompile) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Commit pushed:
|
…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>
Contributor
Author
|
Commit pushed:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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.tsxfiles.Changes
src/metricsAnalyzer/languages/javascriptAnalyzer.ts— JavaScript analyzer usingtree-sitter-javascriptsrc/metricsAnalyzer/languages/typescriptAnalyzer.ts— TypeScript analyzer usingtree-sitter-typescriptmetricsAnalyzerFactory.ts— registersjavascript,javascriptreact,typescript,typescriptreactpackage.json— adds activation events and new dependencies (tree-sitter-javascript@0.21.4,tree-sitter-typescript@0.21.2)src/unit/unit.test.ts— 14 new unit tests covering both analyzerssamples/Test.jsandsamples/Test.ts— sample files for manual testingComplexity Constructs Detected
ifelse if/elsefor,for...of,for...inwhile,do...whileswitchcatch? :&&,||,??break/continueRoot Cause / Design
The existing factory pattern makes adding new languages straightforward. I used
tree-sitter-javascript@0.21.4andtree-sitter-typescript@0.21.2— both compatible with the existingtree-sitter@^0.21.1. These are loaded viarequire()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
tree-sitter-javascript+tree-sitter-typescript)else/else ifare tracked separately from theif(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— passesnpm 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 CICloses #32