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

--fix-only returns exit code 1 upon fixes #4092

Closed
spapanik opened this issue Apr 25, 2023 · 6 comments · Fixed by #4146
Closed

--fix-only returns exit code 1 upon fixes #4092

spapanik opened this issue Apr 25, 2023 · 6 comments · Fixed by #4146
Assignees
Labels
cli Related to the command-line interface

Comments

@spapanik
Copy link

Thank you for the great work! Ruff is fantastic, and I have replaced all my linters with it. I just have a small feature request on the fixers of it.

Now, the cli options to fix the ruff issues are: ruff --fix . and ruff --fix-only . They are a bit problematic to work with in scripts, as even if they fix all the issues that are fixable, the exit code can be zero, if there are no fixable issues. There is the obvious workaround of adding || true, but this will mask all errors, for example ruff itself panicking instead of fixing the fixable issues. A new option that would allow just run it in fix mode.

@JonathanPlasse
Copy link
Contributor

Would --exit-non-zero-on-fix work for you?

@spapanik
Copy link
Author

@JonathanPlasse it does exactly the opposite. I was looking for a --exit-zero-on-fix. Let me explain the scenario: I have two errors in my code: I001 which is fixable, and N801 that's not fixable. What I would like to do is run it, fix I001 and return 0, because it successfully fixed all the fixable errors. Now, the closest is to do ruff --fix-only . || true but this means that if ruff breaks, I will still get an exit code 0, which is wrong.

@charliermarsh
Copy link
Member

I assumed that if you run Ruff in that scenario with ruff --fix-only ., and it fixed I001 but left N801, it would exit with code 0. Does it not?

@charliermarsh charliermarsh added the cli Related to the command-line interface label Apr 25, 2023
@spapanik
Copy link
Author

No, it doesn't:

venv:(***)$ ~/programming/*** git:(main) ✗
stephanos@marco $ ruff --fix-only foo.py
Fixed 1 error.
venv:(***)$ ~/programming/*** git:(main) ✗
stephanos@marco $ echo $?
1

@charliermarsh
Copy link
Member

Ahh ok, that strikes me as a bug, but will look into it.

@charliermarsh charliermarsh self-assigned this Apr 26, 2023
@charliermarsh charliermarsh changed the title Fix mode --fix-only returns exit code 1 upon fixes Apr 26, 2023
@charliermarsh
Copy link
Member

I guess, in this framing, ruff --fix-only would always return 0 (unless the program hit an internal error), whereas ruff --fix-only --exit-non-zero-on-fix would return 1 when at least one error was fixed. Is that right?

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants