ruff: Add an `--exit-non-zero-on-fix` equivalent to the formatter.
Title says it all really. --exit-non-zero-on-change
? I think this would be useful when using tools like pre-commit with CI in the same way as the checker’s --exit-non-zero-on-fix
.
About this issue
- Original URL
- State: open
- Created 8 months ago
- Comments: 16 (9 by maintainers)
Commits related to this issue
- https://github.com/astral-sh/ruff/issues/8191#issuecomment-1781220297 — committed to TheReverend403/cappuccino by TheReverend403 8 months ago
- https://github.com/astral-sh/ruff/issues/8191#issuecomment-1781220297 — committed to TheReverend403/gentoogram-bot by TheReverend403 8 months ago
the use case for us would be to have a single
format
makefile target that can be used both for:something like
without this we need separate targets for dev and CI
@zanieb I do have a need for this, so perhaps this could be re-opened? My use case: I can’t use pre-commit, because my project is a subdirectory in a larger git repo (“monorepo”). pre-commit decided to not support this use case, so I have my own “pre-commit” script, which indeed, I want to fail if it makes changes. Currently I wrote this:
but having a --exit-non-zero-on-fix would be much nicer.
If this is approved, I will be happy to try and implement this.
Thanks!
Exactly, but as an additional flag rather than changing
--check
so as to avoid breaking everyone’s current CI workflows. 😏I used black, just not with this behaviour. It was actually ruff’s own
--exit-non-zero-on-fix
that gave me this idea for the formatter.This seems like a reasonable approach if we do implement it. It isn’t incompatible with
--check
though, it just has no effect. With--diff
I don’t know our exit code behavior.Oh sorry. I misunderstood you. If I understand you correctly, you’re asking that
ruff format --check
exits with a non-zero exit code if it would reformat any files but it would also write the changes back to disk so that runningruff format
isn’t necessary locally.I’m a bit torn where to integrate this functionality best. We could either to
ruff format --exit-non-zero-on-fix
(undecided on the name of the flag) without using check. However, the option would be incompatible when using with--check
or--diff
.Did you use black before? If so, how did your setup look like?