streampipes
streampipes copied to clipboard
Add git pre-commit hook for checkstyle
Body
Since we have checkstyle enabled for all Java modules (see #820), it would be good to validate the styling with a Git pre-commit hook as well.
Mentoring
As this ticket is marked as good first issue: one of @tenthe, @RobertIndie or @bossenti is happy to provide help for getting started, just tag (one of) them if you want to start working on this issue and need some help.
StreamPipes Committer
- [X] I acknowledge that I am a maintainer/committer of the Apache StreamPipes project.
I could help with this one
That would be awesome @deexidee 🤩 Do you need anything to start with?
Sorry for missing, rough week again Sure! Actually, I never did anything related to git commit management. So I would be happy to see an example of a pre-commit hook if there are any in the project. Maybe searched poorly, but I couldn't find where pre-commit scripts are located. Are they in a different repo?
So, in generall a commit hook is a feature provided by git itself: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks You could for example write a bash file that should be executed when comitting.
For StreamPipes we have commit hooks at two places already present. The first one is for the UI codebase, it was contributed in #875
The second one is used in our python module (streampipes-client-python
) where we use the pre-commit
library: https://pre-commit.com/
As far as I know this could be also used for Java with Checkstyle, but there are probably more Java-native solutions? Maybe @dominikriemer @tenthe @smlabt @vesense @RobertIndie have an idea here
There is an ability to import a code style scheme from XML file in IntelliJ IDEA and Eclipse. Not sure if it's a suitable solution though
Yes, you can do this in your IDE. We also have a short description in our wiki how to do it [1]. You can find the checkstyle file in [2]. My suggestion would be to add checkstyle in your local development environment first. To test that everythinf is setup correctly, you can fix the checkstyle violations in #1192.
To ensure that there are no checkstyle violations we use a GitHub action. This is also the reason why the build in #1192 failed. To give the developer an even quicker feedback we want to integrate this check as a git pre-commit hook. That means a developer can only perform a git commit when there are no checkstyle violations.
I didn't do something like this before, but I guess we can also use the library https://pre-commit.com/ for that.
@bossenti: Do you think we should harmonize the tools we use for the hooks? Is it possible to use pre-commit for all the different languages? (For Typescript we use [3])
[1] https://cwiki.apache.org/confluence/display/STREAMPIPES/Code+Style+-+Java [2] https://github.com/apache/streampipes/blob/dev/tools/maven/checkstyle.xml [3] https://github.com/typicode/husky
The only support of pre-commit for JavaScript I could find is this one: https://github.com/jshint/jshint
I also didn't do this before. pre-commit looks like a good candidate.
Well then lets start/continue with pre-commit
and see how far we get 🙂
@deexidee are you still interested in contributing here?
Yes, sure! I'll try to open PR in a couple of days
awesome 🤩 there is no need to hurry
Ok, took me more than a couple of days (caught a cold) but here we are, turned out really easy to implement