java 忽略无效问题的 NOSONAR 标记仍显示为问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39009247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:00:48  来源:igfitidea点击:

NOSONAR tag to ignore an invalid issue still shows as an issue

javasonarqubeguicesonarqube5.1sonarqube-scan

提问by mayooran

I have the below method which is showing a sonar issue saying the method is not used anywhere.

我有以下方法显示声纳问题,说明该方法未在任何地方使用。

@Provides
@ObjectMapperAnnotation
 public ObjectMapper provideObjectMapper() { //NOSONAR
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JsonOrgModule());
    return mapper;

}

But this is a method that is called by the guice library and I do not have to call it explicitly. So in order to compress this issue I used the NOSONAR tag as shown above. But it still is showing a major issue as shown below.

但这是由 guice 库调用的方法,我不必显式调用它。所以为了压缩这个问题,我使用了如上所示的 NOSONAR 标签。但它仍然显示一个主要问题,如下所示。

Is //NOSONAR used to exclude false-positive or to hide real quality flaw ? 

How can I avoid this issue being shown for using the NOSONAR tag? Any help would be much appreciated.

如何避免因使用 NOSONAR 标签而显示此问题?任何帮助将非常感激。

回答by Nicolas B. - SonarSource Team

Looks like the squid:NoSonarrule is activated in the Quality Profile used by this project, precisely to avoid developers silently marking stuff as NOSONARi.e. sweep problems under the carpet.

看起来鱿鱼:NoSonar规则在这个项目使用的质量配置文件中被激活,正是为了避免开发人员默默地将东西标记为NOSONAR,即在地毯下扫除问题。

Moving forward:

向前进:

  • let the original issue be raised in SonarQube (the one saying the method is not used anywhere)
  • discuss it with your team to be sure it's a false-positive
  • close it as False Positivein SonarQube (you can do that right form the UI when managing your issues)
  • get beer
  • 让原始问题在 SonarQube 中提出(那个说该方法不在任何地方使用的人
  • 与您的团队讨论以确保这是误报
  • 在 SonarQube 中将其关闭为False Positive(您可以在管理问题时从 UI 中正确执行此操作)
  • 喝啤酒