I have CheckStyle set to check for lines over 80 characters in Eclipse, and I have a margin line set up in my editor at 80 characters. If I put my cursor at the end of a line of code in my editor, the co-ordinates read (for example) 1433, 77, indicating the 77th character column from the left - yet when I run CheckStyle over the same line it says the line is 88 characters long! There are no extraneous tabs or other whitespace characters at the end of the line, it's definitely 77 long. Is CheckStyle broken?
From the Checkstyle documentation:
The calculation of the length of a line takes into account the number of expanded spaces for a tab character ('\t'). The default number of spaces is 8. To specify a different number of spaces, the user can set TreeWalker property tabWidth which applies to all Checks, including LineLength; or can set property tabWidth for LineLength alone.
http://checkstyle.sourceforge.net/config_sizes.html#LineLength
To do this in Eclipse:
TreeWalker
into the search box under Known modules.Is CheckStyle broken?
Probably not.
I expect you/Eclipse and CheckStyle have a different idea of the width of a TAB character. It sounds you think it means 4 spaces, whereas CheckStyle thinks it means 8 characters (its default).
One way around this is to configure Eclipse to not use TAB characters in your source file, then re-indent your source files.
Another way is to make use that CheckStyle and Eclipse agree on the TAB width; e.g. see @MartinEllis's answer.
(I prefer the first approach because it means that my source code will look correctly indented, irrespective of the platform's default TAB width; i.e. Windows versus Linux/Unix. Hard TAB characters in source code are a bad idea.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With