Remove Leading Space before Asterisk - Block Comment Style in IntelliJ

470 Views Asked by At

In using IntelliJ, I have found that it puts a space in the second and subsequent lines before the asterisk for a block comment, for example:

/***************************************************************************
 * This is a code header.
 * The extra space before the asterisk is not good.
 ***************************************************************************/

Our team has a common shared header file which is enforced via Checkstyle, and not everyone uses IntelliJ. I don't know how other IDEs handle headers, and I think some folks are using plain text editors. So, rather than change everyone else, I'd like to get rid of the space that is inserted by default when I reformat the code. Is this possible (either in the IDE, or less preferably, via allowing an optional space in the header file via Checkstyle)?

2

There are 2 best solutions below

1
Raymo111 On

This is proper programming style as recommended by Oracle. Deviation from this practice is not recommended. If you really wanted to remove the spaces, you could edit your workspace preferences to disable auto-formatting for headers. Or just don't auto-format at all.

3
theMayer On

So, I was able to configure Checkstyle to accept a RegEx'd header file (so now I have two problems ;).

In the Style.xml file, I set it to use RegexpHeader:

<module name="RegexpHeader">
    <property name="headerFile" value="${config_loc}/required-header.txt"/>
</module>

Then, I wrote the file RegEx to allow an optional space in that location:

^\/[\*]{75}$
^\W?\* This is a code header\.$
^\W?\* The RegEx is configured to allow an optional leading space\.$
^\W?[\*]{75}\/$

However, I'd still like to know whether IntelliJ can be configured to ignore the code header, so feel free to answer if you know how to get it to do that.