Is there a simple CLI Java linter?

JavaLint

Java Problem Overview


I've been trying to find a Java linter capable of running on the CLI that is separate from Eclipse that I can call as a commit hook for git or from our automated build script. Does such a thing exist?

Ideally it needs to check for unused imports and variables, that style guidelines are followed, exceptions are used properly, etc. Though some subset of those features would be better that what we have now - nothing!

Java Solutions


Solution 1 - Java

  • SpotBugs (earlier Findbugs) for finding existing bugs. VERY GOOD!
  • PMD for finding patterns that can lead to bugs (e.g. unused variables)
  • Checkstyle to enforce coding standards and conventions (e.g. whitespace, Javadoc)
  • Error Prone hooks right into your application's compile step
  • clang-format supports java and may be available on your system already

All these tools have some overlapping rules. There are many other similar tools, but these are the most popular and supported.

Solution 2 - Java

Also, check out Sonar, which combines many of the other tools and provides a nice view for it too.

> rules from Checkstyle, FindBugs, PMD, Clirr, fb-contrib.


Not sure exactly how to add it to a post-commit hook, but http://docs.codehaus.org/display/SONAR/Analyzing+with+Maven might be a good starting point (especially if you're using maven).

Maybe even consider using one of the approaches listed in http://docs.codehaus.org/display/SONAR/Continuous+Integration since it seems that you might be trying to look for better tooling for your whole team ("Though some subset of those features would be better that what we have now - nothing!"

Solution 3 - Java

This is EXACTLY what I am working on: a tool CLI-friendly to be used to check the quality of Java code. It has also an interactive modality. You can run single queries (to check for single warnings) or all queries together.

The tools is in its early stage but I am working on it almost every day. It is available here:

https://github.com/ftomassetti/effectivejava

Please let me know what do you think about it and feel free to ask questions.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBlueDragonXView Question on Stackoverflow
Solution 1 - JavamikeslatteryView Answer on Stackoverflow
Solution 2 - JavayegeniyView Answer on Stackoverflow
Solution 3 - JavaFederico TomassettiView Answer on Stackoverflow