klaw icon indicating copy to clipboard operation
klaw copied to clipboard

Add Static Code Analyzers and Style Checkers for the Java parts

Open jlprat opened this issue 2 years ago • 3 comments

What is currently missing?

There are different ways to write Java (curly braces on same line vs newline, naming conventions), we should programatically decide on the way the project should be written. Additionally, there are several known bug prone code patterns that we can automatically check and prevent before committing, making our code more secure and in turn reviews are easier to perform.

How could this be improved?

Last time I worked on Java only codebases there was a triad of plugins to use:

  • Spotless (I understand is a better alternative to Checkstyle) -- Already in the project :heavy_check_mark:
  • PMD
  • SpotBugs (successor of FindBugs)

First, decide on which tools to use (I propose the 3 mentioned above) and configure them with the proper defaults

Is this a feature you would work on yourself?

  • [x] I plan to open a pull request for this feature

jlprat avatar Nov 29 '22 11:11 jlprat

Spotless (I understand is a better alternative to Checkstyle)

it is already enabled here https://github.com/aiven/klaw/blob/f6564513a9fad919485dd16bf6c3f91126634f9c/pom.xml#L190-L211

snuyanzin avatar Nov 29 '22 11:11 snuyanzin

Ah yes, Spotless is enabled right. We might want to check if we want to do add extra stylistic rule

jlprat avatar Nov 29 '22 12:11 jlprat

PMD is a nice tool although you can waste a lot of time until you settle on a configuration that not only works for you but is also not too pedantic in some situations.

In some of my projects I have had good experience with moving this kind of configuration into its own dependency. Then projects that want to use this configuration only need to customize the maven plugin a bit. I believe this is a reasonable approach when trying to achieve some standardization among similar projects. Maybe this is something you want to consider as well, given that you probably have a couple of projects in the organization.

Maybe this sample provides some value, though I would replace Checkstyle with Spotless these days (which you use already): https://github.com/sekaiser/build-tools-sample

sekaiser avatar Dec 12 '22 16:12 sekaiser