Skip to content

fix(prettier): read check results from stderr, never report a failing check as success - #117

Merged
kylehgc merged 3 commits into
developfrom
fix/prettier-check-stderr
Aug 19, 2026
Merged

kylehgc merged 3 commits into
developfrom
fix/prettier-check-stderr

Conversation

@kylehgc

@kylehgc kylehgc commented Aug 19, 2026 •

Copy link
Copy Markdown
Owner

Adopts upstream rtk-ai/rtk#3571 by @guyoron1. Closes #105.

Bug

Prettier >= 1.19 writes --check results ([warn] <file>) to stderr, but the filter ran with RunOptions::stdout_only() and additionally skipped any line containing [warn]. On a failing check the file list was discarded and the check-mode branch produced Prettier: All files formatted correctly beside exit code 1 — a truth inversion. On current develop the never_worse guard usually masked the false success down to a bare Checking formatting... (zero signal on stdout), with the raw [warn] lines only surviving via the runner's rtk-ai#3026 stderr passthrough.

Commits

Commit Author What
34946b7 guyoron1 (cherry-pick from upstream rtk-ai#3571, byte-identical) Filter combined stdout+stderr, recognize [warn] <file>, exit-aware guard: non-zero exit with no parsable file list passes real output through instead of claiming success
6f4d9f7 kylehgc (fork amendment) Strip ANSI before parsing: real prettier 3.x colors the [warn] marker even when piped, so the literal strip_prefix("[warn]") never matched real output and every failing check fell through to raw passthrough. One strip_ansi call at filter entry, matching the convention used by git/uv/binlog/glab filters. Regression test uses the captured real ANSI sequence.
59f2564 kylehgc (fork amendment, review round) Enforce one invariant at every call site: a run that signals failure — non-zero exit, or prettier's own Code style issues found verdict for callers with no exit code — never yields the success line. Plumbs result.exit_code through rtk format prettier (it was discarded at the dispatch), guards the previously unguarded All matched files use Prettier early return, covers the exit-code-less pipe path via the textual verdict, and adds the checklist-required count_tokens ≥60% savings test.

Repro (real binary, Windows)

bad.js = const x=1, prettier 3.x installed locally, rtk prettier --check bad.js.

Before (installed rtk, pre-fix develop):

=== stdout ===
Checking formatting...
=== stderr ===
[\x1b[33mwarn\x1b[39m] bad.js
[\x1b[33mwarn\x1b[39m] Code style issues found in the above file. Run Prettier with --write to fix.
exit=1

File list absent from stdout; summary claims nothing; the only signal is raw ANSI-laden stderr.

After (branch build):

=== stdout ===
Prettier: 1 files need formatting
1. bad.js
=== stderr ===
(empty)
exit=1

Success case unchanged: good.js → Prettier: All files formatted correctly, exit 0.

Call-site analysis

filter_prettier_output has three callers; after the review round each one enforces the failure invariant:

  • prettier_cmd::run — real exit code via run_filtered_with_exit (cherry-pick).
  • format_cmd::run (rtk format prettier) — had result.exit_code in hand and discarded it; now passes it through filter_prettier_output_with_exit (review round).
  • pipe_cmd::resolve_filter — exit code structurally unavailable (piped text); covered by the textual Code style issues found failure signal (review round).

Cluster / deliberately not fixed

  • Upstream #2410 (open, older) attacks the same false-success defect via a larger mode-routing redesign (Check/ListDifferent/Passthrough, +134/−16). Not adopted: the ticket names fix(prettier): never report a failed run as formatted rtk-ai/rtk#3571, which fixes the verified mechanism with a quarter of the blast radius. fix: avoid false prettier success output rtk-ai/rtk#2410's remaining value (arg-based mode routing, --list-different handling) is separable follow-up work.
  • Upstream keyword search for other prettier PRs found no further overlapping candidates ("probably none", not proof).
  • The extension allow-list if-cascade is untouched beyond deleting the [warn] skip — collapsing it into a const array is cosmetic and out of scope.

Quality gate

cargo fmt --all && cargo clippy --all-targets && cargo test --all

Clean: zero clippy warnings, 20 test suites all green (2711 unit tests incl. 12 prettier tests, 7 of them new), release build OK (x86_64-pc-windows-msvc host toolchain). Re-run in full after the review round.

guyoron1 and others added 3 commits August 19, 2026 10:08
… check as success

Prettier >= 1.19 writes its --check results ([warn] <file>) to stderr, but
the filter ran with RunOptions::stdout_only() and also explicitly skipped
any line containing [warn]. On a failing check the file list was silently
discarded and the filter produced 'Prettier: All files formatted correctly'
alongside exit code 1.

- filter the combined stdout+stderr stream
- recognize '[warn] <file>' lines as files needing formatting
- exit-aware guard: a check that exited non-zero with no parsable file list
  passes the real output through instead of claiming success
Prettier 3.x colors the [warn] marker even when its output is piped
(observed through rtk's own capture on Windows: '[\x1b[33mwarn\x1b[39m]'),
so the literal strip_prefix("[warn]") never matched real output and every
failing check fell through to the raw passthrough guard. Strip ANSI from
the whole input first, matching the strip_ansi convention used by other
filters (git, uv, binlog, glab).

Regression test uses the ANSI sequence captured from a real
'rtk prettier --check' run.

Co-Authored-By: Claude Fable 5 <[email protected]>
Review round: one invariant — a run that signals failure never yields the
success line. Failure is non-zero exit, or prettier's own 'Code style
issues found' verdict for callers that have no exit code to give.

- rtk format prettier had result.exit_code in hand and discarded it at the
  filter dispatch; pass it through filter_prettier_output_with_exit
- guard the previously unguarded 'All matched files use Prettier' early
  return (stray success summary beside a non-zero exit)
- the pipe path (no exit code, text only) is covered by the textual verdict
- add the checklist-required count_tokens >=60% savings test

Co-Authored-By: Claude Fable 5 <[email protected]>
@kylehgc

kylehgc commented Aug 19, 2026

Copy link
Copy Markdown
Owner Author

Review round (pre-merge)

Three passes ran on 34946b7 + 6f4d9f7: /code-review Standards + Spec axes, plus an uncontaminated run of upstream's own .claude/agents/code-reviewer.md prompt (diff + repo only, no author framing).

Findings and outcomes (all fixed in 59f2564):

  1. 🔴 (code-reviewer, Call-Site Analysis) format_cmd.rs:122 — rtk format prettier had result.exit_code in hand and discarded it at the filter dispatch, leaving the truth inversion alive on that path with unparsable file lists (e.g. .vue). Fixed: exit code plumbed through filter_prettier_output_with_exit (now pub(crate)); verified against the real binary (rtk format prettier --check bad.js → 1 files need formatting, exit 1).
  2. Spec axis — the All matched files use Prettier early return ignored exit_code, so a stray success summary beside a non-zero exit still claimed success. Fixed: guarded by the shared invariant; regression test added.
  3. 🟡 (code-reviewer) pipe path (pipe_cmd.rs:29) structurally has no exit code, defaulting to 0. Fixed via prettier's own textual verdict: failure = exit_code != 0 || output.contains("Code style issues found") — one invariant enforced at all three call sites.
  4. 🟡 (Standards + code-reviewer) missing checklist-required count_tokens ≥60% savings test. Added on a 100-file fixture (measured ~86% at that size; small outputs are guarded by never_worse at runtime).

Not acted on: the extension allow-list if-cascade shape (cosmetic, pre-existing, out of scope).

Gate re-run after fixes: fmt + clippy + test --all + release build, all clean (2711 unit tests, 12 prettier tests).

@kylehgc
kylehgc merged commit 3b5490c into develop Aug 19, 2026
5 checks passed
@kylehgc
kylehgc deleted the fix/prettier-check-stderr branch August 19, 2026 14:25
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.

adopt prettier: never report a failing check as success (upstream #3571)

2 participants