如何使用Intellij SonarLint插件抑制特定方法的警告

时间:2017-11-18 18:23:22

标签: intellij-idea sonarlint sonarlint-intellij

我想抑制一些方法的Sonar lint插件警告, 这个问题不是我想要的Intellij SonarLint 2.3 - ignore rule

目前我必须使用@SuppressWarnings("all")注释该方法,这会禁止所有警告。

2 个答案:

答案 0 :(得分:23)

您可以使用//NOSONAR@SuppressWarnings(),但需要指定规则。

来自SonarQube documentation

  

//NOSONAR标记可用于停用给定行的所有规则   但不适合停用所有规则(或仅限给定规则)   方法或类的所有行。这就是为什么支持   SonarQube已添加@SuppressWarnings("all")

     

SINCE 2.8 of Java Plugin,你也可以使用@SuppressWarnings   带有规则键列表的注释:

     

@SuppressWarnings("squid:S2078")或   @SuppressWarnings({"squid:S2078", "squid:S2076"})

答案 1 :(得分:2)

您可以自行在编辑器中取消检查,

enter image description here

请参阅https://www.jetbrains.com/help/idea/disabling-and-enabling-inspections.html,它有多种方法可以完成此操作,有许多方法可以自定义所需的行为。