问题描述
我需要暂时忽略规则单元测试的分支覆盖率不足"(common-java:InsufficientBranchCoverage).
I need to temporary ignore rule "Insufficient branch coverage by unit tests" (common-java:InsufficientBranchCoverage).
阅读 http://docs.sonarqube.org/display/SONAR/Frequently+Asked+Questions 我看到 SuppressWarnings
应该适用于所有规则.
Reading http://docs.sonarqube.org/display/SONAR/Frequently+Asked+Questions I see that SuppressWarnings
should work for all rules.
但任何组合
@SuppressWarnings("common-java:InsufficientBranchCoverage")
@SuppressWarnings("InsufficientBranchCoverage")
@SuppressWarnings("java:InsufficientBranchCoverage")
对我不起作用.
我使用 Sonar 5.0,Sonar Java 插件 3.0.
I use Sonar 5.0, Sonar Java plugin 3.0.
此警告可能会从声纳 UI 中被抑制(删除).我看到了两种解决方案
This warning may be supressed (removed) from sonar UI. I see two solutions
为我的质量配置文件禁用单元测试的分支覆盖率不足"规则.缺点是整个项目都禁用了该规则,而不仅仅是单个类
disable the rule 'Insufficient branch coverage by unit tests' for my quality profile. The drawback is, that rule is disabled for whole project, not just for single class
在深入浏览问题时将问题标记为已忽略.这只会忽略问题的单一出现.缺点是,需要在每个声纳项目中标记问题(我们有每个分支的项目).当我需要删除警告时,我必须在声纳 UI 中为每个项目再次执行此操作.
mark issue as ignored when browsing issues drilldown. This ignores only single occurence of the issue. The drawback is, issue need to be marked in every sonar project (we have project-per-branch). When I need to remove warning, I must do this in sonar UI again, for each project.
推荐答案
很遗憾,这是不可能的.
Unfortunately, it is not possible.
InsufficientBranchCoverage
规则直接应用于文件级别,因此它不链接到文件中的任何特定行.要使用 @SuppressWarnings
删除与给定规则键相关的问题,该规则必须在类或方法级别应用(您可以在文档中阅读).
The InsufficientBranchCoverage
rule applies directly at File level and it is consequently not linked to any particular line in the file. To remove issues related to a given rule key using @SuppressWarnings
, the rule has to apply at Class or Method level (as you can read in the documentation).
请注意,为了保证分析结果的一致性,我们不能在文件级别禁用问题,因为它可能会以隐藏本来完全合法的问题而告终(例如 java
文件有多个类).
Note that to guarantee consistency of the results of the analysis, we can not disable the issue at File level, as it may end by hiding issues which would have been perfectly legit (take for instance the situation of a java
file having multiple classes).
这篇关于如何抑制“common-java"规则的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!