How to SuppressWarnings for #39;common-java#39; rules(如何抑制“common-java规则的警告)
问题描述
我需要暂时忽略规则单元测试的分支覆盖率不足"(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"规则的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何抑制“common-java"规则的警告
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01