@SuppressWarnings 的 Javascript 等价物? [英] Javascript equivalent of @SuppressWarnings?

查看:70
本文介绍了@SuppressWarnings 的 Javascript 等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在运行 Sonar 以对我的代码进行静态分析.当我分析 java 文件并想抑制某个警告时,我使用了 @SuppressWarnings(nameOfTheWarningOnSonar) 注释.我想知道 Javascript 中是否有一个简单的等价物来抑制 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.

推荐答案

嗯,最简单的方法是肯定的:

Well, the easiest way is for sure :

纠正 Sonar 所说的内容 :)

但让我们假设它是误报.

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

以下是解决此问题的可能方法列表:

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

自 2014 年 11 月起: 标签支持

// NOSONAR
the code who display Sonar error

现在完全支持 JavaScript 检查(感谢@RPallas)

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

当你不控制声纳时: 相当丑陋的方法

try {

  the code who display Sonar error     

} catch(err) { }

如果您发现任何可能的问题,Sonar 将无法检测到某些东西(感谢 @JavaScript).

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 :

当您控制 Sonar 时: 添加插件

在 Sonar 上使用 CheckStyle 插件:(http://checkstyle.sourceforge.net/)

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

解决方案是向违规类添加 Checkstyle 结构化注释以禁止特定检查.

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

需要的抑制评论(SuppressionCommentFilter)格式是这样的:

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

//CHECKSTYLE:OFF

     the code who display Sonar error    

//CHECKSTYLE:ON

但是我把你送到这个插件的文档(http://checkstyle.sourceforge.net/config.html)

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

我希望这个答案会有所帮助.

I hope this answer helps.

这篇关于@SuppressWarnings 的 Javascript 等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆