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