Javascript equivalent to @SuppressWarnings?

I am currently running Sonar to statically analyze my code. When I analyzed java files and wanted to suppress a specific warning, I used the @SuppressWarnings (nameOfTheWarningOnSonar) annotation. I wanted to know if there was a simple equivalent in Javascript to suppress specific sonar warnings.

+5
source share
2 answers

Well, the easiest way:

Fix what the sonar says :)

but suppose it is false positive.

The following is a list of possible solutions to this problem:

From November 2014: tag support

// NOSONAR the code who display Sonar error 

now fully supported by JavaScript validation (thanks @ RPallas )

If you don't control sonar: a pretty ugly method

 try { the code who display Sonar error } catch(err) { } 

If you catch any possible problem, Sonar will not be able to detect something (thanks @ JavaScript ).

But the best way is to definitely reconfigure Sonar:

When you control Sonar: add a plugin

To use the CheckStyle plugin on Sonar: ( http://checkstyle.sourceforge.net/ )

The solution is to add a structured Checkstyle comment to the intruder class to suppress a particular check.

The required format for suppressing comments (SuppressionCommentFilter) is as follows:

 //CHECKSTYLE:OFF the code who display Sonar error //CHECKSTYLE:ON 

But I am sending you to the documentation of this plugin ( http://checkstyle.sourceforge.net/config.html )

Hope this answer helps.

+4
source

You can put // NOSONAR in a string, causing a warning.

+2
source

All Articles