streampipes icon indicating copy to clipboard operation
streampipes copied to clipboard

Add git pre-commit hook for checkstyle

Open tenthe opened this issue 2 years ago • 13 comments

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.

tenthe avatar Dec 22 '22 15:12 tenthe

I could help with this one

deexidee avatar Jan 31 '23 18:01 deexidee

That would be awesome @deexidee 🤩 Do you need anything to start with?

bossenti avatar Jan 31 '23 19:01 bossenti

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?

deexidee avatar Feb 08 '23 13:02 deexidee

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

bossenti avatar Feb 08 '23 16:02 bossenti

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

deexidee avatar Feb 09 '23 12:02 deexidee

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

tenthe avatar Feb 10 '23 07:02 tenthe

The only support of pre-commit for JavaScript I could find is this one: https://github.com/jshint/jshint

bossenti avatar Feb 10 '23 18:02 bossenti

I also didn't do this before. pre-commit looks like a good candidate.

vesense avatar Feb 14 '23 14:02 vesense

Well then lets start/continue with pre-commit and see how far we get 🙂

bossenti avatar Feb 19 '23 14:02 bossenti

@deexidee are you still interested in contributing here?

bossenti avatar Feb 19 '23 14:02 bossenti

Yes, sure! I'll try to open PR in a couple of days

deexidee avatar Feb 19 '23 23:02 deexidee

awesome 🤩 there is no need to hurry

bossenti avatar Feb 20 '23 05:02 bossenti

Ok, took me more than a couple of days (caught a cold) but here we are, turned out really easy to implement

deexidee avatar Mar 05 '23 12:03 deexidee