I have recently installed Sonar with the JavaScript Plugin, and have let the sonar-scanner analyze some sample projects. I started investigating the Duplications detection a litte closer. For one of my samples, I let Sonar scan the src/ folder of JQuery and received 0.0% Duplications in the Code. However, there are duplicates in the JQuery src Folder. For instance, the final lines in both src/core/ready.js and src/core/ready-no-deferred.js are:
// Catch cases where $(document).ready() is called
// after the browser event has already occurred.
// Support: IE <=9 - 10 only
// Older IE sometimes signals "interactive" too soon
if ( document.readyState === "complete" ||
( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
window.setTimeout( jQuery.ready );
} else {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", completed );
// A fallback to window.onload, that will always work
window.addEventListener( "load", completed );
}
} );
This is, in my purely subjective opinion, a pretty big duplicate, that should be noticed by a static code analysis. However, I am new to Sonar so I would like to know if anyone can reproduce this result or if I have made a misconfiguration somewhere. I did run other analyses that have detected Duplications and I have already included
# Rules
sonar.cpd.javascript.minimumTokens=5
sonar.cpd.javascript.minimumLines=3
in sonar-project.properties file, without any effect.