Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude JavaScript libraries from Sonar

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

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)?

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.

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

like image 645
opticyclic Avatar asked Aug 31 '12 19:08

opticyclic


People also ask

How do I exclude a package from sonar scan?

Specifying an exclusion means that everything under your sonar. sources directory will be included in analysis except the files with paths that match your exclusion pattern. To use exclusions to analyze everything but the specified files, go to Project Settings > General Settings > Analysis Scope > Files.

How do you use sonar exclusions?

Choosing Files To specify which files are are and are not included in an analysis go to Administration > General Settings > Analysis Scope > Files. Use exclusion to analyze everything but the specified files: sonar. exclusions - to exclude source code files.

How do you ignore sonar rules?

In Java, we can exclude Sonar checks using the built-in @SuppressWarnings annotation. This works exactly the same way as suppressing compiler warnings. All we have to do is specify the rule identifier, in this case java:S106.

What is sonar coverage exclusions?

sonar.exclusions will exclude mentioned files or directories from analysis. sonar.coverage.exclusions still exists and will exclude mentioned files or directories from code coverage like in question asked. But it's not mentioned in current documentation.


2 Answers

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

enter image description here

like image 54
Renzo Robles Avatar answered Oct 29 '22 01:10

Renzo Robles


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:

<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.

like image 33
Andrea Bergia Avatar answered Oct 28 '22 23:10

Andrea Bergia