最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sonarqube - Javascript equivalent of @SuppressWarnings? - Stack Overflow

programmeradmin5浏览0评论

I am currently running Sonar for the static analysis of my code. When I was analyzing java files and wanted to suppress a certain warning, I used the @SuppressWarnings(nameOfTheWarningOnSonar) annotation. I wanted to know if there was a simple equivalent in Javascript to suppress specific warnings on Sonar.

I am currently running Sonar for the static analysis of my code. When I was analyzing java files and wanted to suppress a certain warning, I used the @SuppressWarnings(nameOfTheWarningOnSonar) annotation. I wanted to know if there was a simple equivalent in Javascript to suppress specific warnings on Sonar.

Share Improve this question edited Jan 13, 2019 at 15:44 Cœur 38.7k26 gold badges202 silver badges277 bronze badges asked Jul 9, 2015 at 14:11 ProPhilProPhil 2671 gold badge3 silver badges11 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 9

You can put // NOSONAR on the line triggering the warning.

Well, the easiest way is for sure :

Correct what Sonar is saying :)

but let's assume that it's false positive.

Here are the list of possible method to fix this issue :

Since November 2014 : tag support

// NOSONAR
the code who display Sonar error

is now fully supported by the JavaScript check (thanks @RPallas)

When you don't control the Sonar : quite ugly method

try {

  the code who display Sonar error     

} catch(err) { }

If you catch any possible problem, Sonar can't detect something (thanks @JavaScript).

But the best way is for sure to modify the configuration of Sonar :

When you control Sonar : add a plugin

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

The solution will be to add a Checkstyle structured comment to the offending class to suppress a particular check.

The suppression comment (SuppressionCommentFilter) format required is like this:

//CHECKSTYLE:OFF

     the code who display Sonar error    

//CHECKSTYLE:ON

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

I hope this answer helps.

发布评论

评论列表(0)

  1. 暂无评论