0

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)?

theMayer
  • 15,456
  • 7
  • 58
  • 90
  • In all honesty I don't think this is directly possible, short of not auto-formatting or asking everyone else to look the other way when reviewing the code with this whitespace. Or, bringing the group together and "coming to Jesus" and saying that y'all should be a bit more flexible on these standards. – Makoto Apr 09 '18 at 15:52
  • @Makoto - we are using Checkstyle, and it is importing a text file header. I don't see that there is a way to tell it to allow an optional leading space - if there were, I think the team would be OK with that. – theMayer Apr 09 '18 at 16:00
  • Mm...you were able to add the header into Checkstyle as a thing to check. You should be able to remove it from Checkstyle if that's necessary. – Makoto Apr 09 '18 at 16:01
  • Removing the header from Checkstyle is not an option. – theMayer Apr 09 '18 at 16:03

2 Answers2

1

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.

theMayer
  • 15,456
  • 7
  • 58
  • 90
  • *I'd still like to know whether IntelliJ can be configured to ignore the code header* - probably yes! But ask it in a new question first. – barfuin Apr 10 '18 at 08:36
  • @ThomasJensen do you have a suggestion for how my existing question is not sufficiently written to ask this? I posted this as a good workaround, but I don't feel it is really what I was looking for. – theMayer Apr 10 '18 at 12:18
  • Your question is fine, but it is about how to deal with the leading space, and it has a good answer (yours). *How to make IntelliJ ignore the header* is simply a new question, and thus should be treated as such. Mixing two questions into one will only make the answers less useful for others. – barfuin Apr 10 '18 at 18:56
0

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.

Raymo111
  • 514
  • 8
  • 24