You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beam.apache.org by Kenneth Knowles <ke...@apache.org> on 2018/11/01 16:30:36 UTC

Never get spotless errors with this one weird trick

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.

    #!/bin/sh
    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`).

Kenn

Re: Never get spotless errors with this one weird trick

Posted by Maximilian Michels <mx...@apache.org>.
> Scott just separated the spotless check from the Java unit test precommit job, so you get faster feedback on spotless errors.

Nice!

+1 for the pre-commit hook. Have it set up. Unfortunately, it doesn't 
work with the GitHub merge button.

Cheers,
Max

On 02.11.18 09:26, Ismaël Mejía wrote:
> 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 <am...@google.com> 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 <go...@google.com> wrote:
>>>
>>> Thanks for sharing the trick.
>>>
>>>
>>> On Thu, Nov 1, 2018 at 9:30 AM Kenneth Knowles <ke...@apache.org> 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.
>>>>
>>>>      #!/bin/sh
>>>>      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`).
>>>>
>>>> Kenn

Re: Never get spotless errors with this one weird trick

Posted by Ismaël Mejía <ie...@gmail.com>.
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 <am...@google.com> 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 <go...@google.com> wrote:
>>
>> Thanks for sharing the trick.
>>
>>
>> On Thu, Nov 1, 2018 at 9:30 AM Kenneth Knowles <ke...@apache.org> 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.
>>>
>>>     #!/bin/sh
>>>     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`).
>>>
>>> Kenn

Re: Never get spotless errors with this one weird trick

Posted by Alan Myrvold <am...@google.com>.
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 <go...@google.com> wrote:

> Thanks for sharing the trick.
>
>
> On Thu, Nov 1, 2018 at 9:30 AM Kenneth Knowles <ke...@apache.org> 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.
>>
>>     #!/bin/sh
>>     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`).
>>
>> Kenn
>>
>

Re: Never get spotless errors with this one weird trick

Posted by Ankur Goenka <go...@google.com>.
Thanks for sharing the trick.


On Thu, Nov 1, 2018 at 9:30 AM Kenneth Knowles <ke...@apache.org> 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.
>
>     #!/bin/sh
>     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`).
>
> Kenn
>