How can I easily fix Checkstyle errors?

Your question is rather vague, but I think what you're asking is if CheckStyle can automatically reformat code that it's checking to fix code layout problems that it finds.

The direct answer here is "no."

However, there are a number of "Java source code formatters" (google that, choose one) that will do what I believe you're asking for.


If you're using Eclipse, yes. You can't correct all problems though. There are two ways:

  1. Right click on the java file in Package Explorer or whatever, and select 'Apply Checkstyle Corrections'.
  2. Click on the error in the problems view, and select 'Quick fix'. This corrects the problem.

If you are using IntelliJ, you can install the CheckStyle IDEA plugin.

Then import the CheckStyle settings into the editor, and Reformat like normal (Ctrl+Alt+L is default shortcut key).