Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforce java 8 conventions using checkStyle

I'm looking to enforce some best practices for Java 8 using checkStyle, some examples include:

  1. Don't nest optionals
  2. Limit lambdas to x lines if it's in the middle of stream transformations
  3. General warning against parallel stream

Based on my research, I can see that checkStyle supports java 8, but nothing specific to enforcing standards on features.

Is this something that's available?

Thanks for your help.

like image 505
Hari Avatar asked Jul 09 '15 14:07

Hari


People also ask

What Cannot be done by checkstyle tool?

The checks performed by Checkstyle are mainly limited to the presentation of the code. These checks do not confirm the correctness or completeness of the code.

Can checkstyle check code layout and formatting issues?

Checkstyle can check many aspects of your source code. It can find class design problems, method design problems. It also has the ability to check code layout and formatting issues.

Is checkstyle a Linter?

Checkstyle is one of the most popular linters available. With this popularity comes regular updates, thorough documentation, and ample community support.


1 Answers

If checkstyle supports it out of the box, it'll be listed among the standard checks that checkstyle comes with (I didn't see any when I glanced over it, unfortunately). If it's not in that list, I would then start looking at third party checkstyle libraries (such as SevNTU Checkstyle, Checkstyle Addons, and CS-Contrib among them) to see if you can find checks that satisfy your needs. If you are still unable to find anything, you might have to implement the checks yourself. If you do, you might want to consider contributing them to the community, winning the eternal gratitude of checkstyle users around the world.

like image 129
Brandon McKenzie Avatar answered Oct 17 '22 09:10

Brandon McKenzie