Is there a simple CLI Java linter? [closed]

2019-01-30 08:10发布

问题:

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!

回答1:

  • 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

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



回答2:

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!"



回答3:

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.



标签: java lint