Suppress diagnostic output for format --check --slient#17736
Suppress diagnostic output for format --check --slient#17736ntBre merged 9 commits intoastral-sh:mainfrom
format --check --slient#17736Conversation
|
|
I'll fix the formatting later |
|
Looks good. Could you add a test plan demonstrating that the fix works as expected? |
Sure, I will add test |
ntBre
left a comment
There was a problem hiding this comment.
Thanks for working on this! I resolved the merge conflicts and also tested the current state of this PR, and along the lines of Micha's comment above, I think we've suppressed too many diagnostics. I put together this table comparing the behavior of ruff check and ruff format --check both on the main branch and on this PR:
| check | format --check (main) | format --check (pr) | |
|---|---|---|---|
| default | diagnostics + summary | diagnostics + summary | diagnostics + summary |
| quiet | diagnostics | diagnostics | exit code |
| silent | exit code | diagnostics | exit code |
I used this very short file for testing:
import math(Note the two spaces, which causes the format --check to fail as well as the linter to emit an unused import diagnostic)
The issue reported in #17729 is the bold entry in the third column, where format --check --silent prints diagnostics, unlike check --silent, which exits silently. The issue remaining on this PR is in bold in the fourth column: we now exit silently even when --quiet is used rather than --silent.
We should instead match the behavior of the ruff check subcommand.
Some CLI output
# This PR
❯ ~/astral/worktrees/ruff1/target/debug/ruff format --check --no-cache try.py --preview
unformatted: File would be reformatted
--> try.py:1:1
- import math
1 + import math
1 file would be reformatted
/tmp/tmp.K9wYNh2q4X via 🐍 v3.14.2
❯ ~/astral/worktrees/ruff1/target/debug/ruff format --check --no-cache try.py --preview --quiet
/tmp/tmp.K9wYNh2q4X via 🐍 v3.14.2
❯ ~/astral/worktrees/ruff1/target/debug/ruff format --check --no-cache try.py --preview --silent
# ruff check
❯ ruff check --no-cache try.py --preview
F401 [*] `math` imported but unused
--> try.py:1:9
|
1 | import math
| ^^^^
|
help: Remove unused import: `math`
- import math
Found 1 error.
[*] 1 fixable with the `--fix` option.
/tmp/tmp.K9wYNh2q4X via 🐍 v3.14.2
❯ ruff check --no-cache try.py --preview --quiet
F401 [*] `math` imported but unused
--> try.py:1:9
|
1 | import math
| ^^^^
|
help: Remove unused import: `math`
- import math
/tmp/tmp.K9wYNh2q4X via 🐍 v3.14.2
❯ ruff check --no-cache try.py --preview --silent
Sorry for not following up on this PR recently. Thank you very much for your help! I’ll make the necessary updates as soon as possible based on the current feedback. |
|
Thanks for the detailed review and the helpful comparison table! I've updated the fix to properly match the behavior of this table:
Hopefully this is correct now. Thanks again for your help and patience |
ntBre
left a comment
There was a problem hiding this comment.
Thank you! The new tests look great!
ruff] Fix For format --check --slient not respect --silent flagformat --check --slient
Summary
FIx for: #17729