-
Notifications
You must be signed in to change notification settings - Fork 897
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
JSON output on ruff check --fix
does not show any thing related to fixes
#11329
Comments
ruff check --fix
does not show any thing related to fixes
You can extract the $ ruff check --output-format=json src/lsp.py
[
{
"cell": null,
"code": "F401",
"end_location": {
"column": 25,
"row": 3
},
"filename": "/Users/dhruv/playground/ruff/src/lsp.py",
"fix": {
"applicability": "safe",
"edits": [
{
"content": "",
"end_location": {
"column": 1,
"row": 4
},
"location": {
"column": 1,
"row": 3
}
}
],
"message": "Remove unused import: `pathlib.Path`"
},
"location": {
"column": 21,
"row": 3
},
"message": "`pathlib.Path` imported but unused",
"noqa_row": 3,
"url": "https://docs.astral.sh/ruff/rules/unused-import"
},
{
"cell": null,
"code": "T201",
"end_location": {
"column": 6,
"row": 5
},
"filename": "/Users/dhruv/playground/ruff/src/lsp.py",
"fix": {
"applicability": "unsafe",
"edits": [
{
"content": "",
"end_location": {
"column": 1,
"row": 12
},
"location": {
"column": 1,
"row": 5
}
}
],
"message": "Remove `print`"
},
"location": {
"column": 1,
"row": 5
},
"message": "`print` found",
"noqa_row": 5,
"url": "https://docs.astral.sh/ruff/rules/print"
}
] Does this help? |
Hi @dhruvmanila, thank you for the reply. I believe this feature should already work but some combination of |
Do you mean that you want the JSON output and that Ruff applies the fix? |
Yes, correct. If the information is available in one output type I think it makes sense it is available in all of them. Otherwise |
Thanks for confirming! I think this is an ideal behavior although it's not enforced on the CLI. This is because Can you provide the use-case for this behavior? What kind of information are you looking for with the applied fixes? |
Well, it does affect right now because JSON output prevents --show-fixes from displaying anything
Right now I am trying to display to users what have been changed on their code. This is part of a pre-commit script |
Thank you for providing your use-case!
I see. Looking at the following code: Lines 295 to 301 in 1f79407
Ruff would always prefer to display violations unless either the And as per the following code: ruff/crates/ruff/src/printer.rs Lines 219 to 235 in 1f79407
Ruff wouldn't display the fix summary if the output format isn't either "full", "concise", or "grouped". So, I think this behavior is correct because if someone wants to output in JSON, it's likely to be post-processed where it wouldn't make sense to provide additional output including the fix summary.
I think this is an expected behavior. The JSON output should only include the violations that are leftover after the fixes has been applied. It wouldn't include the violations which has been fixed. tl;dr
(Sorry for the long explanation, but it's helpful to know the context.) |
I understood why it is happening, but I don't think I agree this is expected behavior. There is nowhere saying "--show-fixes" should only append information to the output and not be part of the normal output It would make much more sense if it modified the output to contain with
with
|
I'm a bit torn. It could make sense to include the fixed violations but we'd of course be changing the meaning of the API (right now, the contract is: these are the violations that Ruff found that exist in your files). Including fixed violations is a bit strange because (e.g.) the locations no longer make sense, since the file has changed. I'd probably be open to changing it (curious to hear @dhruvmanila take) but wouldn't prioritize it unless someone wanted to take it on. I don't think we even have the information we'd need to power this in reporter right now. We could also consider using an entirely different JSON output for |
ruff 0.4.3 (1e91a09 2024-05-03)
I am trying to parse the output of
ruff check --fix --fix-only --show-fixes
to validate what has been changed. When using output =text
orfull
, I get:That is byproduct of the "--show-fixes", but I think this format is not very stable as it has changed before and also it has a non ascii character that prints weird in some places.
I would expect to get something meaningful out of json output when using show-fixes, but the process output is always empty (not even the
[]
from checks since I use --fix-only)I have tried all commands with
--isolated
and it behaves the same.The text was updated successfully, but these errors were encountered: