feat(cli): add --category filter and --score output - #147
Conversation
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.
📝 WalkthroughWalkthroughThis PR adds ChangesCategory and Score CLI flags
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/cli/test/resolve-args.test.ts (1)
152-198: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueLGTM!
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
📒 Files selected for processing (8)
.changeset/cli-category-score-flags.mddocs/src/content/docs/guides/cli.mddocs/src/content/docs/ja/guides/cli.mdpackages/cli/src/bin.tspackages/cli/src/index.tspackages/cli/src/resolve-args.tspackages/cli/test/resolve-args.test.tspackages/cli/test/run.test.ts
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--baselinepass too, so category-scoped PR gates stay consistent. Health becomes the weighted average of the categories present (existingcomputeHealthbehavior).--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 80works as a quiet gate. Passing--reporter/--jsonalongside warns on stderr that reporter output is suppressed.Notes
--weightsprecedent (case-insensitive, de-duplicated, unknown categories are a fatal exit-2 error listing the known set). A value-less--categoryis ignored like a value-less--weights; a value with zero valid entries (e.g.--category ,) is a fatal error.resolve-args.ts'sCATEGORIESlist remains the single source both--weightsand--categoryvalidate against.categoriesinput on the MCPanalyzetool —analyzeProjectalready accepts it, so that's a two-line follow-up if demand shows up.Changes
packages/cli/src/resolve-args.ts(parseCategories,--scorewiring),index.ts(options + rule filtering + score-only output path),bin.ts(flags + help)resolve-args.test.tsandrun.test.ts--categoryand--scoresections in the CLI guide (en/ja)svelte-vitalsVerification
pnpm typecheck,pnpm --filter svelte-vitals test(424 tests),pnpm lint— all green--scoreprints exactly one integer line (exit 1 with findings present, exit gate honors--min-health);--category seo --jsonreports only SEO-prefixed rule ids🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
--categoryflag to limit analysis to selected rule categories.--scoreflag to output only the overall Health score for scripting.Bug Fixes
Documentation