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

问题描述 投票:0回答:2

我想抑制某些方法的 Sonar lint 插件警告。
这个问题不是我想要的 Intellij SonarLint 2.3 - 忽略规则

目前我必须用

@SuppressWarnings("all")
注释该方法,这会抑制所有警告。

intellij-idea sonarlint sonarlint-intellij
2个回答
130
投票

您可以使用

//NOSONAR
@SuppressWarnings()
,但需要指定规则。

来自 SonarQube 文档

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

从 Java Plugin 2.8 开始,您还可以使用

@SuppressWarnings
带有规则键列表的注释:

@SuppressWarnings("squid:S2078")

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


0
投票

您可以在编辑器中自行禁止检查,

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

© www.soinside.com 2019 - 2024. All rights reserved.