Skip to content

Suppress diagnostic output for format --check --slient#17736

Merged
ntBre merged 9 commits intoastral-sh:mainfrom
Kalmaegi:fix_ruff_format_slient_always_print_reformat
Feb 3, 2026
Merged

Suppress diagnostic output for format --check --slient#17736
ntBre merged 9 commits intoastral-sh:mainfrom
Kalmaegi:fix_ruff_format_slient_always_print_reformat

Conversation

@Kalmaegi
Copy link
Contributor

Summary

FIx for: #17729

@github-actions
Copy link
Contributor

github-actions bot commented Apr 30, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@Kalmaegi
Copy link
Contributor Author

I'll fix the formatting later

@MichaReiser
Copy link
Member

Looks good. Could you add a test plan demonstrating that the fix works as expected?

@ntBre ntBre added the cli Related to the command-line interface label Apr 30, 2025
@Kalmaegi
Copy link
Contributor Author

Looks good. Could you add a test plan demonstrating that the fix works as expected?

Sure, I will add test

@ntBre ntBre linked an issue Jan 28, 2026 that may be closed by this pull request
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Kalmaegi
Copy link
Contributor Author

Kalmaegi commented Feb 3, 2026

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.

@Kalmaegi
Copy link
Contributor Author

Kalmaegi commented Feb 3, 2026

Thanks for the detailed review and the helpful comparison table!

I've updated the fix to properly match the behavior of this table:

check format --check (main) format --check (pr)
default diagnostics + summary diagnostics + summary diagnostics + summary
quiet diagnostics diagnostics diagnostics
silent exit code exit code exit code

Hopefully this is correct now. Thanks again for your help and patience

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! The new tests look great!

@ntBre ntBre added the formatter Related to the formatter label Feb 3, 2026
@ntBre ntBre changed the title [ruff] Fix For format --check --slient not respect --silent flag Suppress diagnostic output for format --check --slient Feb 3, 2026
@ntBre ntBre merged commit aa9c9bf into astral-sh:main Feb 3, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to the command-line interface formatter Related to the formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ruff format --check --silent still output the same log as with --quiet

4 participants