How to SuppressWarnings for 'common-java' rules

倖福魔咒の 提交于 2021-02-19 00:45:27

问题


I need to temporary ignore rule "Insufficient branch coverage by unit tests" (common-java:InsufficientBranchCoverage).

Reading http://docs.sonarqube.org/display/SONAR/Frequently+Asked+Questions I see that SuppressWarnings should work for all rules.

But any combination of

@SuppressWarnings("common-java:InsufficientBranchCoverage")
@SuppressWarnings("InsufficientBranchCoverage")
@SuppressWarnings("java:InsufficientBranchCoverage")

does not work for me.

I use Sonar 5.0, Sonar Java plugin 3.0.

Edit:

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

  • 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.


回答1:


Unfortunately, it is not possible.

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).

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).



来源:https://stackoverflow.com/questions/29343389/how-to-suppresswarnings-for-common-java-rules

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!