Skip to content

refactor: migrate shared algorithms to codescan-core#43

Open
DaisukeYoda wants to merge 6 commits intomainfrom
refactor/migrate-to-codescan-core
Open

refactor: migrate shared algorithms to codescan-core#43
DaisukeYoda wants to merge 6 commits intomainfrom
refactor/migrate-to-codescan-core

Conversation

@DaisukeYoda
Copy link
Copy Markdown
Member

Summary

  • Replace local implementations of CFG, APTED, MinHash/LSH, clone grouping (5 strategies), and Tarjan SCC with language-agnostic equivalents from codescan-core
  • Introduce JS-specific adapters: JSStatementClassifier, JSComplexityContributor, TreeConverter, DirectedGraphAdapter, GroupableItem on domain.Clone
  • Fix complexity calculation bug where node.Walk() traversed into nested function bodies, inflating parent function complexity (e.g. lodash anonymous_9: 1034 → 27)
  • Net reduction: -3,924 lines (1,059 added / 4,983 deleted)

Deleted files (7)

File Replaced by
internal/analyzer/cfg.go codescan-core/cfg
internal/analyzer/apted.go codescan-core/apted
internal/analyzer/apted_tree.go codescan-core/apted
internal/analyzer/minhash.go codescan-core/lsh
internal/analyzer/lsh_index.go codescan-core/lsh
internal/analyzer/ast_features.go codescan-core/clone
internal/analyzer/grouping_strategy.go (algorithms) codescan-core/clone (generics)

New files (3)

File Purpose
internal/analyzer/js_classifier.go cfg.StatementClassifier for JS return/break/continue/throw
internal/analyzer/js_complexity.go cfg.ComplexityContributor for JS logical/ternary operators
internal/analyzer/tree_converter.go *parser.Node*apted.TreeNode conversion

Test plan

  • go build ./... passes
  • go test ./... — all tests pass
  • go vet ./... — no issues
  • End-to-end validation: jscan analyze, jscan check, jscan deps on lodash test repo
  • Complexity values verified against lodash (no more inflated scores)

🤖 Generated with Claude Code

Daisuke Yoda and others added 6 commits February 15, 2026 01:58
Replace local implementations of CFG, APTED, MinHash/LSH, clone grouping,
and Tarjan SCC with language-agnostic equivalents from codescan-core.
Keep only JavaScript/TypeScript-specific logic locally (parser, classifiers,
cost models). Fix complexity calculation bug where nested function bodies
inflated parent function complexity scores.

Deleted files (7): cfg.go, apted.go, apted_tree.go, minhash.go,
lsh_index.go, ast_features.go, grouping_strategy algorithms.

New files (3): js_classifier.go (StatementClassifier), js_complexity.go
(ComplexityContributor), tree_converter.go (AST→APTED TreeNode).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
P1: Add TODO comment to replace directive — cannot remove until
codescan-core is published to a Go module proxy.

P2: Populate Nodes field in ComplexityResult using cfg.Size() so
node counts are no longer reported as 0 in CSV/JSON/text outputs.

P3: Fix nil dereference in Clone.ItemKey() — check c == nil before
accessing c.ID to prevent panic on nil clone pointers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use the published v0.1.0 module from the Go module proxy instead
of a local path replacement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
corecfg counts EdgeLoop back-edges as decision points, but jscan's
CFG already creates EdgeCondTrue/EdgeCondFalse at loop headers.
Subtract loop back-edge count to avoid double-counting each loop.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
codescan-core v0.1.1 no longer counts EdgeLoop back-edges as decision
points, so the jscan-side subtraction workaround is no longer needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant