Javascript equivalent of @SuppressWarnings?

馋奶兔 提交于 2020-01-24 04:46:11

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/31320062/javascript-equivalent-of-suppresswarnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!