Java checkstyle, MagicNumberCheck

I use checkstyle to get reports on my source code. This question is about MagicNumberCheck .

I use Date/(org.joda.)DateTimein my source code as follows:

DateTime dateTime = new DateTime(2013, 2, 27, 23, 0):
dateTime.plusHours(57);

Is there a way to suppress MagicNumberCheck notifications if the magic number is within a date or date?

+5
source share
2 answers

To do this, you can use SuppressionCommentFilter .

Set property values ​​similar (in your checkstyle configuration file )

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

Now for the required lines you can do, for example,

//Check:OFF: MagicNumber
DateTime dateTime = new DateTime(2013, 2, 27, 23, 0):
dateTime.plusHours(57);
//Check:ON: MagicNumber

MagicNumber checks, .

,

//Check:OFF: MagicNumber|Indentation
Code Here
//Check:ON: MagicNumber|Indentation

MagicNumber and Indentation Checks. .

+14

CheckStyle,

//CHECKSTYLE:OFF

//CHECKSTYLE:ON

.

SuppressionCommentFilter.

, , , .

+2

All Articles