How do I Suppress Warnings in CheckStyle?

Tom Tresansky picture Tom Tresansky · Aug 25, 2010 · Viewed 33.9k times · Source

I'm using the CheckStyle plugin for Eclipse.

It's great at finding things I didn't intend 99% of the time, but the 1% of the time I actually did intend to knowingly violate a rule, I would like to let CheckStyle know it need not concern itself with flagging a warning.

Example: the Missing a Javadoc comment rule. Most of the time I want Javadoc comments on my methods. However, a method such as:

public boolean isValid() {
  return valid;
}

can probably get by without one.

Is there anything like the @SuppressWarnings annotation which can be used to flag a specific CheckStyle rule violation as acceptable? Some sort of specially formatted comment, maybe? I don't want to disable the rule, I just want to ignore a specific violation.

(I realize in this case I could just write the Javadoc comment, but in other cases fixing the rule violation isn't so simple).

Answer

Aaron picture Aaron · Aug 4, 2011

PhiLho is right - SuppressWithNearbyCommentFilter or SuppressionCommentFilter can help. I have SuppressionCommentFilter configured and adding the comments "CHECKSTYLE:OFF" and "CHECKSTYLE:ON" will disable check style temporarily.