Skip to content

feat(react-doctor): collapse non-verbose diagnostics to top 3 rules#170

Merged
aidenybai merged 6 commits intomainfrom
cursor/collapse-non-verbose-diagnostics-6934
May 8, 2026
Merged

feat(react-doctor): collapse non-verbose diagnostics to top 3 rules#170
aidenybai merged 6 commits intomainfrom
cursor/collapse-non-verbose-diagnostics-6934

Conversation

@aidenybai
Copy link
Copy Markdown
Member

@aidenybai aidenybai commented May 8, 2026

What

When react-doctor is run without --verbose, only print the 3 most important rule groups (sorted by severity, then by issue count). Collapse the remaining rule groups into a single summary line that points users at --verbose for full details.

In --verbose mode, the output is unchanged — every rule group with its per-file sites is still shown.

Before

  ⚠ Derived state in useEffect — compute during render instead (2)
  ⚠ Enforce a clickable non-interactive element has at least one keyboard event listener.
  ⚠ Static HTML elements with event handlers require a role.
  ⚠ forwardRef is no longer needed on React 19+ ...
  ⚠ useState "count" is mirrored from prop "name" via this effect ...
  ⚠ In-place mutation of useState value "items" via .push() ...
  ⚠ useState initialized from prop "name" ...

(All rule groups dumped at once — noisy on real codebases where dozens of rules can fire.)

After

  ⚠ Derived state in useEffect — compute during render instead (2)
  ⚠ Enforce a clickable non-interactive element has at least one keyboard event listener.
  ⚠ Static HTML elements with event handlers require a role.

  ⚠ 4 more warnings
    Run `npx react-doctor@latest . --verbose` to get all details

If hidden diagnostics include both severities, both counts are shown side by side, e.g. ✗ 2 more errors ⚠ 64 more warnings.

How

  • New constant MAX_RULE_GROUPS_SHOWN_NON_VERBOSE = 3 in constants.ts.
  • printDiagnostics slices the sorted rule groups when not verbose and delegates the remainder to a new printHiddenDiagnosticsSummary helper.
  • Renamed sortBySeveritysortByImportance and added a secondary sort by descending diagnostic count so the 3 visible groups are the most impactful within their severity tier.
  • Extracted summary text construction into utils/build-hidden-diagnostics-summary.ts so the pluralization and severity-ordering logic is unit-tested directly (no need to craft a fixture project that triggers 4+ rules).
  • Reused the shared buildDiagnostic helper from tests/regressions/_helpers.ts rather than redefining it locally.
  • Updated the --verbose flag description in both the CLI help text and README.md so users discover the new truncation behavior.

Verification

  • pnpm typecheck — pass
  • pnpm lint — 0 warnings, 0 errors
  • pnpm test623/623 pass (46 test files; +6 new unit tests for the summary builder)
  • Manual run against a fixture project that triggers 7 rule groups confirms the new output, and --help shows the updated flag description and wraps cleanly.
Open in Web Open in Cursor 

When --verbose is not set, only show the 3 most important rule groups
(sorted by severity, then by issue count). Collapse the remaining
diagnostics into a single summary line and point users at --verbose for
full details.

Closes the noisy default output when many rules fire — typical scans
hide dozens of repeated warnings behind a one-line hint instead of
flooding the terminal.

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-doctor-website Ready Ready Preview, Comment May 8, 2026 10:20am

@aidenybai aidenybai marked this pull request as ready for review May 8, 2026 10:08
cursoragent and others added 2 commits May 8, 2026 10:12
Move the hidden-diagnostics summary text construction (including
pluralization and severity ordering) into a pure utility so it can be
unit-tested without crafting a fixture project that triggers more than
three rule groups. scan.ts now wraps the returned parts with severity
colors and prints them.

Adds focused unit tests covering pluralization, single-severity
collapse, and mixed-severity ordering.

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Update the CLI flag description and README so users discover that
without --verbose, only the top 3 rule groups are shown and the
remainder collapses into a summary line.

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
cursoragent and others added 2 commits May 8, 2026 10:16
Drop the locally-redefined buildDiagnostic in
build-hidden-diagnostics-summary.test.ts and import the shared one
from tests/regressions/_helpers.ts (already used by
merge-and-filter-diagnostics.test.ts).

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
This reverts commit e52fd83.

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
@aidenybai aidenybai merged commit 97cb1bb into main May 8, 2026
6 checks passed
@aidenybai aidenybai deleted the cursor/collapse-non-verbose-diagnostics-6934 branch May 8, 2026 10:29
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.

2 participants