Skip to content

fix(prettier): never report a failed run as formatted - #3571

Open
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/prettier-check-stderr-false-success
Open

guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/prettier-check-stderr-false-success

Conversation

@guyoron1

@guyoron1 guyoron1 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

rtk prettier --check and rtk format prettier --check could report Prettier: All files formatted correctly for a run that had failed.

Reproduced with prettier 3.9.8:

  • a syntax error, or a pattern that matches no files (prettier exits 2), printed Prettier: All files formatted correctly on stdout, with the real [error] ... only on stderr
  • rtk format prettier --check bad.js (which filters stdout and stderr together) printed Prettier: All files formatted correctly with exit code 1, and for a syntax error lost every diagnostic

Fix: the prettier filter now takes the exit code and refuses to summarise a failed run (files_to_format.is_empty() && exit_code != 0 returns prettier's own text), [warn] <file> lines are recognised (needed for the rtk format path), and rtk format passes the exit code through. rtk prettier keeps RunOptions::stdout_only() and forwards stderr, so the contract pinned by tests/stderr_only_failure_test.rs still holds. A plain failing check through rtk prettier was already faithful on develop (raw stdout plus the forwarded [warn] lines) and is unchanged.

An earlier version of this PR filtered the combined stream inside rtk prettier. Since stdout-only stderr forwarding landed, that fails no_invented_stdout_diagnostic_when_the_tool_used_stderr, so it is reduced here to the part that still reproduces.

$ rtk prettier --check broken.js         # syntax error, exit 2
before: Prettier: All files formatted correctly
after : Checking formatting...
        Error occurred when checking code style in the above file.     (+ [error] ... forwarded on stderr)

$ rtk format prettier --check bad.js     # exit 1
before: All files formatted correctly
after : Prettier: 1 files need formatting / 1. src/bad.js

Overlaps #2410 (fixes #2395 with the same combined-stream idea; merged onto develop it fails that pinned test as well, and it does not pass the exit code from rtk format). Glad to coordinate on whichever the maintainers prefer.

Test plan

  • 3 original unit tests kept, 2 added
  • tests/prettier_failed_run_test.rs (4 tests; a stand-in prettier printing real 3.9.8 output on the right streams): 3 of the 4 fail on develop's code with the false success line
  • tests/stderr_only_failure_test.rs still passes (6 tests)
  • cargo fmt --all -- --check, cargo clippy --all-targets (0 warnings), cargo test --all (all pass)

The filter printed "All files formatted correctly" for any output that
had no parsable file list. Prettier >= 1.19 writes its --check findings
("[warn] <file>", "[error] ...") to stderr, so a syntax error or a
non-matching pattern (exit 2), and a failing check seen through
`rtk format`, had no list to parse and came out as formatted next to a
non-zero exit code.

- give the filter the exit code: a failing run with no parsable file
  list passes what prettier printed through instead of a success line
- recognise "[warn] <file>" lines, which `rtk format` hands the filter
  because it filters stdout and stderr together
- `rtk prettier` keeps filtering stdout only and forwarding stderr, so
  prettier's own diagnostics still reach the user untouched
@guyoron1 guyoron1 changed the title fix(prettier): read check results from stderr, never report a failing check as success fix(prettier): never report a failed run as formatted Sep 21, 2026
@guyoron1
guyoron1 force-pushed the fix/prettier-check-stderr-false-success branch from f2c1e48 to aa5f31e Compare September 21, 2026 12:20
@guyoron1

Copy link
Copy Markdown
Contributor Author

Reworked after the stdout-only stderr forwarding landed: rtk prettier still filters stdout only and forwards stderr (tests/stderr_only_failure_test.rs pins that), so this no longer merges the two streams. What still reproduces with prettier 3.9.8: a syntax error or a non-matching pattern (exit 2) prints "All files formatted correctly", and rtk format prettier --check reports a failing check as formatted and drops the diagnostics.

The filter now takes the exit code and refuses to summarise a failed run, and rtk format passes it. I've retitled the PR accordingly. This overlaps #2410, which currently fails tests/stderr_only_failure_test.rs and doesn't cover rtk format; glad to coordinate on whichever the maintainers prefer.

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.

bug: rtk prettier prints "All files formatted correctly" when the prettier binary is not installed (and for --version)

1 participant