javascript:S905 Fails to track side effects of setting properties

A common pattern in the project I’m analyzing right now is to define object functions in instantly called functions.

function TheClass() { /* init */ }
!function() {
    TheClass.prototype.whatever = TheClass_whatever;
    function TheClass_whatever() { /* things here */ }
}();

After each such block an S905 bug is raised, despite the code having side effects.

Hi,

Which version of SonarJS are you using?
Analyzer should not report when parentheses are used:

function TheClass() { /* init */ }
(function() {
    TheClass.prototype.whatever = TheClass_whatever;
    function TheClass_whatever() { /* things here */ }
}());

This is the SonarQube Scanner 4.2.0.1873 windows package, connecting to a 8.1 server.

So as a workaround you can use () instead of !.
Ticket to support your case -> https://github.com/SonarSource/SonarJS/issues/1931

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.