I’m always looking for simple ways that I can improve my Java programming. And SpotBugs, CheckStyle and PMD can help me do that.
NOTE: updated 20200625 because I no longer use QAPlug or FindBugs, I install PMD, CheckStyle and SpotBugs directly from the IntelliJ plugins. Updated 20200713 to include recommendation of SonarLint
I’m always looking for simple ways that I can improve my Java programming.
I use SonarLint, PMD, SpotBugs, CheckStyle IntelliJ Plugins my IDE.
Using Static Analysis
Using Static Analysis is like having a coach sitting by you when you are writing code. And some of the suggestions the tools make you won’t understand, so you have to search and learn what they mean - forcing you to learn that little bit more about your chosen language.
Don’t take all the suggestions at face value. You choose which suggestions to act on, and you can configure the tools to warn you about some things and not others.
Over time, you might choose to add the command line and build versions of the tools into your CI process rather than just your personal coding approach.
SonarLint
Katherine Rollo recommended I try SonarLint.
The interesting part of SonarLint is that it works ‘on the fly’. It is a little easier to use because you open the tab for SonarLint and it shows you any issues with the current file you are working with.
I’ve been finding the speed and accessiblity of the tool very useful, so I have been using SonarLint more than the other tools, which means I’ve been using Static Analysis to help me improve my coding more than ever.
By keeping the tab open, it is like having someone to pair with, who comments on your Java coding as you go. I find it very useful.
- Open the SonarLint Tab
- Read the results of the analysis
PMD Plugin
- right click on the project
- choose “PMD”
- choose profile
- analyse the results
CheckStyle Plugin
- configure using Preferences \ Tools \ Checkstyle
- set to scan scope including tests
- click the Checkstyle tab
- Check Project
- Analyse the results
SpotBugs Plugin
- click the SpotBugs tab
- analyse project file including test sources
- Analyse the Results
Demo of QAPlug plugin with PMD, FindBugs and CheckStyle
QAPlug wraps it all up in an right click menu item to Analyze the source code and shows all the items in a list for you to work through.
Just make sure you double click on the lowest branch in the tree to jump right to the code position where the tool identified the issue or suggestion.