【问题标题】:Exclude sonar rules排除声纳规则
【发布时间】:2014-01-29 14:02:30
【问题描述】:

有没有办法用 Java 代码排除声纳(4.0 版)规则?

我在我的课上使用:

@SuppressWarnings("all")

但声纳并没有解决所有问题,我们仍然有:

  • 正确性 - 类定义了掩盖超类字段的字段
  • 代码重复问题

我错过了什么?

编辑:On sonar docs SuppressWarnings 停用所有规则,但对我不起作用。这个注解只是去掉了一些规则。

【问题讨论】:

标签: java sonarqube code-duplication


【解决方案1】:

您可能需要参考此FAQ 以获得一些想法。此外,正如this question 中所建议的,您可以使用以下代码:

@edu.umd.cs.findbugs.annotations.SuppressWarnings(
    value = "NAME_OF_THE_FINDBUGS_RULE_TO_IGNORE",
    justification = "Why you choose to ignore it")

【讨论】:

  • 为什么不使用 java.lang.@SuppressWarnings("all") ?
  • 好吧,因为它被 Find Bugs(声纳所依赖的)忽略了。
【解决方案2】:

感谢@ArnaudPotier 和@AlexanderGavrilov

回答我自己的帖子:

有没有办法用 Java 代码排除声纳(4.0 版)规则?

可以,但需要声纳配置:http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus#NarrowingtheFocus-IgnoreIssues

  • 添加的文件正则表达式:javax\.annotation\.Generated
  • 类注释:@Generated(value = { "someValue" })

java.lang.@SuppressWarnings("all") 不适用于所有问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    • 2013-04-30
    • 1970-01-01
    • 2018-10-31
    相关资源
    最近更新 更多