brainy-fountain-94451
05/08/2024, 4:15 PMpre-commit
hook which has fallen into disuse but which we’d like to bring back. One challenge with Pants in that workflow is that it doesn’t differentiate when it found errors and successfully fixed them, from errors that it couldn’t fix. (A human can determine this from the text output, but it’s hard to do this in a script.) By contrast, ruff
has a --exit-non-zero-on-fix
flag which allows this to be differentiated. Would it be feasible for Pants to incorporate a similar pattern?
Thank you!broad-processor-92400
05/08/2024, 11:22 PMpants lint
will exit with a non-zero code if there's problems, so I'm not 100% sure I understand your concern.
What's in your pre-commit hook at the moment?
Can you give examples of what you expect to happen as the result of git commit
with (1) fixable errors or (2) non-fixable errors?rapid-bird-79300
05/09/2024, 10:19 PMpants fix fmt
and it applied autofixes but doesn't exit with 1 when there are changes. We want pre-commit to fail so the developer has a chance to include those fixes.broad-processor-92400
05/09/2024, 11:19 PMpants tailor --check update-build-files --check lint check ::
as validation)
In the interim, one option would be just running a validation-only version like the above, and then have devs re-run the command to actually make the fixes. We have an alias that allows just running one command pants local
habitually:
[cli.alias]
local = "tailor update-build-files fmt lint check ::"
Either that, or use a fancier shell script that does something like pants <validation> || (pants <fix>; exit 1)
as the precommit.brainy-fountain-94451
05/10/2024, 4:12 PMbrainy-fountain-94451
05/10/2024, 4:12 PMrapid-bird-79300
05/10/2024, 4:23 PMcareful-address-89803
05/13/2024, 5:43 AMpants lint
should also run any fixers and formatters, but won't write their changes to disk.rapid-bird-79300
05/13/2024, 8:14 PMpants lint fix fmt lint
The first lint
captures all errors. The fix fmt
applies any autofixes. The final lint
is sanity check making nothing else was introduce post fix + fmt.rapid-bird-79300
05/13/2024, 8:15 PMpants --exit-non-zero-on-fix fix fmt lint