Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check code style formatting in IDEA?

How to check code style in the whole project or some part of it in IDEA? Let me make an accent here on a word "check". I don't need to fix code style I just want to see how big is the problem of not following code style in the project. So I want to see list of lines or cases where code formatting is not inline with what I have set in the File -> Settings -> Code Style -> Java. I thought that Code Inspection does this but when I checked File -> Settings -> Inspections -> Code style issues it seemed to me that these issues are not about code style formatting.

What I would like to use is: I start some inspection on some part of code or the whole project and as a result of inspection I want to see list of issues/lines where code formatting is broken. I know I might just reformat the whole project and then run source control diff but I don't think that this is really good. I would like to see some categorization of code style issues with statistics, etc... Is there any way to get this in IDEA?

like image 449
vladimir Avatar asked Oct 22 '22 00:10

vladimir


2 Answers

You should consider CheckStyle. It analyses the code and shows summary similar to error or warning message in the IDE. In addition you could customize the check style or use existing one. There should be a plugin for IDEA as well.

like image 65
Shamim Ahmmed Avatar answered Oct 27 '22 10:10

Shamim Ahmmed


Try out maven-checkstyle-plugin. It's based on the Checkstyle. You can create configuration to run it under IntelliJ IDEA.

The output looks like:

C:\src\ClassPathTldsLoader.java:8:8: Unused import - java.util.Collections.
C:\src\model\Class1.java:64: 'if' construct must use '{}'s.
C:\src\model\Class2.java:55: 'if' construct must use '{}'s.
C:\src\Class3.java:4:1: Redundant import from the same package - java.util.Collections
...
like image 24
Lu55 Avatar answered Oct 27 '22 09:10

Lu55