为某些代码关闭声纳 [英] Turning Sonar off for certain code
问题描述
是否可以关闭特定代码块的声纳 (www.sonarsource.org) 测量,其中不想被测量?
Is it possible to turn off sonar (www.sonarsource.org) measurements for specific blocks of code, which one doesn't want to be measured?
一个例子是 Findbugs 输出的保留堆栈跟踪"警告.当离开服务器时,我可能只想将消息传递回客户端,不包括我刚刚捕获的实际异常,如果客户端不知道该异常(因为客户端没有包含该异常的 JAR)例如,包含异常).
An example is the "Preserve Stack Trace" warning which Findbugs outputs. When leaving the server, I might well want to only pass the message back to the client, not including the actual exception which I just caught, if that exception is unknown to the client (because the client doesn't have the JAR in which that exception was contained for example).
推荐答案
这是一个常见问题解答.您可以将 //NOSONAR
放在触发警告的行尾.
This is a FAQ. You can put //NOSONAR
at the end of the line triggering the warning.
//NOSONAR
对于大多数语言,SonarQube 支持使用通用机制://NOSONAR
在问题行的末尾.这将抑制现在和将来可能在线提出的所有问题.
For most languages, SonarQube supports the use of the generic mechanism: //NOSONAR
at the end of the line of the issue. This will suppress all issues - now and in the future - that might be raised on the line.
不过,我更喜欢使用 FindBugs 机制,其中包括添加 @SuppressFBWarnings 注释:
I prefer using the FindBugs mechanism though, which consists in adding the @SuppressFBWarnings annotation:
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value = "NAME_OF_THE_FINDBUGS_RULE_TO_IGNORE",
justification = "Why you choose to ignore it")
这篇关于为某些代码关闭声纳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!