DescriptionAdds Linter.java and a build rule that runs sanity checks on our
client-side JS.
The linter looks for @requires, @provides, and @overrides comment
annotations in each JS file and comes up with a set of globals that
the file is allowed to read/write.
It then applies a ScopeAnalyzer to map nodes to the scopes that
contain them. The ScopeAnalyzer has a few overrideable methods,
and so can support a wide variety of scoping models including
(1) ES3.1 scoping rules plus let and const
(2) ES3 scoping
(3) ES3 scoping with IE quirks
(4) Block scoping as understood by the naive JS programmer.
The scoping rules used by Linter are javascript standard, with one
added constraint.
Variables may not be re-declared, unless all re-declarations occur in
mutually-disjoint loops. This catches errors like
var i = 1;
if (...) {
...
for (var i = 0; ... ) // Deeply nested loop
...
}
return i;
but allows the common idiom whereby loop iterators are reused within a loop
for (var i = 0; ...) { ... }
for (var i = 0; ...) { ... }
This works because the below is banned
for (var i = 0; ...) { .. .}
return i;
since a variable declared in a loop can only be used in the loop.
Once scopes are assigned, a VariableLiveness instance walks the
tree figuring out the conservative set of variables which might
be live at any point in the program.
The scoping and liveness data is used to check for common scoping
and namespace violation bugs.
The Linter also identifies expressions that are typically used as
expressions but which appear in a statement context.
So
{
a;
+b;
}
is flagged because the operator + is normally evaluated for its value,
but the value is ignored in this case.
I included &&, ||, and ?: in the set of expressions typically
evaluated for their value.
So
condition && side_effecting_expression();
should instead be written as
if (condition) { side_effecting_expression(); }
This change also includes cleanup and fixes of our supporting JS
to make it lint clean, and adds an ANT build rule that runs the
linter over our supporting JS when tests are built.
Submitted @3808
Patch Set 1 #Patch Set 2 : A lint tool for javascript. #Patch Set 3 : A lint tool for javascript. #Patch Set 4 : A lint tool for javascript. #Patch Set 5 : A lint tool for javascript. #Patch Set 6 : A lint tool for javascript. #Patch Set 7 : A lint tool for javascript. #Patch Set 8 : A lint tool for javascript. #Patch Set 9 : A lint tool for javascript. #Patch Set 10 : A lint tool for javascript. #Patch Set 11 : A lint tool for javascript. #Patch Set 12 : A lint tool for javascript. #Patch Set 13 : A lint tool for javascript. #Patch Set 14 : A lint tool for javascript. #Patch Set 15 : A lint tool for javascript. #Patch Set 16 : A lint tool for javascript. #Patch Set 17 : A lint tool for javascript. #Patch Set 18 : A lint tool for javascript. #Patch Set 19 : A lint tool for javascript. #Patch Set 20 : A lint tool for javascript. #Patch Set 21 : A lint tool for javascript. #Patch Set 22 : A lint tool for javascript. #Patch Set 23 : A lint tool for javascript. #Patch Set 24 : A lint tool for javascript. #Patch Set 25 : A lint tool for javascript. #Patch Set 26 : A lint tool for javascript. #Patch Set 27 : A lint tool for javascript. #Patch Set 28 : A lint tool for javascript. #Patch Set 29 : A lint tool for javascript. #
Total comments: 2
MessagesTotal messages: 5
|