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
12 changes: 7 additions & 5 deletions src/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ export function textReport(scan, { price, top, wrote }) {
const cats = Object.entries(t.byCategory).sort((a, b) => b[1].tokens - a[1].tokens);
L.push(c("90", " by category: ") + cats.map(([k, v]) => `${k} ${fmtTokens(v.tokens)}`).join(c("90", " · ")));
L.push("");
L.push(c("1", " Top offenders"));
for (const f of scan.files.filter((f) => f.trim).slice(0, top)) {
const tok = ("~" + fmtTokens(f.tokens)).padStart(7);
L.push(` ${c("33", tok)} ${c("90", usd(dollars(f.tokens, price)).padStart(7))} ${f.rel} ${c("90", "— " + f.reason)}`);
if (top > 0) {
L.push(c("1", " Top offenders"));
for (const f of scan.files.filter((f) => f.trim).slice(0, top)) {
const tok = ("~" + fmtTokens(f.tokens)).padStart(7);
L.push(` ${c("33", tok)} ${c("90", usd(dollars(f.tokens, price)).padStart(7))} ${f.rel} ${c("90", "— " + f.reason)}`);
}
}
L.push("");
if (wrote && wrote.length) {
Expand All @@ -57,4 +59,4 @@ export function jsonReport(scan, { price, wrote }) {
offenders: scan.files.filter((f) => f.trim).map((f) => ({ path: f.rel, tokens: f.tokens, category: f.category, reason: f.reason })),
wrote: wrote || [],
}, null, 2);
}
}
9 changes: 9 additions & 0 deletions test/ctxtrim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { dirname, join } from "node:path";
import { scanRepo, estimateTokens } from "../src/scan.js";
import { classify, classifyPath } from "../src/classify.js";
import { merge, block } from "../src/ignore.js";
import { textReport } from "../src/report.js";

const repo = join(dirname(fileURLToPath(import.meta.url)), "fixtures", "sample-repo");
const cli = join(dirname(fileURLToPath(import.meta.url)), "..", "bin", "ctxtrim.js");
Expand Down Expand Up @@ -185,3 +186,11 @@ test("unknown --targets values fail before writing ignore files", (t) => {
assert.equal(existsSync(join(root, ".aiexclude")), false);
assert.equal(existsSync(join(root, ".aiignore")), false);
});
test("textReport with top: 0 omits Top offenders header", () => {
const scan = scanRepo(repo);
const out = textReport(scan, { price: 3, top: 0 });
assert.ok(
!out.includes("Top offenders"),
"should not show Top offenders header when top is 0",
);
});
Loading