Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to suppress the Sonar lint plugin warning for some methods, this question is not what I want Intellij SonarLint 2.3 - ignore rule.

Currently I have to annotate the method with @SuppressWarnings("all"),which suppresses all warnings.

like image 353
aristotll Avatar asked Nov 18 '17 18:11

aristotll


People also ask

How do I turn off SonarLint warning?

You can use //NOSONAR or @SuppressWarnings() but you need to specify the rule. From the 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.

How do I turn off SonarLint rule in IntelliJ?

Regarding the highlighting issue: You need to go to Settings > Editor > SonarLint, then click on "Info issue", disable "Inherit values from" and set your preferred error stripe mark.

How do I set SonarLint rules in IntelliJ?

In Intellij — Go to File >> Plugins >> Type 'SonarLint' >> Install and Restart IDE. (2) we can choose the SonarQube rules. → To integrate SonarQube(server) and SonarLint in our IDE and run SonarQube code inspection rules per class to give results quickly. Add the sonarQube connection binding.


2 Answers

You can use //NOSONAR or @SuppressWarnings() but you need to specify the rule.

From the 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"}).

like image 53
syncdk Avatar answered Sep 28 '22 08:09

syncdk


You can Suppress an inspection in the editor it-self,

enter image description here

Refer to https://www.jetbrains.com/help/idea/disabling-and-enabling-inspections.html, It has various methods to get this done, there are many ways to customize the required behaviors.

like image 27
prime Avatar answered Sep 28 '22 10:09

prime