-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move clang-format checks to pre-commit #787
Conversation
cc00974
to
942cd8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Are you considering using this for other linters?
Yes, in time! |
Is it worth keeping the CI check in case it fails locally in some way and something badly formatted creeps in? |
You mean to keep the local $ pip install pre-commit
$ pre-commit run --all-files Let me know what you think. |
Right I mean if the pre-commit hook fails in some way. But maybe this is obvious/unlikely |
Ah, I think I understand what you mean. Consider, though, that pre-commit will automatically update the files for you so they conform to the clang-format requirements; so in principle if you run pre-commit locally (which doesn't have to be in a pre-commit hook, by the way!) the code should always pass the CI job. |
I'm very unfamiliar with this... 🤔 How does this work? Does one need to install some extra piece of software? Is it really that a git commit will now forcefully update the code, not allowing formatting at all that I personally really don't view the current setup we have as so much of a problem. But if this is easy enough to use, we can give it a try, sure... |
So you do need to install something? Why is it way better to install this, instead of Docker? 😕 |
Even though the tool is called pre-commit, it's not actually required to be in a pre-commit hook at all; it also works as a stand-alone tool and - as shown in the PR - as a CI job. So it's still perfectly possible to commit and push code that is improperly formatted. It will just be rejected by the CI, as it is right now. The problem with the current setup is that it is a bit of a pain in the rear for users to find the right versions of clang-format; you can download some pre-build binaries from a slightly sketchy git repository or you can use your package manager, but the latter often only supports the latest few versions of clang-format.
Well, pre-format makes it much easier for users to use the exact same setup as the CI to reduce version conflicts. Also, spinning up a Docker container every time you want to format the code seems like a lot of unnecessary work. Still, this change doesn't prohibit that at all; users who prefer to use Docker are completely free to do that if they so please. |
This PR came to be because we talked about updating the clang-format versions on Mattermost. Without pre-commit, this would require users to find a way to install the new version of clang-format; with pre-commit, zero user action would be required. |
My main point is that you have to write instructions as part of this PR on how to use this pre-commit setup. I myself have no idea for instance. |
942cd8f
to
bfa2fc8
Compare
This will make them significantly easier for users to use, as well as easier to migrate to future versions.
Quality Gate passedIssues Measures |
Fair point, I added some documentation to the README. 👍 |
|
||
```console | ||
$ pre-commit run --all-files | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to mention that pre-commit can made to run as a pre-commit hook but does not by default (despite the name). And that you can enable that for your local git checkout with
$ pre-commit install
Getting the diff from a failed format run is nice - I tested this out here:
so from that point of view it is an improvement on our current system: you don't actually have to set up clang-format locally if you're willing to just apply the diff. |
This will make them significantly easier for users to use, as well as easier to migrate to future versions.