有没有一个简单的 CLI Java linter?

我一直试图找到一个能够在独立于 Eclipse 的 CLI 上运行的 Java linter,我可以将它作为 git 的提交钩子或自动构建脚本调用。有这种东西吗?

理想情况下,它需要检查未使用的导入和变量,遵循样式指南,正确使用异常,等等。尽管这些特性的一些子集会比我们现在所拥有的更好——什么都没有!

69364 次浏览
  • 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.

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

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.