:wave: I just joined here. I work on the Developer...
# general
b
👋 I just joined here. I work on the Developer Experience team at Rippling. (cc @rapid-bird-79300) We use Pants for various linting/formatting checks, including in a
pre-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!
b
Welcome! Sorry for the trouble. Hm, usually a run like
pants 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?
r
Hey @broad-processor-92400 thanks for the response! I believe the issue is because we are running
pants 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.
b
Ah, yeah, I see. It seems reasonable to add that feature to pants, can you file a feature request? Are you interested in implementing it? (I'd use it too! we have pre-push hook that runs
pants 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:
Copy code
[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.
b
To clarify: I want something like, • no errors found, no work done – exit 0 • errors found, not all could be auto-fixed – exit 1 • errors found, all auto-fixed, nothing left to fix – exit 2
🎯 1
Is that feasible? I’m not yet familiar with the internals of Pants.
r
@brainy-fountain-94451 @broad-processor-92400 created an issue here https://github.com/pantsbuild/pants/issues/20905 (comment if missing anything) I'd imagine this is simple to extend Pants for but like Ben said we have not contributor to internal goals lik` fix / fmt` so not sure where to begin, we'll need some guidance.
👍 1
c
If it helps, I think we automatically construct `lint`ers from `fix`ers . So
pants lint
should also run any fixers and formatters, but won't write their changes to disk.
r
Yeah we have considered that but it's not helpful for our use case because we want to apply the fixes for the developer like ruff does. In general we need something like this to achieve what we want
pants 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.
vs if we had the option for non-zero exit code it could be
pants --exit-non-zero-on-fix fix fmt lint