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).
As explained in this post, you can use a regular expression that matches anything but
unchecked
by configuring the check like this: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.