SonarJS
SonarJS copied to clipboard
Fix FN S2259 (`null-dereference`): when property is called `length`
We don't detect the issue for S2259 (null-dereference) when property is called length
var x;
if (x === undefined) {
console.log(x.length); // FN
}
Hi @saberduck , any update on this? I'd like to add that this issue not only happens with .length, Sonarlint doesn't detect not declared variables either. Example: var x; if (x === undefined) { console.log(x); // FN console.log(asdf); // Should be detected too } This is a big issue for me since we are trying to use this as a standard in the team, but seems to be not possible atm. Thanks.
For this reproducer:
let x;
if (x === undefined) {
x.length; // FN
}
For some reason, isUndefinedOrNull() returns false
for x
at line 3 when the property is .length
, and true
when it's anything else. So it breaks the function of the CheckNullDereference() function.