Skip to content

Instantly share code, notes, and snippets.

@croensch
Last active August 29, 2015 14:05
Show Gist options
  • Save croensch/5424bc6fc3024d94bf1f to your computer and use it in GitHub Desktop.
Save croensch/5424bc6fc3024d94bf1f to your computer and use it in GitHub Desktop.
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