Search code examples
javamavenintellij-ideacheckstyle

IntelliJ IDEA code reformat not working


I am using IntelliJ IDEA version 2017.3, then I install plug-in CheckStyle-IDEA v 5.16.0 successful, I install Apache Maven Checkstyle Plugin to run myCheckFile.xml. At install phase, I received many check style error like:

Indentation: '.' has incorrect indentation level 6, expected level should be 8.
Indentation: 'new' has incorrect indentation level 6, expected level should be 8.

After importing CheckStyle settings, I expect when I hit Ctrl+Alt+L inside IntelliJ IDEA all check style error will die but that doesn't happen, is there's something i'm missing ?


Solution

  • You might have a .editorconfig file which is taking precedence. I ran into the same problem and my solution was to comment out the .editorconfig file. Our team is using JHipster, which automatically generates a .editorconfig file. This generally has just a few key settings, including indent_size=4. I was experimenting with Google's checkstyle xml settings and saw the same overall issue you were seeing, where the checkstyle plugin was indicating the indentation was wrong, but the code/reformat option wasn't fixing it.

    TL;DR - see if you have a .editorconfig file and if so delete it or comment out the conflicting styles.