codelore-rca: Vendored Mozilla rust-code-analysis
This crate is a maintained fork of mozilla/rust-code-analysis.
Upstream baseline
- Source commit:
37e5d83c056c8cbf827223d5814a93c5218df1a9 - Source date:
2026-01-20 - Vendored on: 2026-06-06
Upstream layout notes
The upstream repository is structured as a Cargo workspace:
src/— the main library crate (what we vendor)rust-code-analysis-cli/— CLI binary (NOT vendored)rust-code-analysis-web/— actix-web HTTP frontend (NOT vendored; this is the "web" drop)tree-sitter-mozcpp/— Mozilla tree-sitter-cpp fork (NOT vendored; external dep)tree-sitter-mozjs/— Mozilla tree-sitter-js fork (NOT vendored; external dep)tree-sitter-ccomment//tree-sitter-preproc/— custom grammars (NOT vendored; external deps)
Note: src/languages/language_mozcpp.rs does NOT exist in this upstream revision.
The mozcpp grammar lives in the tree-sitter-mozcpp/ top-level crate and is accessed
via macros.rs referencing tree_sitter_mozcpp::LANGUAGE. That external dep reference
in src/macros.rs is kept as-is and will be resolved in Task 5 (Cargo.toml).
Modifications from upstream
The following were REMOVED from the vendored tree:
-
src/languages/language_mozjs.rs— Mozilla-specific tree-sitter-js fork (generated code, ~3000 lines ofMozjsenum variants). Thepub mod language_mozjsandpub use language_mozjs::*declarations insrc/languages/mod.rswere removed. -
src/metrics/abc.rs— ABC metric (Assignments/Branches/Conditions). Java-only specialization. -
src/metrics/wmc.rs— WMC metric (Weighted Methods per Class). Java-only specialization. -
src/metrics/npa.rs— NPA metric (Number of Public Attributes). Java-only specialization. -
src/metrics/npm.rs— NPM metric (Number of Public Methods). Java-only specialization. Thepub mod abc,pub mod wmc,pub mod npa,pub mod npmdeclarations insrc/metrics/mod.rswere removed.
Task 5 excision (completed 2026-06-06)
Option B chosen: fully excise Mozjs and dropped metrics.
The dangling references from Task 4's file drops were resolved by:
Mozjs excision
src/langs.rs— removed Mozjs entry frommk_langs!; moved js/jsm/mjs/jsx extensions to Javascriptsrc/macros.rs— restored mozcpp special-case forget_language!(tree_sitter_cpp); removedimplement_metric_trait!(Abc, ...)andimplement_metric_trait!(Wmc, ...)macro armssrc/checker.rs— removedimpl Checker for MozjsCodeblocksrc/getter.rs— removedimpl Getter for MozjsCodeblock; fixedMozjs::Pair/Mozjs::VariableDeclaratorreferences in JS/TS/TSX impl blocks to use correct enum namespacessrc/alterator.rs— removedimpl Alterator for MozjsCodeblocksrc/metrics/cognitive.rs— removedimpl Cognitive for MozjsCode; updated MozjsParser tests to use JavascriptParser. The re-pointed mozjs else-if test read sum 16 instead of 11 not because of a grammar difference but because the JavaScriptis_else_ifhelper compared the wrong parent node kind and never matched, soelse ifbranches were over-counted. The cognitive-complexity correctness fix (see the "Cognitive-complexity correctness" section) restores 11.src/metrics/cyclomatic.rs— removedimpl Cyclomatic for MozjsCodesrc/metrics/exit.rs— removedimpl Exit for MozjsCodesrc/metrics/halstead.rs— removedimpl Halstead for MozjsCode; updated MozjsParser test refssrc/metrics/loc.rs— removedimpl Loc for MozjsCode; updated MozjsParser test refssrc/metrics/mi.rs— removed MozjsCode fromimplement_metric_trait!([Mi], ...)src/metrics/nargs.rs— removed MozjsCode fromimplement_metric_trait!([NArgs], ...)src/metrics/nom.rs— removed MozjsCode fromimplement_metric_trait!([Nom], ...)src/ops.rs— removedmozjs_opsandmozjs_function_opstests
Abc/Wmc/Npa/Npm excision
src/spaces.rs— removed imports, struct fields, merge/compute callssrc/traits.rs— removed Abc/Wmc/Npa/Npm from ParserTrait associated typessrc/parser.rs— removed trait bounds and associated type assignmentssrc/output/dump_metrics.rs— removed imports and dump_abc/wmc/npm/npa functions
Files modified: 15 source files + Cargo.toml + UPSTREAM.md
Tree-sitter grammar version notes
The language_*.rs enum files were generated from specific grammar versions. Using mismatched
grammar versions causes node-ID mismatches and silent metric failures. Pinned versions verified
by checking root node kind_id against enum constants:
| Grammar | Version | Key node |
|---|---|---|
| tree-sitter-javascript | =0.23.1 | program id=133 |
| tree-sitter-typescript | =0.23.1 | program id=166/172 |
| tree-sitter-python | =0.23.6 | module id=108 |
| tree-sitter-java | =0.23.5 | program id=138 |
| tree-sitter-rust | =0.23.2 | source_file id=155 |
| tree-sitter-kotlin-ng | 1.1.0 | source_file id=142 |
| bca-tree-sitter-mozcpp | 1.1.0 | translation_unit id=308 |
| bca-tree-sitter-ccomment | 1.1.0 | (aliased as tree-sitter-ccomment) |
| bca-tree-sitter-preproc | 1.1.0 | (aliased as tree-sitter-preproc) |
C++ uses bca-tree-sitter-mozcpp (aliased as tree-sitter-mozcpp) because language_cpp.rs
was generated from the mozcpp grammar. The get_language!(tree_sitter_cpp) macro arm routes
to tree_sitter_mozcpp::LANGUAGE.
When upgrading grammar versions in future, verify node IDs by running:
let root = tree.root_node();
println!("{} id: {}", root.kind(), root.kind_id());
and comparing against the enum constants in src/languages/language_*.rs.
Cognitive-complexity correctness
The cognitive-complexity visitors in src/metrics/cognitive.rs and their
is_else_if helpers in src/checker.rs diverge from upstream to correct
miscounts against the Campbell/SonarSource cognitive-complexity specification.
Current behavior:
-
else ifdetection.is_else_iffor JavaScript and TSX compares the parent node kind againstelse_clause. Upstream compared it againstif_statement, which never matches because tree-sitter wraps the else branch in anelse_clause; the result was thatelse ifbranches were counted as freshly-nestedifs. Java has noelse_clausenode, so itsis_else_ifmatches anif_statementwhose parentif_statementholds it as thealternativefield. -
Missing nesting constructs. The increase-nesting arm also covers Rust
loop, Java enhanced-forand ternary, and Pythonmatch.case/switcharms add nothing on their own, matching upstream's treatment ofswitch. -
finallyis not a branch. Pythonfinallydoes not increment; onlyelse,elif, andexceptdo.except/catchstill counts via its own arm.
License
The upstream rust-code-analysis package declares license = "MPL-2.0" in its Cargo.toml.
No LICENSE file was present at the repository root at the vendored commit; the LICENSE-MPL
file in this directory contains the canonical MPL-2.0 text.
Original files retain their MPL-2.0 license as declared by upstream. New files added by bca contributors carry GPL-3.0-only headers.
SPDX (crate-level): MPL-2.0 AND GPL-3.0-only
See also: Mozilla's MPL combining guide.
Sync procedure
To pull upstream fixes:
- Fetch upstream commits since the SHA above.
- Cherry-pick correctness fixes and grammar bumps (avoid Mozilla-specific features).
- Update this file with the new SHA + date.
- Run
cargo test -p codelore-rcato verify.
Year-1 maintenance budget: ~8 days (see spec §4.1).