[javascriptlint-commit] SF.net SVN: javascriptlint:[315] trunk
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2013-09-28 05:00:33
|
Revision: 315
http://sourceforge.net/p/javascriptlint/code/315
Author: matthiasmiller
Date: 2013-09-28 05:00:30 +0000 (Sat, 28 Sep 2013)
Log Message:
-----------
Warn against multiple useless comparison (e.g. a == a == b)
Modified Paths:
--------------
trunk/javascriptlint/warnings.py
trunk/tests/warnings/useless_comparison.js
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2013-09-28 04:50:25 UTC (rev 314)
+++ trunk/javascriptlint/warnings.py 2013-09-28 05:00:30 UTC (rev 315)
@@ -14,6 +14,7 @@
if questionable:
raise LintWarning, node
"""
+import itertools
import re
import sys
import types
@@ -287,9 +288,9 @@
@lookfor(tok.EQOP,tok.RELOP)
def useless_comparison(node):
- lvalue, rvalue = node.kids
- if lvalue.is_equivalent(rvalue):
- raise LintWarning, node
+ for lvalue, rvalue in itertools.combinations(node.kids, 2):
+ if lvalue.is_equivalent(rvalue):
+ raise LintWarning, node
@lookfor((tok.COLON, op.NAME))
def use_of_label(node):
Modified: trunk/tests/warnings/useless_comparison.js
===================================================================
--- trunk/tests/warnings/useless_comparison.js 2013-09-28 04:50:25 UTC (rev 314)
+++ trunk/tests/warnings/useless_comparison.js 2013-09-28 05:00:30 UTC (rev 315)
@@ -52,4 +52,12 @@
if (useless_comparison() == useless_comparison()) {
return;
}
+
+ // Test multiple comparisons.
+ if (i == i == 3) /*warning:useless_comparison*/
+ return;
+ if (i == 3 == i) /*warning:useless_comparison*/
+ return;
+ if (i == 3 == j == 3) /*warning:useless_comparison*/
+ return;}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|