big-code-analysis 2.0.0

Tool to compute and export code metrics
Documentation
[workspace]
resolver = "3"
members = [
  "big-code-analysis-cli",
  "big-code-analysis-py",
  "big-code-analysis-web",
  "xtask",
]
# `xtask` and `big-code-analysis-py` are intentionally excluded from
# `default-members`. `xtask` is a build-time helper that renders man
# pages from the live clap definitions (see `xtask/src/main.rs` and
# `man/`); `big-code-analysis-py` is a PyO3 cdylib that requires
# Python headers and is built via `maturin`, not pure cargo. Both
# build cleanly under `cargo build --workspace`, but a bare
# `cargo build` at the repo root should not pull in artefacts that
# have no shipping counterpart in a Rust-only build.
default-members = [".", "big-code-analysis-cli", "big-code-analysis-web"]
exclude = [
  "enums",
  "tree-sitter-ccomment",
  "tree-sitter-mozcpp",
  "tree-sitter-mozjs",
  "tree-sitter-preproc",
  "tree-sitter-tcl",
]

[workspace.package]
version = "2.0.0"
edition = "2024"
rust-version = "1.94"
license = "MPL-2.0"
repository = "https://github.com/dekobon/big-code-analysis"
authors = [
  "Calixte Denizet <cdenizet@mozilla.com>",
  "Elijah Zupancic <elijah@zupancic.name>",
]

# Pins below mirror enums/Cargo.toml. The `enums` crate is excluded from
# this workspace (see [workspace].exclude above) and cannot inherit these
# entries via `.workspace = true`, so any grammar bump here MUST be
# applied to enums/Cargo.toml in lockstep (see recreate-grammars.sh).
[workspace.dependencies]
tree-sitter = "=0.26.9"
tree-sitter-bash = "=0.25.1"
tree-sitter-c-sharp = "=0.23.5"
tree-sitter-elixir = "=0.3.5"
tree-sitter-go = "=0.25.0"
dekobon-tree-sitter-groovy = "=0.2.2"
tree-sitter-irules = "=0.1.1"
tree-sitter-java = "=0.23.5"
tree-sitter-javascript = "=0.25.0"
tree-sitter-kotlin-ng = "=1.1.0"
tree-sitter-lua = "=0.5.0"
tree-sitter-objc = "=3.0.2"
tree-sitter-perl = "=1.1.2"
tree-sitter-php = "=0.24.2"
tree-sitter-python = "=0.25.0"
tree-sitter-ruby = "=0.23.1"
tree-sitter-rust = "=0.24.2"
tree-sitter-typescript = "=0.23.2"
# Upstream community C++ grammar backing `LANG::Cpp` since #720 (the
# Mozilla fork `tree-sitter-mozcpp` moved to the opt-in `LANG::Mozcpp`).
# Pinned to mozcpp's exact base so the flip diffs only by the Gecko
# overlay (see #719). Mirror in enums/Cargo.toml.
tree-sitter-cpp = "=0.23.4"
# Upstream community C grammar backing the dedicated `LANG::C` since
# #721 (`.c` previously routed through the C++ grammar). Mirror in
# enums/Cargo.toml.
tree-sitter-c = "=0.24.2"
# Vendored grammar forks. Each is published under a `bca-tree-sitter-*`
# package name (so we do not collide with the upstream Mozilla / community
# crates on crates.io), but the produced Rust crate keeps its original
# `tree_sitter_<lang>` import path via `[lib] name = ...` in the leaf
# manifest. Cargo's `package = ...` alias here means consumer code that
# pulls in the dep as `tree-sitter-<lang>` continues to work unchanged.
# Rationale and the rejected alternatives live on the umbrella
# issue (dekobon/big-code-analysis#149); the operational details
# (publish order, first-bootstrap workflow) live in `RELEASING.md`.
tree-sitter-ccomment = { package = "bca-tree-sitter-ccomment", path = "./tree-sitter-ccomment", version = "=2.0.0" }
tree-sitter-mozcpp = { package = "bca-tree-sitter-mozcpp", path = "./tree-sitter-mozcpp", version = "=2.0.0" }
tree-sitter-mozjs = { package = "bca-tree-sitter-mozjs", path = "./tree-sitter-mozjs", version = "=2.0.0" }
tree-sitter-preproc = { package = "bca-tree-sitter-preproc", path = "./tree-sitter-preproc", version = "=2.0.0" }
tree-sitter-tcl = { package = "bca-tree-sitter-tcl", path = "./tree-sitter-tcl", version = "=2.0.0" }

# PyO3 powers the `big-code-analysis-py` cdylib. Pinned to a major
# series; bumping is a deliberate, separate change because the Bound
# API shape changed across minors.
pyo3 = "=0.29.0"
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
csv = "=1.4.0"
tempfile = "^3.0"

# Workspace-wide lint posture. The allow set is intentionally minimal
# — additional allows go at file or function level so the carve-out
# stays visible at the affected site rather than weakening the whole
# workspace.
[workspace.lints.rust]
missing_docs = "warn"

[workspace.lints.clippy]
pedantic = { level = "warn", priority = -1 }
module_name_repetitions = "allow"

[package]
name = "big-code-analysis"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true
documentation = "https://docs.rs/big-code-analysis/"
readme = "README.md"
keywords = ["metrics"]
description = "Tool to compute and export code metrics"
# Whitelist what ends up in the published .crate. Without this,
# cargo picks up the entire repo — including tests/repositories/
# (30k+ files of real-world corpora used for snapshot tests, ~130
# MiB compressed) and the mdBook source. None of that is needed by
# downstream consumers.
include = [
  "/src/**/*",
  "/Cargo.toml",
  "/README.md",
  "/LICENSE",
  "/CHANGELOG.md",
]

[dependencies]
aho-corasick = "^1.0"
# `bstr` carries the raw, possibly-non-UTF-8 bytes git stores for paths
# and author identities through the VCS pipeline; UTF-8 conversion is
# deferred to the output boundary with explicit error handling (per the
# path rules in AGENTS.md). Gated behind `vcs-git`.
bstr = { version = "^1.12", optional = true }
crossbeam = { version = "^0.8", features = ["crossbeam-channel"] }
csv.workspace = true
# `gix` is the pure-Rust git implementation backing the `vcs-git`
# backend (issue #328). The feature set is deliberately minimal:
# `max-performance-safe` (zlib-ng without `unsafe`), `blob-diff` (line
# churn), `mailmap` (identity canonicalisation), `revision` (rev-walk +
# revspec parsing), `blame` (per-function line→commit attribution,
# issue #329). `index` is listed defensively — `revision`/`mailmap`
# enable it transitively today, so it is pinned to survive a future gix
# refactor that decouples them (the walk itself is tree-to-tree and does
# not read the index/worktree). `sha1` (see below). Gated behind
# `vcs-git`.
gix = { version = "^0.83", default-features = false, features = [
  "max-performance-safe",
  "blob-diff",
  "mailmap",
  "revision",
  "blame",
  "index",
  # `sha1` enables `gix-hash/sha1`, which gates the `ObjectId` hash
  # kind. It is part of gix's default feature set; we pin
  # `default-features = false` for a minimal surface, so it must be
  # listed explicitly or `gix-hash::Kind` compiles with no variants.
  "sha1",
], optional = true }
num-derive = "^0.4"
num-format = "^0.4"
num-traits = "^0.2"
petgraph = "^0.8"
regex = "^1.7"
serde.workspace = true
# `float_roundtrip` makes serde_json's float *parser* bit-exact, so a value
# serialized and read back through `wire` (#532) round-trips losslessly
# (the default parser can be off by 1 ULP). Parse-only: serialized output
# is unchanged, so no snapshot churn.
#
# `preserve_order` is deliberately NOT enabled: it would flip every
# `Value::Object` workspace-wide to insertion order, perturbing the frozen
# code-climate / SARIF fingerprint contracts (#559). The text metric dump
# (#674) therefore renders fields in serde_json's default sorted-key order,
# which is deterministic and gives the uniform field set #674 requires.
serde_json = { workspace = true, features = ["float_roundtrip"] }
# Pinned to match the version already locked transitively via grammar
# crates (Cargo.lock). Used by the GitLab Code Climate writer to
# compute stable per-violation fingerprints.
sha2 = "=0.10.9"
# HMAC-SHA256 for the opt-in keyed author-identity hashing
# (`--author-hash-key`, #956). Shares the RustCrypto `digest` 0.10 trait
# family with `sha2`, so it adds no new transitive trait version.
hmac = "=0.12.1"
termcolor = "^1.2"

tree-sitter.workspace = true
# Grammar crates are gated behind per-language Cargo features (see
# `[features]` below). The default feature set `all-languages` enables
# every grammar so a bare `cargo build` matches the historical
# behaviour; consumers that only need a subset of languages can opt
# into a narrower set with `--no-default-features --features rust,…`.
tree-sitter-bash = { workspace = true, optional = true }
tree-sitter-c-sharp = { workspace = true, optional = true }
tree-sitter-elixir = { workspace = true, optional = true }
tree-sitter-go = { workspace = true, optional = true }
dekobon-tree-sitter-groovy = { workspace = true, optional = true }
tree-sitter-irules = { workspace = true, optional = true }
tree-sitter-java = { workspace = true, optional = true }
tree-sitter-javascript = { workspace = true, optional = true }
tree-sitter-kotlin-ng = { workspace = true, optional = true }
tree-sitter-lua = { workspace = true, optional = true }
tree-sitter-objc = { workspace = true, optional = true }
tree-sitter-perl = { workspace = true, optional = true }
tree-sitter-php = { workspace = true, optional = true }
tree-sitter-python = { workspace = true, optional = true }
tree-sitter-ruby = { workspace = true, optional = true }
tree-sitter-rust = { workspace = true, optional = true }
tree-sitter-typescript = { workspace = true, optional = true }
tree-sitter-ccomment = { workspace = true, optional = true }
tree-sitter-mozcpp = { workspace = true, optional = true }
tree-sitter-cpp = { workspace = true, optional = true }
tree-sitter-c = { workspace = true, optional = true }
tree-sitter-mozjs = { workspace = true, optional = true }
tree-sitter-preproc = { workspace = true, optional = true }
tree-sitter-tcl = { workspace = true, optional = true }

# Per-language Cargo features. `default = ["all-languages"]` keeps the
# library's historical "every grammar compiled in" behaviour for
# callers that take the crate as a black box (the CLI and web crates
# pin to `features = ["all-languages"]` for exactly this reason).
#
# Each language feature pulls in only the grammar crate(s) the
# matching `src/languages/language_*.rs` module needs at runtime — the
# token enums themselves carry no grammar-crate references and stay
# unconditionally compiled, so the `LANG` enum, the per-language
# `*Code` / `*Parser` tags, and the `Tree::new` / `analyze` dispatch
# surface remain identical across feature sets. Disabling a feature
# strips the grammar crate from the dep graph; calling into a
# disabled variant produces `Err(MetricsError::LanguageDisabled(LANG))`
# from every entry point that returns a `Result`.
#
# `cpp`, `c`, and `mozcpp` share the C-family helper crates
# (`tree-sitter-ccomment`, `tree-sitter-preproc`); listing the deps on
# each leaves their union enabled when any of those features is on.
[features]
default = ["all-languages"]
# Change-history (VCS) metrics (issue #328). `vcs` is the umbrella
# feature mirroring `all-languages`: it turns on every shipped backend.
# `vcs-git` is the one v1 backend (gitoxide). Future backends land as
# additional leaves (`vcs-hg`, `vcs-jj`, …) folded into the umbrella,
# so consumers that opt into `vcs` automatically pick them up without a
# manifest edit. The generic `src/vcs/` types are gated on `vcs-git`
# today because it is the only backend; the gate widens to
# `any(feature = "vcs-git", feature = "vcs-hg", …)` when a second
# backend lands.
vcs = ["vcs-git"]
vcs-git = ["dep:gix", "dep:bstr"]
all-languages = [
  "bash",
  "c",
  "cpp",
  "csharp",
  "elixir",
  "go",
  "groovy",
  "irules",
  "java",
  "javascript",
  "kotlin",
  "lua",
  "mozcpp",
  "mozjs",
  "objc",
  "perl",
  "php",
  "python",
  "ruby",
  "rust",
  "tcl",
  "typescript",
]
bash = ["dep:tree-sitter-bash"]
# Since #720 the `Cpp` LANG variant uses the upstream community
# `tree-sitter-cpp` grammar (see `get_language!(tree_sitter_cpp)` in
# `src/macros.rs`); the Mozilla fork moved to the opt-in `mozcpp`
# feature / `LANG::Mozcpp` below. The `Ccomment` and `Preproc` LANG
# variants are internal C-family helpers (comment stripping +
# preprocessor directives) shared by all three C-family features, so
# `cpp`, `c` (added in #721), and `mozcpp` each pull them. NOTE: the
# `cpp` dep set changed in #720 (`tree-sitter-mozcpp` → `tree-sitter-cpp`)
# — a SemVer break for `--no-default-features` consumers, recorded in
# CHANGELOG under the 2.0 milestone.
# Internal: the C-family comment-stripping (`Ccomment`) and
# preprocessor (`Preproc`) helper variants. Enabled automatically by
# every C-family language feature below (`cpp`, `c`, `mozcpp`) so those
# helper LANG variants are compiled in whenever any C-family grammar is.
# Not meant to be selected on its own — it pulls no user-facing language.
# (Before #721 these crates were listed directly on each C-family
# feature, but the `Ccomment` / `Preproc` LANG variants were gated on
# `cpp` alone, so a `--features c` / `--features mozcpp` build without
# `cpp` had the crates yet disabled the variants — breaking `strip-comments`
# / `preproc` for C-only and Mozcpp-only builds.)
c-family-helpers = ["dep:tree-sitter-ccomment", "dep:tree-sitter-preproc"]
cpp = ["dep:tree-sitter-cpp", "c-family-helpers"]
# Dedicated C language (`LANG::C`, upstream `tree-sitter-c`), added in
# #721. Owns `.c`; shares the C-family `ccomment` / `preproc` helpers.
c = ["dep:tree-sitter-c", "c-family-helpers"]
# Opt-in Mozilla/Gecko C++ dialect (vendored `tree-sitter-mozcpp` fork,
# `LANG::Mozcpp`). Owns zero file extensions — selected only explicitly
# (`--language mozcpp`, manifest, API), mirroring `mozjs` since #507.
# Enabling `mozcpp` alone therefore analyzes no files by extension.
mozcpp = ["dep:tree-sitter-mozcpp", "c-family-helpers"]
csharp = ["dep:tree-sitter-c-sharp"]
elixir = ["dep:tree-sitter-elixir"]
go = ["dep:tree-sitter-go"]
groovy = ["dep:dekobon-tree-sitter-groovy"]
irules = ["dep:tree-sitter-irules"]
java = ["dep:tree-sitter-java"]
javascript = ["dep:tree-sitter-javascript"]
kotlin = ["dep:tree-sitter-kotlin-ng"]
lua = ["dep:tree-sitter-lua"]
mozjs = ["dep:tree-sitter-mozjs"]
# Objective-C (`LANG::Objc`, upstream `tree-sitter-objc`). Owns `.m`;
# `.mm` Objective-C++ stays on `LANG::Cpp` (the ObjC grammar parses C
# but not the C++ half of `.mm` files) — see #724.
objc = ["dep:tree-sitter-objc"]
perl = ["dep:tree-sitter-perl"]
php = ["dep:tree-sitter-php"]
python = ["dep:tree-sitter-python"]
ruby = ["dep:tree-sitter-ruby"]
rust = ["dep:tree-sitter-rust"]
tcl = ["dep:tree-sitter-tcl"]
typescript = ["dep:tree-sitter-typescript"]

[lints]
workspace = true

[dev-dependencies]
insta = { version = "1.29.0", features = ["yaml", "json", "redactions"] }
jsonschema = "^0.46"
tempfile.workspace = true
pretty_assertions = "^1.3"
quick-xml = "^0.39"
# Test-only: the integration corpus harness and the concurrent_files
# unit tests walk fixture trees; production code no longer walks (#495).
walkdir = "^2.3"
# Test-only: the integration corpus harness builds include/exclude
# globsets to filter the resolved corpus file list; production code no
# longer filters via globsets (the CLI owns the walk seam) (#495).
globset = "^0.4"
# Test-only: the non-finite serialize-boundary test (#531) renders the
# crate-internal `NonFinite` newtype through every structured output
# format the project supports (JSON via serde_json above, plus these
# three) to pin the uniform null/omit policy across all of them. Versions
# mirror the `big-code-analysis-cli` pins; these crates already sit in the
# workspace graph, so listing them here adds no new resolved dependency.
serde_yaml = "^0.9"
ciborium = "^0.2"
toml = "^1.1"

[profile.dev.package.insta]
opt-level = 3

[profile.dev.package.similar]
opt-level = 3

[profile.release]
opt-level = 3
debug = "line-tables-only"
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = "unwind"
incremental = false
overflow-checks = false