Skip to content

feat: initial implementation of codeanalyzer-go#4

Draft
sinha108 wants to merge 6 commits into
mainfrom
feat/initial-implementation
Draft

feat: initial implementation of codeanalyzer-go#4
sinha108 wants to merge 6 commits into
mainfrom
feat/initial-implementation

Conversation

@sinha108

@sinha108 sinha108 commented Jul 3, 2026

Copy link
Copy Markdown

Summary

  • Static analyzer for Go projects producing analysis.json (symbol table + call graph) in the CLDK canonical schema
  • Consumable by the Python SDK via CLDK(language="go").analysis(project_path=...)
  • Level 1: symbol table via go/ast + golang.org/x/tools/go/packages
  • Level 2: resolver-based call graph via go/types

What's included

  • cmd/codeanalyzer — Cobra CLI (-i, -o, -a, -t, --skip-tests, --eager, --cache-dir, -v, --version)
  • internal/syntactic_analysisSymbolTableBuilder: structs, interfaces, methods, generics, closures, call sites, cyclomatic complexity, struct tags, cross-file method reconciliation
  • internal/semantic_analysisCallGraphBuilder: go/types resolver backfills callee_signature and emits project-internal call edges; CodeQL backend wired but stubbed
  • internal/analysis — pluggable pass registry with topological ordering (extension seam for framework passes)
  • internal/frameworksBaseEntrypointFinder seam for Gin/net-http entrypoint detection
  • internal/schema — canonical output types (GoApplication, GoFile, GoType, GoCallable, GoCallsite, GoCallEdge) with spine-compatible JSON keys

Test fixtures

Fixture Purpose
testdata/greeter/ Minimal two-package fixture (struct, interface, basic call sites)
testdata/multipackage/ Embedded fields, variadic params, goroutines, cross-file methods, multiple return types
testdata/generics/ Go 1.18+ generics (Set[T], union-constraint interfaces, multi-type-param functions)
testdata/chi/ Vendored chi v5 (35 files) — real-world HTTP router patterns, closures, init()

105 tests across symbol table correctness, call graph edges, generics, JSON round-trip, caching, incremental analysis, and error paths.

Test plan

  • go test ./... passes (all 105 tests)
  • go build ./... succeeds
  • go vet ./... clean
  • Level 1 analysis on a real project produces valid analysis.json
  • Level 2 analysis produces non-empty call graph with no dangling edges

sinha108 added 4 commits July 3, 2026 13:39
Adds the static code analysis engine for Go including syntactic analysis,
schema definitions, CLI entrypoint, and test fixtures. Semantic analysis
via CodeQL is scaffolded but not yet implemented.

Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
Incorporates the GitHub Go template (*.dll, *.so, go.work, .env, etc.)
alongside project-specific ignores for built binaries and .claude/.

Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
Bug fix: populate InnerCallables by walking ast.FuncLit nodes in
buildInnerCallables; add *ast.FuncLit: return false to buildCallSites so
closure call sites are not double-counted in the outer function.

New test files:
- cmd/codeanalyzer/main_test.go: CLI integration tests covering --version,
  --format validation, --output, --analysis-level, --skip-tests, --target-files
- internal/analysis/registry_test.go: orderPasses topo-sort tests and
  RunPipeline smoke test
- internal/semantic_analysis/call_graph_test.go: MergeEdges unit tests
- internal/utils/fs_test.go: table-driven tests for IsTestFile, IsVendored,
  FileHash, EnsureDir, DiscoverGoFiles
- internal/core/skip_tests_test.go: SkipTests true/false behaviour
- internal/core/incremental_test.go: TargetFiles single/multi package and nil

Test additions to existing files:
- chi_test.go: InnerCallables populated, IsConstructorCall for methodTyp()
  type conversion, init() presence and is_exported
- multipackage_test.go (renamed from realistic_test.go): LocalVariables
  present with correct type and scope

Testdata restructure:
- testdata/fixture/ -> testdata/greeter/
- testdata/realistic/ -> testdata/multipackage/
- testdata/chi/: replace single-file wrapper with chi v5 library source (35 files)
- testdata/generics/: add generics fixture (fn + set packages)
- testdata/multipackage/server/server_test.go: minimal test file for
  --skip-tests=false coverage

Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
- Add .github/workflows/ci.yml: test (go build + go test) and lint
  (golangci-lint) jobs triggered on push to main/feat/** and PRs to main
- Fix stale testdata path references in README (fixture/→greeter/,
  realistic/→multipackage/) and update test count (57→105)
- Add /output/ to .gitignore to exclude generated analysis artifacts

Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
@sinha108 sinha108 requested a review from rahlk July 3, 2026 17:42
sinha108 added 2 commits July 3, 2026 13:45
golangci-lint-action@v6 resolved to v1.64.8 (built with Go 1.24) which
refuses to analyze go 1.25.0 modules. Installing via go install compiles
the tool from source using the project's own toolchain, so the version
check always passes.

Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
- fs_test.go: use writeFile helper for TestFileHash_DifferentContent
  and check os.MkdirAll error in TestDiscoverGoFiles_SkipsVendorDir
- signature.go: remove unused signatureOfNamed, signatureForCall,
  normalizeReturnType functions and their unused strings import

Signed-off-by: Saurabh Sinha <sinha108@gmail.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