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

How to suppress warning for a specific method with Intellij SonarLint plugin

我想抑制某些方法的 Sonar lint 插件警告, 这个问题不是我想要的.

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

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

来自 SonarQube documentation:

The //NOSONAR tag is useful to deactivate all rules at a given line but is not suitable to deactivate all rules (or only a given rule) for all the lines of a method or a class. This is why support for @SuppressWarnings("all") has been added to SonarQube.

SINCE 2.8 of Java Plugin, you can also use @SuppressWarnings annotation with a list of rule keys:

@SuppressWarnings("squid:S2078")

or

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

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

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