从声纳中排除 JavaScript 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12221770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:37:56  来源:igfitidea点击:

Exclude JavaScript libraries from Sonar

javascriptsonarqube

提问by opticyclic

If you look at this site analysing JavaScript with Sonar you see that there are lots of errors reported on the JavaScript libraries.

如果您查看使用 Sonar 分析 JavaScript 的站点,您会发现 JavaScript 库报告了很多错误。

http://nemo.sonarsource.org/drilldown/violations/jquery?rids%5B%5D=421365&severity=MAJOR

http://nemo.sonarsource.org/drilldown/violations/jquery?rids%5B%5D=421365&severity=MAJOR

How can I prevent Sonar reporting the errors in the JavaScript libraries that I am using (since I can't fix any issues)?

如何防止声纳报告我正在使用的 JavaScript 库中的错误(因为我无法解决任何问题)?

At the same time, if I do manage to exclude the library, I don't want errors like "undefined variables" to appear in my files because they are referencing the JavaScript library.

同时,如果我确实设法排除了该库,我不希望我的文件中出现诸如“未定义变量”之类的错误,因为它们引用了 JavaScript 库。

If it makes any difference, I am using ExtJS 4.0.

如果有什么不同,我使用的是 ExtJS 4.0。

采纳答案by Andrea Bergia

I am using Maven and ExtJS 4.1 in my project. I have managed to run the analysis only on my source code by putting these lines in my pom.xml:

我在我的项目中使用 Maven 和 ExtJS 4.1。通过将这些行放在我的中,我设法仅在我的源代码上运行分析pom.xml

<properties>
    <sonar.language>js</sonar.language>
    <sonar.exclusions>extjs/**</sonar.exclusions>
</properties>

<build>
    <sourceDirectory>src/main/webapp</sourceDirectory>
</build>

I don't know whether you're using Maven as well, but perhaps this will give you some hints.

我不知道您是否也在使用 Maven,但也许这会给您一些提示。

回答by Renzo Robles

You can add the library as a source file exclusion inside of Analysis Scopeconfiguration, and you should use some willcards to help you.

您可以将库添加为分析范围配置中的源文件排除项,并且您应该使用一些遗嘱来帮助您。

enter image description here

在此处输入图片说明

回答by Diodeus - James MacFarlane

Often you can hide your JavaScript from other interpreters using a cdata wrapper:

通常,您可以使用 cdata 包装器对其他解释器隐藏您的 JavaScript:

<script type="text/javascript">
/*<![CDATA[*//*---->*/

alert('Your Javascript is working!');

/*--*//*]]>*/
</script>