Skip to content

Deeper Go and Rust checks: interface{}/any and unsafe density, cargo workspaces - #13

Merged
ranjan-mohanty merged 2 commits into
mainfrom
roadmap/go-rust-depth
Nov 15, 2026
Merged

ranjan-mohanty merged 2 commits into
mainfrom
roadmap/go-rust-depth

Conversation

@ranjan-mohanty

Copy link
Copy Markdown
Collaborator

Roadmap item (part 1 of 2): Deeper Go and Rust checks: unsafe and interface{} density, and nested Cargo.toml workspaces. Java/Kotlin comes in a separate PR.

What

Three new checks in src/checks/go-rust.ts. Each is n/a when the language is absent and weighted by the language's share of the code (weightScale).

id weight measures scoring
types.go-any 1 interface{} and any used as a type per kloc of Go product code. Not counted: generic constraints ([T any], [K comparable, V any], [K, V any]), comments and strings, _test.go, .pb.go/_gen.go/zz_generated, vendor and examples. 1.0 at ≤ 2/kloc, linear down to 0.7 at ≥ 30/kloc; top files as info findings
types.rust-unsafe 1 unsafe { }, unsafe fn/impl/trait/extern per kloc of Rust product code. Comments and strings stripped; -sys FFI crates, tests, benches and fuzz skipped. #![forbid(unsafe_code)] / #![deny(unsafe_code)] in every crate root, or unsafe_code = "forbid" in Cargo.toml, scores 1. 1.0 at ≤ 1/kloc, linear down to 0.7 at ≥ 20/kloc
feedback.cargo-workspace 1 Whether one cargo invocation reaches every crate. The primary workspace is the root one, or else the one reaching the most crates (codex keeps its workspace in codex-rs/). Understood: members globs, exclude (deliberate, not counted), path dependencies, which Cargo makes implicit members, and cargo-fuzz fuzz/ workspaces (skipped). Flagged: separate nested workspaces and crates in no workspace. share of crates reached

The penalties are deliberately mild (floor 0.7), in line with how types.typescript treats any. Runtimes and FFI code legitimately need unsafe, and Go APIs like zap's sugared logger take interface{} by design.

Tests

test/go-rust.test.ts (8 tests) covers:

  • Go counting: param, map value, variadic and slice uses count; generic constraints, comments, strings and non-empty interfaces don't
  • dense vs clean Go, with tests and .pb.go excluded
  • Rust counting: no false hits on identifiers, comments or strings
  • -sys skipping and forbid(unsafe_code)
  • cargo workspaces: globs + exclude + path deps + fuzz all pass; a nested workspace and an orphan crate are both flagged; a single crate is n/a
  • TOML array parsing

npm run check && npm run build pass (91 tests). Self-score is still 100/100.

Scores (before → after)

repo overall details
ripgrep 62 → 63 0.1 unsafe/kloc; all 10 crates in the root workspace (feedback 93 → 94)
zap 69 → 69 10.9 any/kloc (sugared logger) → types 100 → 95
tokio 66 → 65 9.4 unsafe/kloc (it's a runtime) → types 100 → 93
hugo 80 → 78 15.2 any/kloc (template funcs) → types 100 → 93
hyper 66 → 66 3.0 unsafe/kloc (FFI module) → types 98
cobra 63 → 63 3.8 any/kloc → types 99
codex 67 → 67 1.1 unsafe/kloc; 169 of 170 crates reached. tools/argument-comment-lint is a separate workspace and is flagged.
ollama 79 → 79 8.0 any/kloc
other 12 comparison repos unchanged no Go/Rust

An earlier draft flagged 3 codex crates as "in no workspace". They were path dependencies, which Cargo adds as members automatically, so this is now handled.

🤖 Generated with Claude Code

…workspaces

- types.go-any: interface{}/any as a type per kloc of Go product code
  (generic constraints, comments, strings, tests, generated files excluded)
- types.rust-unsafe: unsafe blocks/fns/impls per kloc of Rust (-sys crates
  skipped; forbid(unsafe_code) scores 1)
- feedback.cargo-workspace: one cargo workspace reaches every crate;
  flags nested workspaces and orphan crates, understands members globs,
  exclude, path dependencies and fuzz/ crates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts: src/checks/index.ts (goRustChecks registered with docHistoryCheck, agentToolingChecks and runChecks), README.md (check table merged: Rust cargo-workspace item kept; also lists the MCP/hooks, Go any / Rust unsafe density and agent-permissions checks; roadmap keeps all ticks and the '(Go/Rust done)' note), CHANGELOG.md (one [Unreleased]). feedback.cargo-workspace is repo-only in per-package scans, like feedback.ci.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ranjan-mohanty
ranjan-mohanty merged commit 100cb95 into main Nov 15, 2026
9 checks passed
@ranjan-mohanty
ranjan-mohanty deleted the roadmap/go-rust-depth branch November 15, 2026 00:29
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