Re: False postive for javascript:S2392

23 views
Skip to first unread message
Message has been deleted

alix....@gmail.com

unread,
Sep 20, 2017, 7:17:16 AM9/20/17
to SonarQube


Den onsdag 20 september 2017 kl. 13:16:35 UTC+2 skrev alix....@gmail.com:
Hi,

I'd like to report an issue with rule "Variables should be defined in the blocks where they are used" (javascript:S2392).

This code example illustrates the problem:

// Triggers javascript:S2392
let a
, b;


// Doesn't trigger javascript:S2392
// let a = null;
// let b = null;


for (let i = 0; i < 3; i++) {
 
if (i === 1) {
     a
= true;
 
}
 
if (i === 2) {
     b
= true;
 
}
 
if (a && b) {
    console
.debug('same');
 
}
}


Following the recommendation by the rule description and move cylA and cylB declarations into the loop would result in changed behavior as both values would then be recomputed every iteration. Therefore I thinks it's a false positive and not a false negative.

Regards Alix

alix....@gmail.com

unread,
Sep 20, 2017, 7:19:57 AM9/20/17
to SonarQube
'cylA' and 'cylB' is 'a' and 'b'.
Sorry for the confusion. Not possible to edit posts here...

carlo.bo...@sonarsource.com

unread,
Sep 20, 2017, 7:51:23 AM9/20/17
to SonarQube
Hello Alix,
it does look like a FP to me, would you like to report it on SonarJS' github issues? https://github.com/SonarSource/sonar-javascript/issues

Cheers,

Carlo

alix....@gmail.com

unread,
Sep 20, 2017, 8:17:41 AM9/20/17
to SonarQube
Certainly.

/Alix
Reply all
Reply to author
Forward
0 new messages