Skip to content

Commit 27e7ea7

Browse files
committed
feat(scripts): add --show-all flag to display all types in Markdown report
- Update `formatSummary` to support `showAll` parameter for flexible filtering. - Enhance CLI argument parsing to handle the `--show-all` flag. - Modify default behavior to filter types without `never_seen` items unless `--show-all` is set.
1 parent 408dd63 commit 27e7ea7

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

scripts/find-unused-type-properties.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ import { fileURLToPath } from "node:url";
4141
* quality
4242
* - `ItemBasicInfo` suppression is heuristic and tied to the explicit
4343
* `ITEM_TYPE_NAMES` list below
44+
* - the default human-readable output is intentionally filtered to only show
45+
* types with at least one `never_seen` property; use `--show-all` to include
46+
* clean sections too
4447
*/
4548
type JSONSchema = TJS.Definition & {
4649
$ref?: string;
@@ -490,7 +493,7 @@ function buildReport(): FinalReport {
490493
/**
491494
* Render a human-readable Markdown report.
492495
*/
493-
function formatSummary(report: FinalReport): string {
496+
function formatSummary(report: FinalReport, showAll: boolean): string {
494497
const lines: string[] = [];
495498

496499
lines.push("# Unused SupportedTypes Property Report");
@@ -526,15 +529,19 @@ function formatSummary(report: FinalReport): string {
526529
lines.push(`- never seen: ${report.totals.neverObserved}`);
527530

528531
for (const typeReport of report.perType) {
532+
const neverSeen = typeReport.entries.filter(
533+
(entry) => entry.status === "never_seen",
534+
);
535+
if (!showAll && neverSeen.length === 0) {
536+
continue;
537+
}
538+
529539
lines.push("");
530540
lines.push(`## ${typeReport.typeName}`);
531541
lines.push(
532542
`objects=${typeReport.objectCount}, declared=${typeReport.declaredPathCount}, raw=${typeReport.usedInRaw}, flattened_only=${typeReport.usedOnlyAfterFlattening}, never_seen=${typeReport.neverObserved}`,
533543
);
534544

535-
const neverSeen = typeReport.entries.filter(
536-
(entry) => entry.status === "never_seen",
537-
);
538545
if (neverSeen.length === 0) {
539546
lines.push("- no never-seen declared paths");
540547
continue;
@@ -555,16 +562,22 @@ function formatSummary(report: FinalReport): string {
555562
function parseArgs(argv: string[]): {
556563
outputPath?: string;
557564
json: boolean;
565+
showAll: boolean;
558566
} {
559567
let outputPath: string | undefined;
560568
let json = false;
569+
let showAll = false;
561570

562571
for (let index = 0; index < argv.length; index += 1) {
563572
const arg = argv[index];
564573
if (arg === "--json") {
565574
json = true;
566575
continue;
567576
}
577+
if (arg === "--show-all") {
578+
showAll = true;
579+
continue;
580+
}
568581
if (arg === "--output") {
569582
const candidate = argv[index + 1];
570583
if (!candidate || candidate.startsWith("-")) {
@@ -575,18 +588,18 @@ function parseArgs(argv: string[]): {
575588
}
576589
}
577590

578-
return { outputPath, json };
591+
return { outputPath, json, showAll };
579592
}
580593

581594
/**
582595
* Entry point for CLI execution.
583596
*/
584597
function main(): void {
585-
const { outputPath, json } = parseArgs(process.argv.slice(2));
598+
const { outputPath, json, showAll } = parseArgs(process.argv.slice(2));
586599
const report = buildReport();
587600
const rendered = json
588601
? JSON.stringify(report, null, 2)
589-
: formatSummary(report);
602+
: formatSummary(report, showAll);
590603

591604
if (outputPath) {
592605
const absoluteOutputPath = path.resolve(process.cwd(), outputPath);

0 commit comments

Comments
 (0)