Is there a simple CLI Java linter? [closed]

2019-01-30 08:03发布

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 lint
3条回答
再贱就再见
2楼-- · 2019-01-30 08:09
  • 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.

查看更多
甜甜的少女心
3楼-- · 2019-01-30 08:19

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.

查看更多
放荡不羁爱自由
4楼-- · 2019-01-30 08:26

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

查看更多
登录 后发表回答