Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting output format hides output in ruff check #14452

Open
kaddkaka opened this issue Nov 19, 2024 · 2 comments
Open

setting output format hides output in ruff check #14452

kaddkaka opened this issue Nov 19, 2024 · 2 comments
Labels
cli Related to the command-line interface needs-design Needs further design before implementation

Comments

@kaddkaka
Copy link

When running a ruff check --fix-only there is no output about what errors were fixed. This surprised me, I thought it would still print the fixed error since the documentation about --fix-only says "Like fix, but disables reporting on leftover violation. Implies fix."

Maybe supplying --show-fixes will fix it? Yes,

ruff check --fix-only --show-fixes shows the fixed errors, great!

Can we also get this info in json output format? No,

ruff check --fix-only --show-fixes --output-format json print nothing! --output-format junit has the same issue.

Ruff version: 0.7.0

@zanieb
Copy link
Member

zanieb commented Nov 19, 2024

❯ echo "import b, a" > example.py
❯ ruff check example.py --select I
example.py:1:1: I001 [*] Import block is un-sorted or un-formatted
  |
1 | / import b, a
  |
  = help: Organize imports

Found 1 error.
[*] 1 fixable with the `--fix` option.

❯ ruff check example.py --select I --fix-only
Fixed 1 error.

❯ echo "import b, a" > example.py
❯ ruff check example.py --select I --fix
Found 1 error (1 fixed, 0 remaining).

❯ ruff check example.py --select I --fix-only --output-format json

❯ echo "import b, a" > example.py
❯ ruff check example.py --select I --fix --output-format json
[]%                        

❯ echo "import b, a" > example.py
❯ ruff check example.py --select I --fix --output-format json --show-fixes
[]%                          

❯ echo "import b, a" > example.py
❯ ruff check example.py --select I --fix-only --show-fixes

Fixed 1 error:
- example.py:
    1 × I001 (unsorted-imports)

Fixed 1 error.                                                                                                                                  

I don't think this has to do with --fix-only, i.e., it applies equally to --fix. I think we should improve the JSON output here, though I don't think it should rely on the --show-fixes flag.

@MichaReiser MichaReiser added cli Related to the command-line interface needs-design Needs further design before implementation labels Nov 20, 2024
@MichaReiser
Copy link
Member

I suspect that Ruff throws away the diagnostics after each fix cycle. We would need to preserve them and pass them through to the json emitter. This likely requires some special casing in the CLI because we don't want to emit the diagnostics for all output formats (which makes the experience somewhat inconsistent)

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 needs-design Needs further design before implementation
Projects
None yet
Development

No branches or pull requests

3 participants