Using Checkstyle

On some homework assignments, the checkstyle tool will be used to inspect your style and documentation. The tool is set up to ensure that you are following the Google Java Style Guide. The rules in this guide are a superset of what we introduced in class. The primary goal of tools like this is to ensure that you follow specified guidelines; these guidelines help with readability, especially in large codebases that multiple people are working on! Checkstyle will check for things like the presence of javadoc documentation comments, spacing between operators, the presence of curly braces around blocks.

Grading

When checkstyle is used towards your assignment grade, I’ll count the number of rules you’ve violated rather than the number of violations. This means that you ’t be penalized many times for the same type of problem, but you do need to fix all of the problems to get full credit. I acknowledge that the Google guidelines are picky in some cases that I frankly don’t care about, but I decided to use them here because I think it’s good to work with a common and well-documented standard. As the rules are a little bit harsh, I will ignore up to two broken rules for each submission.

After 2 violated rules, each violated rule will lead to a 1% deduction to your grade up to a maximum amount. You’ll have the opportunity to resubmit up until the deadline to fix checkstyle violations just like you would for any Gradescope test failures.

Gradescope Output

When you submit on Gradescope, the summary will contain information about checkstyle errors. You’ll see a table that looks like this:

The table shows:

  • Rule: the identifier for the rule that was violated
  • Details: a detailed message about the violation
  • Start Line: the line to look at to fix the violation
  • Start Column: the position within the line to look at to fix the violation (if relevant)

Running Checkstyle in VS Code

Rather than only seeing checkstyle output when you submit on Gradescope, you can also install the checkstyle VS Code extension to run checkstyle in your editor!

Follow the instructions on that page to set the checkstyle configuration file (Google’s is available as one of the default options). Set the checkstyle version to the most recent version using the Checkstyle: Set the Checkstyle Version command. You should use version 11.01, which matches the version used on Gradescope. Then, run the Checkstyle: Check Code with Checkstyle command. You’ll see yellow underlines under checkstyle errors. If you hover over them, you’ll see details like this: