In CheckStyle there is a module (File Tab Character
) that checks that there are not tab-characters in the source code. Their rationale is:
- Developers should not need to configure the tab width of their text editors in order to be able to read source code.
- From the Apache jakarta coding standards: In a distributed development environment, when the commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.
To ensure there is the correct number of spaces, there is an additional module (Indentation
).
I prefer using tabs for indentation and want to add this requirement to my CheckStyle-file. My rationale:
- Developers should have the opportunity to configure the space used for indentation
- Tabs are a logical and configurable unit for indentation,
n spaces
is just an arbitrary number of spaces.
Unfortunately I could not find a way to do this with CheckStyle.
There is no ready-made check which does this, but you can configure the RegexpSinglelineJava check accordingly. The following configuration goes into your checkstyle.xml under TreeWalker
:
<module name="RegexpSinglelineJava">
<property name="format" value="^\t* "/>
<property name="message" value="Indent must use tab characters"/>
<property name="ignoreComments" value="true"/>
</module>
It checks if there are spaces in the indent. Setting ignoreComments
eliminates the problem that Javadoc comments often have at least one space before the asterisk.
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