25

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.

dur
  • 15,689
  • 25
  • 79
  • 125
opticyclic
  • 7,412
  • 12
  • 81
  • 155

3 Answers3

31

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

dur
  • 15,689
  • 25
  • 79
  • 125
Renzo Robles
  • 684
  • 6
  • 10
17

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.

dur
  • 15,689
  • 25
  • 79
  • 125
Andrea Bergia
  • 5,502
  • 1
  • 23
  • 38
-7

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

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

alert('Your Javascript is working!');

/*--*//*]]>*/
</script>
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • 2
    I don't want to modify the JS library that I am using. I am really looking for config in Sonar to do this. Probably via the build mechanism somehow. – opticyclic Sep 03 '12 at 14:22