Allow several styles of indentation with Checkstyle

85 views
Skip to first unread message

Daniel Novais

unread,
Feb 1, 2016, 8:21:53 PM2/1/16
to checkstyle

I'm using checkstyle to analyse Java code readability. The modules I'm using are LineLength, NoLineWrap, NeedBraces, LeftCurly, RightCurly, WhitespaceAround, OneStatementPerLine, EmptyLineSeparator, SeparatorWrap, GenericWhitespace, Indentation and CommentsIndentation. If you know any more modules that might be related to code readability please let me know.


My problem is: I'm not really interested in knowing if the code analysed follows some code standard (Google, Sun, etc) I just want to know if the code is readable in a general way. Right now I'm having issues in the modules LeftCurly and Indentation.


In the case of LeftCurly I want to be able to accept both EOL and NL because I think both styles are readable.


In the case of indentation I don't want to define a tabsize, or the question tabs vs spaces, I just want consistency. I think I could achieve this by allowing several tabsizes but I don't know how to do that.


Thanks in advance!

Roman Ivanov

unread,
Feb 4, 2016, 8:48:08 PM2/4/16
to Daniel Novais, checkstyle
Hi Daniel,

I'm not really interested in knowing if the code analysed follows some code standard (Google, Sun, etc) I just want to know if the code is readable in a general way. 

Such configurations are only examples to let user understand what our library is capable of. Some people like following Google style - it is their choice. 
Each project has its own style guide and sent of Check they like. Our projects have specific config.

Right now I'm having issues in the modules LeftCurly and Indentation.

If you do not like current implementation, just deactivate such Checks at all.

In the case of LeftCurly I want to be able to accept both EOL and NL because I think both styles are readable.

If you do not care - just remove that Check from config.

>   I just want consistency. I think I could achieve this by allowing several tabsizes but I don't know how to do that.

Consistency is such a term .... We enforce consistency for whole project by default (single format style) if you have two files in different style that a located in the same folder - 
We cannot help you there, we can NOT predict what is correct base on file, correct is defined in checkstyle config.
You can use suppressions extensively http://checkstyle.sourceforge.net/config_filters.html to suppress validation on some files or use multiple instances of checkstyle execution with different configs over different sets of files.
But expected style (very strict style) is defined in config, there is NO auto-detection of style. 
For now I do not how to implement auto-detection reliably in limited amount of time that we have for this project. 

thanks,
Roman Ivanov

--
You received this message because you are subscribed to the Google Groups "checkstyle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to checkstyle+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michal Kordas

unread,
Feb 17, 2016, 12:13:45 PM2/17/16
to Roman Ivanov, check...@googlegroups.com, Daniel Novais

Daniel,

I think I understand your need. The solution would be to create new config options for existing checks out new checks. Fit example LeftCurly could get "any reasonable placement" option and regarding tabs vs spaces we could have check that just verifies consistency within one file, because the worst thing is to have inconsistencies in the same scope, while not being so fanatic to unify entire project.

Please divide your needs into small improvements/ideas and submit as issues. We'll discuss them separately.

Thanks,
Michal

Reply all
Reply to author
Forward
0 new messages