Skip to content

feat(cli): add --category filter and --score output - #147

Merged
oekazuma merged 1 commit into
mainfrom
advisor/018-cli-category-score-flags
Jul 8, 2026
Merged

oekazuma merged 1 commit into
mainfrom
advisor/018-cli-category-score-flags

Conversation

@oekazuma

@oekazuma oekazuma commented Jul 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements plan plans/018-cli-category-score-flags.md — two small quality-of-life flags:

  • --category <cats> — restrict analysis to whole categories (seo | performance | correctness | security | architecture, comma-separated, case-insensitive). Previously "just check SEO" meant enumerating 30 rule ids with --rules. Applied as an intersection after --rules/--ignore/config selection, and threaded into the --baseline pass too, so category-scoped PR gates stay consistent. Health becomes the weighted average of the categories present (existing computeHealth behavior).
  • --score — print only the combined Health score (one integer line on stdout, spinner and reporter output suppressed) for scripts and shell prompts. Exit-code semantics are unchanged, so --score --min-health 80 works as a quiet gate. Passing --reporter/--json alongside warns on stderr that reporter output is suppressed.

Notes

  • Validation mirrors the --weights precedent (case-insensitive, de-duplicated, unknown categories are a fatal exit-2 error listing the known set). A value-less --category is ignored like a value-less --weights; a value with zero valid entries (e.g. --category ,) is a fatal error.
  • resolve-args.ts's CATEGORIES list remains the single source both --weights and --category validate against.
  • Out of scope (deliberately): a categories input on the MCP analyze tool — analyzeProject already accepts it, so that's a two-line follow-up if demand shows up.

Changes

  • packages/cli/src/resolve-args.ts (parseCategories, --score wiring), index.ts (options + rule filtering + score-only output path), bin.ts (flags + help)
  • 12 new test cases across resolve-args.test.ts and run.test.ts
  • Docs: --category and --score sections in the CLI guide (en/ja)
  • Changeset: minor for svelte-vitals

Verification

  • pnpm typecheck, pnpm --filter svelte-vitals test (424 tests), pnpm lint — all green
  • Live checks on the test fixture: --score prints exactly one integer line (exit 1 with findings present, exit gate honors --min-health); --category seo --json reports only SEO-prefixed rule ids

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a --category flag to limit analysis to selected rule categories.
    • Added a --score flag to output only the overall Health score for scripting.
  • Bug Fixes

    • Improved filtering so category-based analysis respects existing rule selection and configuration.
    • Suppresses reporter output when score-only mode is used, with a warning if combined with other output formats.
  • Documentation

    • Updated CLI docs in English and Japanese to describe the new flags and behavior.

Add --category <cats> to restrict analysis to rules in the given
categories (intersects with --rules/--ignore/config-file selection), and
--score to print only the combined Health score to stdout, suppressing
reporter output — useful for shell prompts/scripts and for gating with
--min-health without parsing JSON.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds --category and --score CLI flags to the analysis tool. --category restricts rule execution and Health score weighting to specified categories, intersecting with --rules/--ignore; --score prints only the combined Health score, suppressing reporter output. Includes parsing, validation, tests, and docs.

Changes

Category and Score CLI flags

Layer / File(s) Summary
CLI help text and parser config
packages/cli/src/bin.ts
Adds --category <cats> and --score help entries and extends mri boolean/string option lists.
Argument resolution and validation
packages/cli/src/resolve-args.ts, packages/cli/test/resolve-args.test.ts
Adds parseCategories to validate/normalize category input, wires categories into resolved options, warns when --score conflicts with --json/--reporter, and adds corresponding tests.
Category filtering and score-only reporting
packages/cli/src/index.ts, packages/cli/test/run.test.ts
Adds categories to RunOptions/AnalyzeOptions, filters selected rules by category in analyzeProject, threads categories into primary/baseline analysis, and reorganizes run() so --score short-circuits reporter output; adds tests for both flags.
Documentation and changeset
.changeset/cli-category-score-flags.md, docs/src/content/docs/guides/cli.md, docs/src/content/docs/ja/guides/cli.md
Documents --category and --score behavior, health score weighting, and error handling in English and Japanese CLI references, with a changeset entry.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant bin as CLI (bin.ts)
  participant resolveArgs as resolveArgs()
  participant run as run()
  participant analyzeProject as analyzeProject()
  participant Reporter

  User->>bin: run CLI with --category, --score
  bin->>resolveArgs: resolveArgs(argv)
  resolveArgs->>resolveArgs: parseCategories, validate categories
  resolveArgs->>resolveArgs: warn if score + json/reporter
  resolveArgs-->>bin: options { categories, score }
  bin->>run: run(options)
  run->>analyzeProject: analyzeProject(opts with categories)
  analyzeProject->>analyzeProject: filter rules by category
  analyzeProject-->>run: findings + Health score
  alt score enabled
    run-->>User: print numeric Health score to stdout
  else
    run->>Reporter: output findings via selected reporter
    Reporter-->>User: reporter output
  end
Loading

Possibly related PRs

  • oekazuma/svelte-vitals#40: The --score flag directly relies on the combined Health scoring implementation introduced in this related PR.
  • oekazuma/svelte-vitals#129: Both PRs modify analyzeProject's category/scoring behavior, with the related PR adding --weights support that interacts with category-based health scoring.
  • oekazuma/svelte-vitals#42: The --category plumbing depends on the Category type model that this related PR modifies by narrowing valid categories.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main CLI change: adding --category filtering and --score output.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@oekazuma

oekazuma commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/cli/test/resolve-args.test.ts (1)

152-198: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

LGTM!

Consider adding a test for mixed valid and invalid categories (e.g. --category seo,bogus) to confirm the error remains fatal even when some entries are valid.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/test/resolve-args.test.ts` around lines 152 - 198, Add a test in
resolve-args.test.ts around resolve() / --category handling to cover mixed valid
and invalid values like seo,bogus; the current category parsing tests only check
all-valid and all-invalid cases. Assert that resolve('--category', 'seo,bogus')
still returns options as null and emits the fatal unknown-category error in the
same way as the existing bogus case, even when some entries are valid.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/cli/test/resolve-args.test.ts`:
- Around line 152-198: Add a test in resolve-args.test.ts around resolve() /
--category handling to cover mixed valid and invalid values like seo,bogus; the
current category parsing tests only check all-valid and all-invalid cases.
Assert that resolve('--category', 'seo,bogus') still returns options as null and
emits the fatal unknown-category error in the same way as the existing bogus
case, even when some entries are valid.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d0d92188-214a-4bcf-a57c-71171b422036

📥 Commits

Reviewing files that changed from the base of the PR and between d56e1d4 and d9cb3ba.

📒 Files selected for processing (8)
  • .changeset/cli-category-score-flags.md
  • docs/src/content/docs/guides/cli.md
  • docs/src/content/docs/ja/guides/cli.md
  • packages/cli/src/bin.ts
  • packages/cli/src/index.ts
  • packages/cli/src/resolve-args.ts
  • packages/cli/test/resolve-args.test.ts
  • packages/cli/test/run.test.ts

@oekazuma
oekazuma merged commit dad2cce into main Jul 8, 2026
7 checks passed
@oekazuma
oekazuma deleted the advisor/018-cli-category-score-flags branch July 8, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant