Allow to use empty comments by default in TrailingCommentCheck rule

java
formatting

(Adam Gabryś) #1

Hello,
I would like to propose a change of the default value of the legalTrailingCommentPattern from:

^\s*+[^\s]++$

to

^(\s*+[^\s]+)?$.

It allows using empty comments (very often used by developers to force a new line) when automatic code formatted is enabled.

I’ve prepared an example code to allow verification:

Cheers


(Alexandre Gigleux) #4

Hello Adam,

I’m not in favour to change the default configuration of the rule S139 | TrailingCommentCheck to cover a limitation of an IDE code formatter. When I look at your reproducer, I don’t feel well when I see all these //. Without knowing your motivations, I would tend to complain and remove them. I think you should find a way to fix the IDE code formatter so it does what you expect.
S139 is not activated in the default “Sonar way” Quality Profile, so I think it’s acceptable to let users change the configuration of the rule when activating it.

Alex


(Adam Gabryś) #6

Hi Alexandre,

Okay, fair enough :wink:

I also don’t like them, but IDE code formatters give options wrap always, wrap when too long or never wrap :roll_eyes:

Cheers