2

With the SuppressWarnings check I'm able to specify what warning can not be suppressed. So in order not to allow unchecked suppressions:

<module name="SuppressWarnings">
  <property name="format" value="^unchecked$"/>
</module>

I try to do the opposite - I want to forbid all suppressions except unchecked. I tried:

<module name="SuppressWarnings">
  <property name="format" value="[^(unchecked)]"/>
</module>

But it doesn't work (it neither detects unchecked nor any other suppressions).

fracz
  • 20,536
  • 18
  • 103
  • 149

1 Answers1

1

As explained in this post, you can use a regular expression that matches anything but unchecked by configuring the check like this:

<module name="SuppressWarnings">
    <property name="format" value="^(?!unchecked).*$"/>
</module>

This regex construct is called a "zero-width negative lookahead". It is kind of cludgy to use; it would have been better if Checkstyle included an option to configure if you want a whitelist or a blacklist. But well, this works, too.

Community
  • 1
  • 1
barfuin
  • 16,865
  • 10
  • 85
  • 132
  • I needed to allow both `unchecked` and `nls` suppressions, so I used the `^(?!(unchecked)|(nls)).*$` pattern. Thank you. – fracz Nov 14 '14 at 23:09