Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions .bca-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -601,24 +601,12 @@ qualified = "generate_html_report_with_vcs"
metric = "nargs"
value = 6.0

[[entry]]
path = "big-code-analysis-cli/src/html_report.rs"
qualified = "write_table_classed"
metric = "nargs"
value = 5.0

[[entry]]
path = "big-code-analysis-cli/src/html_report.rs"
qualified = "write_table_classed_with_tooltips"
metric = "nargs"
value = 7.0

[[entry]]
path = "big-code-analysis-cli/src/html_report.rs"
qualified = "write_table_core"
metric = "nargs"
value = 7.0

[[entry]]
path = "big-code-analysis-cli/src/html_report.rs"
qualified = "write_table_head"
Expand Down Expand Up @@ -653,7 +641,7 @@ value = 49443.19551903411
path = "big-code-analysis-cli/src/markdown_report.rs"
qualified = "<file>"
metric = "loc.ploc"
value = 633.0
value = 583.0

[[entry]]
path = "big-code-analysis-cli/src/markdown_report.rs"
Expand Down Expand Up @@ -683,7 +671,7 @@ value = 6.0
path = "big-code-analysis-cli/src/markdown_report/hotspot.rs"
qualified = "<file>"
metric = "loc.ploc"
value = 694.0
value = 701.0

[[entry]]
path = "big-code-analysis-cli/src/markdown_report/hotspot.rs"
Expand Down
29 changes: 25 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ jobs:
- uses: taiki-e/install-action@86f7a0ffb25f40114606501a311ebcfaf882ea32 # v2.88.0
with:
tool: cargo-nextest
# Node is installed before the Rust tests, not only for the agent
# hook tests below: `html_report::tests::inline_sort_script_behaves_
# under_a_dom_stub` runs the report's inline sort script under Node
# and, with `CI` set, fails rather than skips when Node is absent —
# so the pinned runtime, not whatever the image ships, is what it
# sees.
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
check-latest: true
# nextest runs the lib / bins / integration tests and writes the JUnit
# report to target/nextest/ci/junit.xml (see .config/nextest.toml). It
# does not run doctests — those are covered by the next step.
Expand All @@ -287,10 +297,6 @@ jobs:
# exercising the workspace's documentation examples.
- name: cargo test --doc
run: cargo test --doc --all-features --workspace --locked
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
check-latest: true
- name: Build analyzer for plugin integration tests
run: cargo build -p big-code-analysis-cli --all-features --locked
- name: Agent hook tests with the checkout analyzer
Expand Down Expand Up @@ -408,6 +414,13 @@ jobs:
- uses: taiki-e/install-action@86f7a0ffb25f40114606501a311ebcfaf882ea32 # v2.88.0
with:
tool: cargo-nextest@0.9.146,cargo-llvm-cov@0.9.1
# The instrumented run below is the same test set as the `test` job,
# including the Node-driven inline-sort-script test, which fails
# under `CI` when Node is missing rather than skipping.
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
check-latest: true
- name: Record coverage provenance
run: |
{
Expand Down Expand Up @@ -622,6 +635,14 @@ jobs:
- uses: taiki-e/install-action@86f7a0ffb25f40114606501a311ebcfaf882ea32 # v2.88.0
with:
tool: cargo-nextest
# The two `(cli)` legs run the CLI crate's lib tests, one of which
# drives the report's inline sort script under Node and fails under
# `CI` when Node is absent — on every leg, so the verdict never
# depends on what the runner image happens to ship.
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
check-latest: true
# The one thing a partial feature set breaks that the clippy run
# above cannot see (#1472): a test gated on the union of its rows
# must be *absent* when none of those features is enabled, not
Expand Down
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ repos:
- id: test
name: test
language: system
files: '\.rs$'
# The `.mjs` is the DOM-stub harness a Rust unit test drives, so an
# edit to it is an edit to that test.
files: '(\.rs|big-code-analysis-cli/tests/fixtures/.*\.mjs)$'
entry: cargo test
pass_filenames: false

Expand Down
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ for historical reference.

### Changed

- **The HTML report's column headers are native sort buttons.** Each
header's label is now a `<button>` inside the `<th>` — the WAI-ARIA
sortable-table shape — so it is announced as a control, sorts on
Enter / Space through the browser's own activation, and needs no
`tabindex` or key handling of our own; `aria-sort` stays on the
cell and the sort arrow is hidden from assistive technology so it
never joins the button's name. The documentation link that was the
label itself is a small `?` after it, so clicking the label sorts
and clicking the glyph navigates; the button carries the cell's
padding, so the rest of the header still sorts as before. Every
`<th>` carries `scope="col"`, and the "click a column header" hint
now appears on the standalone `bca vcs --format html` page as well
as on `bca report html`.

- **`roles/mod.rs` no longer allows `dead_code` module-wide** (#1792).
The allow was recorded as hiding 58 unread macro-emitted items; with
it overridden (`RUSTFLAGS=--force-warn dead_code`) the library
Expand Down Expand Up @@ -66,6 +80,44 @@ for historical reference.
`utils/check-tools.sh --release-only` asks the script itself, names
the binary it judged when it refuses one, and the install hints name
CI's pin, `cargo-deny@0.20.2`.
- **`bca report` renders its tables and notes correctly in both formats.**
A review of the published report found: HTML numeric column headers were
left-aligned over right-aligned cells (only `td.numeric` carried the
rule); notes shared with the Markdown renderer showed literal backticks
in HTML ("the \`bca.toml\` \`[thresholds]\` table"); the change-history
`Hotspot` column rendered `748436.0` beside thousands-separated
siblings; the Markdown pointer under that table told a `bca report`
reader to re-run with `--format csv`, which `report` rejects (it is
`bca vcs --format csv`); the HTML risk-heat bands graded rows against
the rendered top-N rather than every ranked file, so `--top 1` painted
the repository's riskiest file green; the sortable-table script sent a
blank numeric cell *first* on a descending sort; and the `Average CC`
note's `|`-joined fields read as an orphaned table row (rumdl 0.2.2's
MD075, four hits on the published report) directly under the
cyclomatic table. Headers are now
focusable (`tabindex`) and sort on Enter / Space, so the sort is
reachable without a mouse.
- **GFM table cells escape Markdown and HTML metacharacters.** A path
such as `a<img src=x onerror=…>.py` became an element under a
non-sanitising renderer, `a&amp;b.py` displayed as `a&b.py`, and
`__init__.py` rendered as bold `init.py`. `escape_gfm_cell` (shared by
the report, `check`'s `--summary-file` step-summary digest and
`exemptions`) now backslash-escapes `` < & ` * _ ~ [ ] `` alongside the
existing `\` and `|`; GFM renders each as the literal character. The
legend definitions, which are crate-authored prose, are no longer
passed through it.
- **The report legends say what the columns measure.** The Per-language
overview's `Files` / `Functions` / `Avg MI` / `Avg CC` / `Avg Cognitive`
were defined only as HTML hover tooltips, so a Markdown reader meeting
a negative `Avg MI` (the SLOC-weighted *unclamped* average of #725) had
only the per-file `MI` entry's "clamped to 0–100" to go on; both legends
now carry them, the `MI` entry points at the unclamped average, and
`Avg CC` names its population (every function, suppression ignored,
unlike the CC note's `Average CC`). `Exits`, `Methods`, `WMC`, `NPA`
and `NPM` said "out of the function" / "declared on the class" while
the columns are subtree sums (`nexits_sum`, `nom.total`, …, the
deliberate #709 accessor split); and `Comments` said "lines that are
entirely comment" while `cloc()` counts trailing comments too.

## [2.5.1] - 2026-11-06

Expand Down
36 changes: 24 additions & 12 deletions big-code-analysis-book/src/commands/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ summaries, hotspot membership, and captions, so both formats report
identical numbers.

Both formats carry a **Legend** that defines every metric column
abbreviation (`CC`, `MI`, `ABC`, `WMC`, and so on) plus the
global-header stats (`PLOC`, `Comments`, `Comment ratio`). It is a
abbreviation (`CC`, `MI`, `ABC`, `WMC`, and so on), the
global-header stats (`PLOC`, `Comments`, `Comment ratio`), and the
Per-language overview's columns (`Files`, `Functions`, `Avg MI`,
`Avg CC`, `Avg Cognitive`) — `Avg MI` in particular, since it is the
unclamped, SLOC-weighted average and can read negative where the
per-file `MI` column saturates at 0. It is a
`## Legend` section in Markdown (its own outline entry, not nested under
the last language) and an expanded (`<details open>`) block in HTML, so
it survives print, mobile, and screen readers as well as a hover
Expand Down Expand Up @@ -245,16 +249,24 @@ bca report --paths /path/to/project \
html --top 10 --output report.html
```

Click any column header to sort that table ascending, click again to
toggle descending. Each table sorts independently. Empty cells (where a
metric was not measured) sort as if they were positive infinity, which
keeps "no data" rows out of the visible top of a hotspot.

Hover (or keyboard-focus, where the browser supports it) any metric
column header (`SLOC`, `MI`, `CC`, `ABC`, `WMC`, `NPA`, `NPM`,
`Exits`, and the rest) for a one-sentence plain-English explanation of
the metric. The tooltip is delivered through the native HTML `title`
attribute, so it works offline with no JavaScript.
Every column header is a native button: click its label — or Tab to
it and press Enter or Space — to sort that table ascending, and again
to toggle descending. Each table sorts independently. Empty cells
(where a metric was not measured) sort last in both directions, so
"no data" rows never surface at the top of a hotspot. The header
follows the WAI-ARIA sortable-table pattern — the label is the
`<button>`, the cell carries `aria-sort`, and the sort arrow is hidden
from assistive technology — so a screen reader announces the control
as a button and the column's current order. The button fills the
header cell, so clicking anywhere in it sorts; the `?` beside a metric
label is the one thing in a header that does not.

Hover any metric column header (`SLOC`, `MI`, `CC`, `ABC`, `WMC`,
`NPA`, `NPM`, `Exits`, and the rest) for a one-sentence plain-English
explanation of the metric. The tooltip is delivered through the native
HTML `title` attribute, so it works offline with no JavaScript. The
small `?` after a metric's label is the link to that metric's chapter
in this book.

Because `title` tooltips are hover-only (invisible in print, on
mobile, and to screen readers), the page also ends with a visible,
Expand Down
3 changes: 2 additions & 1 deletion big-code-analysis-book/src/commands/vcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ bca vcs --top 50 --format markdown --output vcs.md
```

`--format html` produces a self-contained, sortable page styled like
`bca report html` (click any column header to re-sort); `--format
`bca report html` (click any column header's label, or Tab to it and
press Enter, to re-sort); `--format
markdown` produces the same ranked table as
[GitHub-Flavored Markdown](https://github.github.com/gfm/). Both render
every signal column, the same data the structured formats carry. The
Expand Down
72 changes: 53 additions & 19 deletions big-code-analysis-cli/src/check_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,28 +559,44 @@ fn write_top_offenders(out: &mut String, pairs: &[(Violation, Option<Coverage>)]
}
}

/// Escape `\`, `|`, and newlines in a GFM table cell. `|` is the
/// column separator; `\` must be escaped first so that escaping `|`
/// to `\|` doesn't accidentally interact with a literal backslash
/// already present in the cell (a path `a\|b` would otherwise
/// produce `a\\|b`, which GFM renders as `a\` followed by a column
/// break rather than the literal `a\|b`). Newlines and carriage
/// returns are collapsed to a single space — multi-line cells
/// would break the table layout entirely.
/// Escape a GFM table cell so its text renders verbatim. `|` is the
/// column separator, and a literal `\` is escaped too so that a path
/// `a\|b` renders as itself rather than as `a\` followed by a column
/// break — one backslash per metacharacter, never two, so a `\` already
/// in the cell can never pair with the one added for a following `|`.
/// Newlines and carriage returns are collapsed to a single space —
/// multi-line cells would break the table layout entirely.
///
/// `markdown_report::escape_cell` delegates here so the two GFM-table
/// emitters in this crate share one escaping policy (see issue #439).
/// The remaining escapes keep a path's *identity* intact in the rendered
/// output: `<` opens raw HTML (`a<img src=x onerror=…>.py` became an
/// element under a non-sanitising renderer), `&` starts an entity
/// (`a&amp;b.py` displayed as `a&b.py`), and `` ` `` / `*` / `_` / `~` /
/// `[` / `]` open code spans, emphasis, strikethrough and links
/// (`__init__.py` rendered as bold `init.py`). GFM honours a backslash
/// before any ASCII punctuation, so each renders as the literal character.
///
/// `markdown_report::escape_cell`, `vcs_report` and `exemptions` all
/// route here so every GFM-table emitter in this crate shares one
/// escaping policy (see issue #439).
pub(crate) fn escape_gfm_cell(s: &str) -> String {
let mut out = String::with_capacity(s.len());
let needs_escape = |ch: char| {
matches!(
ch,
'\\' | '|' | '<' | '&' | '`' | '*' | '_' | '~' | '[' | ']'
)
};
// Size for every escape up front: `_` is in most identifiers and
// paths, so the plain `s.len()` guess reallocated on most cells.
let escapes = s.chars().filter(|&ch| needs_escape(ch)).count();
let mut out = String::with_capacity(s.len() + escapes);
for ch in s.chars() {
match ch {
// Escape `\` FIRST so the subsequent `|` → `\|` rule
// doesn't conflict with a literal backslash already in
// the cell.
'\\' => out.push_str("\\\\"),
'|' => out.push_str("\\|"),
'\n' | '\r' => out.push(' '),
_ => out.push(ch),
if needs_escape(ch) {
out.push('\\');
out.push(ch);
} else if matches!(ch, '\n' | '\r') {
out.push(' ');
} else {
out.push(ch);
}
}
out
Expand Down Expand Up @@ -1363,4 +1379,22 @@ mod tests {
assert_eq!(escape_gfm_cell("a\\b"), "a\\\\b");
assert_eq!(escape_gfm_cell("a\\|b"), "a\\\\\\|b");
}

/// A path's Markdown and HTML metacharacters must render as the
/// literal path: unescaped, `<img …>` became an element under a
/// non-sanitising GFM renderer, `&amp;` collapsed to `&`, and
/// `__init__.py` rendered as bold `init.py`.
#[test]
fn escape_gfm_cell_neutralises_markup_in_paths() {
assert_eq!(
escape_gfm_cell("a<img src=x onerror=alert(1)>.py"),
"a\\<img src=x onerror=alert(1)>.py"
);
assert_eq!(escape_gfm_cell("a&amp;b.py"), "a\\&amp;b.py");
assert_eq!(escape_gfm_cell("__init__.py"), "\\_\\_init\\_\\_.py");
assert_eq!(escape_gfm_cell("x*y~z`w[v].rs"), "x\\*y\\~z\\`w\\[v\\].rs");
// Ordinary paths are untouched: no escape is spent on a `.`, `/`,
// `-` or `#`, which GFM renders literally in a cell.
assert_eq!(escape_gfm_cell("src/a-b.c#1.rs"), "src/a-b.c#1.rs");
}
}
4 changes: 3 additions & 1 deletion big-code-analysis-cli/src/exemptions_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ fn a_lineless_baseline_entry_drops_the_line_in_every_format() {
let md = report
.render(OutputFormat::Markdown, "")
.expect("markdown render");
// The symbol's underscores are escaped so GFM renders them rather
// than reading `_one` as an emphasis opener.
assert!(
md.contains("| src/lonely.rs | - | only_one | cognitive | 21 |"),
md.contains("| src/lonely.rs | - | only\\_one | cognitive | 21 |"),
"got: {md}"
);

Expand Down
Loading
Loading