Re: Never get spotless errors with this one weird trick
Nice idea, thanks for sharing and thanks Scott for separating this in the build.
On Thu, Nov 1, 2018 at 11:51 PM Alan Myrvold <amyrvold@xxxxxxxxxx> wrote:
> Thanks for the trick. I added it to https://cwiki.apache.org/confluence/display/BEAM/Java+Tips
> On Thu, Nov 1, 2018 at 2:26 PM Ankur Goenka <goenka@xxxxxxxxxx> wrote:
>> Thanks for sharing the trick.
>> On Thu, Nov 1, 2018 at 9:30 AM Kenneth Knowles <kenn@xxxxxxxxxx> wrote:
>>> Hi all,
>>> Scott just separated the spotless check from the Java unit test precommit job, so you get faster feedback on spotless errors.
>>> I wondered if there was a good place to just always reformat, and whether it was fast enough to be OK. The answer is yes, and yes.
>>> You can set up a git precommit hook to always autoformat code, by putting this in .git/hooks/pre-commit and setting the executable bit.
>>> set -e
>>> ./gradlew spotlessApply
>>> If you haven't used git hooks, the docs are here: https://git-scm.com/docs/githooks. I'll call out that --no-verify will skip it and `chmod u-x` will disable it.
>>> Then testing the time:
>>> - From a fresh checkout ./gradlew spotlessJavaApply took 24s configuration and 49s spotlessApply
>>> - Then I modified one file in nexmark, messed up the formatting, and committed
>>> - The re-run took 1s in configuration and 4s in spotlessApply
>>> So this will add ~5s of waiting each time you `git commit`. You can decide if it is worth it to you. If you are a "push a bunch of commits to be squashed" GitHub user, you could amortize it by making it a pre-push hook that adds a spotless commit (`git commit --fixup HEAD`).