Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sonar-javascript rules

XPath rules

undefined

undefined should not be assigned

``(//initialiser|//assignmentExpression)//unaryExpression//IDENTIFIER[@tokenValue="undefined"]```

var x = undefined; // bad
var x; // ok
x = undefined; // bad
if (x === undefined) { // ok*
    undefined = x; // totally NOT ok ;)
}

undefined should not be checked (in favor of == null)

//equalityExpression//unaryExpression//IDENTIFIER[@tokenValue="undefined"]

var x = null, y = x;
if (x === undefined) { // bad, falls trough
    x = y;
} else if (x == null) { // ok
    x = y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.