[javascriptlint-commit] SF.net SVN: javascriptlint:[380] trunk
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2018-06-10 05:46:18
|
Revision: 380
http://sourceforge.net/p/javascriptlint/code/380
Author: matthiasmiller
Date: 2018-06-10 05:46:15 +0000 (Sun, 10 Jun 2018)
Log Message:
-----------
Add a warning against invalid ! usage
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
trunk/tests/warnings/for_in_missing_identifier.js
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2018-01-02 22:12:15 UTC (rev 379)
+++ trunk/javascriptlint/lintwarnings.py 2018-06-10 05:46:15 UTC (rev 380)
@@ -107,6 +107,7 @@
'e4x_deprecated': 'e4x is deprecated',
'ambiguous_numeric_prop': 'numeric property should be normalized; use {normalized}',
'duplicate_property': 'duplicate property in object initializer',
+ 'ambiguous_not': 'the ! operator is ambiguous; use clarifying parentheses'
}
errors = {
@@ -686,6 +687,16 @@
return # Allow as constructors
raise LintWarning(node)
+@lookfor((tok.UNARYOP, op.NOT))
+def ambiguous_not(node):
+ # Avoid for(!s in o)
+ if node.parent and node.parent.kind == tok.IN:
+ raise LintWarning(node)
+
+ # Avoid use in comparisons.
+ if node.parent and node.parent.kind in (tok.EQOP, tok.RELOP):
+ raise LintWarning(node)
+
def _get_function_property_name(node):
# Ignore function statements.
if node.opcode in (None, op.CLOSURE):
Modified: trunk/tests/warnings/for_in_missing_identifier.js
===================================================================
--- trunk/tests/warnings/for_in_missing_identifier.js 2018-01-02 22:12:15 UTC (rev 379)
+++ trunk/tests/warnings/for_in_missing_identifier.js 2018-06-10 05:46:15 UTC (rev 380)
@@ -7,6 +7,6 @@
for (var prop2 in o)
o[prop2]++;
- for (!prop in o) /*warning:for_in_missing_identifier*/
+ for (!prop in o) /*warning:for_in_missing_identifier*/ /*warning:ambiguous_not*/
o[prop]++;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|