在全局范围内禁止 Spotbugs 警告

huangapple go评论59阅读模式
英文:

Suppress Spotbugs warnings globally

问题

我从spotbugs得到了一个警告。这个警告在所有那些文件中都被@SuppressFBWarnings所抑制。
我需要找到一种方法从一个地方来抑制这个警告,这样我就不必在该包中的每个文件中使用@SuppressFBWarnings。

英文:

I have one warning from spotbugs. This is suppressed with @SuppressFBWarnings in all those files.
I need to find a way to suppress this from one place so that I don't have to @SuppressFBWarnings in each file in that package.

答案1

得分: 4

你可以使用一个过滤器文件

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
  <Class name="my.package.*" />
</Match>
</FindBugsFilter>

这个文件可以作为命令行参数-exclude传递给 SpotBugs,或者如果你正在使用集成开发环境(IDE),可能可以在某个地方配置以供使用。

当你想要排除第三方代码或生成的代码时,这是非常有用的,因为你无法从一开始就添加注释。但它还有助于将 SpotBugs 的配置与代码分开。

还要注意name属性可以是一个正则表达式。

英文:

You can use a filter file

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;FindBugsFilter&gt;
&lt;Match&gt;
  &lt;Class name=&quot;my.package.*&quot; /&gt;
&lt;/Match&gt;
&lt;/FindBugsFilter&gt;

This file can be given to spotbugs as command line argument -exclude, or if you are using an IDE it probably can be configured to be used somewhere.

This is especially useful when you want to exclude third-party code, or generated code, where you can't add the annotation to begin with. But it also helps separate the spotbugs configuration and the code.

Also note the name attribute can be a regular expression.

huangapple
  • 本文由 发表于 2020年8月20日 22:45:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63507614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定