Sonar

Ability to personalize the CheckStyle SuppressionCommentFilter and SuppressWithNearbyCommentFilter modules

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 2.3
  • Component/s: Checkstyle
  • Labels:
    None
  • Number of attachments :
    3

Description

We would like to customize Suppression Filter : here are 2 suppression filter we are using currently

<module name="SuppressionCommentFilter">
		<property name="offCommentFormat" value="CSOFF\: ([\w\|]+) : (\w+)" />
		<property name="onCommentFormat" value="CSON\: ([\w\|]+)" />
		<property name="checkFormat" value="$1" />
	</module>
	<module name="SuppressionCommentFilter">
		<property name="offCommentFormat" value="CSOFF ALL\: (\w+)" />
		<property name="onCommentFormat" value="CSON ALL\: " />
	</module>

Could it be possible to integrate properties in checkstyle quality profile configuration ?

Issue Links

Activity

Hide
Freddy Mallet added a comment -

Hi Bruno, configuring the behavior of the SuppressionCommentFilter with a property available in the Settings page should be possible. Feel free to provide a patch.

Show
Freddy Mallet added a comment - Hi Bruno, configuring the behavior of the SuppressionCommentFilter with a property available in the Settings page should be possible. Feel free to provide a patch.
Hide
Bruno Pirrotta added a comment -

Unfortunatly, i'm not a Java developer ... i can't help on this point. If someone can help...

Show
Bruno Pirrotta added a comment - Unfortunatly, i'm not a Java developer ... i can't help on this point. If someone can help...
Hide
Michael Semb Wever added a comment -

Is there any way to this now? Is there a file in the installation we can edit?

Show
Michael Semb Wever added a comment - Is there any way to this now? Is there a file in the installation we can edit?
Hide
Freddy Mallet added a comment -

Sorry Michael, but nothing is currently possible without patching Sonar.

Show
Freddy Mallet added a comment - Sorry Michael, but nothing is currently possible without patching Sonar.
Hide
Michael Semb Wever added a comment -

Any chance to a hint as to where do i start patching?

Show
Michael Semb Wever added a comment - Any chance to a hint as to where do i start patching?
Hide
Alexander Krist added a comment -

Hey Michael,
ask me tomorrow again, then i'm at work and i'll help you. I patched it for our project.

Show
Alexander Krist added a comment - Hey Michael, ask me tomorrow again, then i'm at work and i'll help you. I patched it for our project.
Hide
Alexander Krist added a comment -

This is my try to fix it.

Show
Alexander Krist added a comment - This is my try to fix it.
Hide
Michael Semb Wever added a comment -

Here's Alexander Krist work as a 'svn diff' against
https://svn.codehaus.org/sonar/tags/2.0.1/plugins/sonar-plugin-checkstyle

(but i suspect the patch can be applied to trunk as well).

While using "rules" to enable and customise the SuppressionCommentFilter might be against the codebase's intention, it works well and simple enough that's it got my vote to include.

Show
Michael Semb Wever added a comment - Here's Alexander Krist work as a 'svn diff' against https://svn.codehaus.org/sonar/tags/2.0.1/plugins/sonar-plugin-checkstyle (but i suspect the patch can be applied to trunk as well). While using "rules" to enable and customise the SuppressionCommentFilter might be against the codebase's intention, it works well and simple enough that's it got my vote to include.
Hide
Freddy Mallet added a comment -

I've fixed this issue by enabling both the configuration of the SuppressionCommentFilter and SuppressWithNearbyCommentFilter modules. Two new properties has been added to the Sonar Checkstyle plugin to allow such configuration, see the attached screenshot.

Show
Freddy Mallet added a comment - I've fixed this issue by enabling both the configuration of the SuppressionCommentFilter and SuppressWithNearbyCommentFilter modules. Two new properties has been added to the Sonar Checkstyle plugin to allow such configuration, see the attached screenshot.
Hide
Michael Semb Wever added a comment -

There's only one field in that screenshot.
There should be three!? offCommentFormat, onCommentFormat, and checkFormat

Show
Michael Semb Wever added a comment - There's only one field in that screenshot. There should be three!? offCommentFormat, onCommentFormat, and checkFormat
Hide
Freddy Mallet added a comment -

Hi Michael, in fact there are two fields/properties : SuppressionCommentFilter and SuppressWithNearbyCommentFilter. The default values of those two properties are :

<module name="SuppressionCommentFilter"/>

and

<module name="SuppressWithNearbyCommentFilter"/>

Let's say, you'd like to change the behavior of the default SuppressionCommentFilter, in that case you'll just have to replace the default value by the full XML description of the SuppressionCommentFilter module node :

<module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="UNUSED OFF\: (\w+)"/>
    <property name="onCommentFormat" value="UNUSED ON\: (\w+)"/>
    <property name="checkFormat" value="Unused"/>
    <property name="messageFormat" value="^Unused \w+ '$1'.$"/>
</module>
Show
Freddy Mallet added a comment - Hi Michael, in fact there are two fields/properties : SuppressionCommentFilter and SuppressWithNearbyCommentFilter. The default values of those two properties are :
<module name="SuppressionCommentFilter"/>
and
<module name="SuppressWithNearbyCommentFilter"/>
Let's say, you'd like to change the behavior of the default SuppressionCommentFilter, in that case you'll just have to replace the default value by the full XML description of the SuppressionCommentFilter module node :
<module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="UNUSED OFF\: (\w+)"/>
    <property name="onCommentFormat" value="UNUSED ON\: (\w+)"/>
    <property name="checkFormat" value="Unused"/>
    <property name="messageFormat" value="^Unused \w+ '$1'.$"/>
</module>
Hide
Alexander Krist added a comment -

It is not enough for our project. The small patch uploaded by me is more usefull for us, becouse with that you can define more than one SuppressionCommentFilter by uploading an xml file with all Rules. For example we have:

<module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: magic number check off"/>
    <property name="onCommentFormat" value="CS\: magic number check on"/>
    <property name="checkFormat" value="MagicNumberCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: GUI members javadoc check off"/>
    <property name="onCommentFormat" value="CS\: GUI members javadoc check on"/>
    <property name="checkFormat" value="JavadocVariableCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: Getter/Setter javadoc check off"/>
    <property name="onCommentFormat" value="CS\: Getter/Setter javadoc check on"/>
    <property name="checkFormat" value="JavadocMethodCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: method length too long check off"/>
    <property name="onCommentFormat" value="CS\: method length too long check on"/>
    <property name="checkFormat" value="MethodLengthCheck"/>
  </module>

Sure them are not all editable in the webinterface, becouse there will be shown only the last one, but they were all used for analyse.

Show
Alexander Krist added a comment - It is not enough for our project. The small patch uploaded by me is more usefull for us, becouse with that you can define more than one SuppressionCommentFilter by uploading an xml file with all Rules. For example we have:
<module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: magic number check off"/>
    <property name="onCommentFormat" value="CS\: magic number check on"/>
    <property name="checkFormat" value="MagicNumberCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: GUI members javadoc check off"/>
    <property name="onCommentFormat" value="CS\: GUI members javadoc check on"/>
    <property name="checkFormat" value="JavadocVariableCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: Getter/Setter javadoc check off"/>
    <property name="onCommentFormat" value="CS\: Getter/Setter javadoc check on"/>
    <property name="checkFormat" value="JavadocMethodCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: method length too long check off"/>
    <property name="onCommentFormat" value="CS\: method length too long check on"/>
    <property name="checkFormat" value="MethodLengthCheck"/>
  </module>
Sure them are not all editable in the webinterface, becouse there will be shown only the last one, but they were all used for analyse.
Hide
Bruno Pirrotta added a comment -

That is what we exactly need Alexander. This solution is very flexible and many rules can be loaded

Show
Bruno Pirrotta added a comment - That is what we exactly need Alexander. This solution is very flexible and many rules can be loaded
Hide
Freddy Mallet added a comment - - edited

Ok Alexander, I understand what you mean and I'm trying improve the current implementation to allow multiple definitions. I guess you can understand that I definitely can't apply your patch as is for the following reasons : a comment filter is NOT a rule and the tip to define multiple modules is a kind of dirty patch. That's perfectly suite your need but we need something more maintainable for the long term.

Show
Freddy Mallet added a comment - - edited Ok Alexander, I understand what you mean and I'm trying improve the current implementation to allow multiple definitions. I guess you can understand that I definitely can't apply your patch as is for the following reasons : a comment filter is NOT a rule and the tip to define multiple modules is a kind of dirty patch. That's perfectly suite your need but we need something more maintainable for the long term.
Hide
Alexander Krist added a comment -

Yes I absolutely understand that, thats why I never voted for my patch. I only share it to other as a temporary workaround.

Show
Alexander Krist added a comment - Yes I absolutely understand that, thats why I never voted for my patch. I only share it to other as a temporary workaround.
Hide
Freddy Mallet added a comment - - edited

Alexandre and Bruno, the Sonar Checkstyle plugin has now only one "filters" property which can be used to configured any number of SuppressionFilter, SuppressionCommentFilter and SuppresWithNearbyCommentFilter. Here is an example :

<module name="Checker">
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: magic number check off"/>
    <property name="onCommentFormat" value="CS\: magic number check on"/>
    <property name="checkFormat" value="MagicNumberCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: GUI members javadoc check off"/>
    <property name="onCommentFormat" value="CS\: GUI members javadoc check on"/>
    <property name="checkFormat" value="JavadocVariableCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: Getter/Setter javadoc check off"/>
    <property name="onCommentFormat" value="CS\: Getter/Setter javadoc check on"/>
    <property name="checkFormat" value="JavadocMethodCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: method length too long check off"/>
    <property name="onCommentFormat" value="CS\: method length too long check on"/>
    <property name="checkFormat" value="MethodLengthCheck"/>
  </module>
  <module name="SuppressWithNearbyCommentFilter">
    <property name="commentFormat" value="Ok to catch (\w+) here"/>
    <property name="checkFormat" value="IllegalCatchCheck"/>
    <property name="messageFormat" value="$1"/>
    <property name="influenceFormat" value="-1"/>
  </module>
</module>
Show
Freddy Mallet added a comment - - edited Alexandre and Bruno, the Sonar Checkstyle plugin has now only one "filters" property which can be used to configured any number of SuppressionFilter, SuppressionCommentFilter and SuppresWithNearbyCommentFilter. Here is an example :
<module name="Checker">
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: magic number check off"/>
    <property name="onCommentFormat" value="CS\: magic number check on"/>
    <property name="checkFormat" value="MagicNumberCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: GUI members javadoc check off"/>
    <property name="onCommentFormat" value="CS\: GUI members javadoc check on"/>
    <property name="checkFormat" value="JavadocVariableCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: Getter/Setter javadoc check off"/>
    <property name="onCommentFormat" value="CS\: Getter/Setter javadoc check on"/>
    <property name="checkFormat" value="JavadocMethodCheck"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CS\: method length too long check off"/>
    <property name="onCommentFormat" value="CS\: method length too long check on"/>
    <property name="checkFormat" value="MethodLengthCheck"/>
  </module>
  <module name="SuppressWithNearbyCommentFilter">
    <property name="commentFormat" value="Ok to catch (\w+) here"/>
    <property name="checkFormat" value="IllegalCatchCheck"/>
    <property name="messageFormat" value="$1"/>
    <property name="influenceFormat" value="-1"/>
  </module>
</module>
Hide
Alexander Krist added a comment -

You are the best, i will take a look

thanks

Show
Alexander Krist added a comment - You are the best, i will take a look thanks
Hide
Bruno Pirrotta added a comment -

It seems good for me too

Show
Bruno Pirrotta added a comment - It seems good for me too
Hide
Michael Semb Wever added a comment -

i see (the fields hold all the fields within the xml).
nice. thanks Freddy.

Show
Michael Semb Wever added a comment - i see (the fields hold all the fields within the xml). nice. thanks Freddy.

People

Vote (3)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: