Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Orion/ESLint"

(Nice to have)
(80 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Orion 5.0 will replace our current JSLint validator with [https://github.com/nzakas/eslint/ ESLint]. This page captures ongoing issues.
+
Orion 5.0 moved to [https://github.com/nzakas/eslint/ ESLint] as the validator that ships with Orion. This page captures ongoing issues.
  
== Rule parity ==  
+
== Rules ==  
Here's a table showing the equivalent validation rules in JSLint and ESLint. Rules that JSLint does not support are marked as Unsupported.  
+
The following table describes all of the rules currently available in Orion and ones that we plan to add in the future.
  
{| class="wikitable" border="1" style="width: 100%;"
+
Rules that are currently available are <del>struck out</del>.
! ESLint rule
+
 
! JSLint option
+
{| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
! JSLint message
+
! style="background:#efefef;" width=5% | Rule
! Details
+
! style="background:#efefef;" width=5% | Default Severity
 +
! style="background:#efefef;" width=5% | Available Since
 +
! style="background:#efefef;" width=40%| Problem Message
 +
! style="background:#efefef;" width=40% | Details
 
|-
 
|-
  
| block-scoped-var
+
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428433 block-scoped-var]
| Always on
+
| Error
 +
| -
 
| '''{variable}' is already defined.''
 
| '''{variable}' is already defined.''
 
|
 
|
Line 19: Line 23:
 
|-
 
|-
  
| brace-style
+
!| brace-style
| Unsupported
+
| Ignore
|  
+
| -
|  
+
| &nbsp;
 +
| &nbsp;
 
|-
 
|-
  
| camelcase
+
!| camelcase
| Unsupported
+
| Ignore
|  
+
| -
|  
+
| &nbsp;
 +
| &nbsp;
 
|-
 
|-
  
| complexity
+
!| complexity
| Unsupported
+
| Ignore
|   
+
-
|  
+
| &nbsp;
 +
| &nbsp;
 
|-
 
|-
  
| consistent-this
+
!| consistent-this
| Unsupported
+
| Ignore
|   
+
-
|  
+
| &nbsp;
 +
| &nbsp;
 
|-
 
|-
  
| curly
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429722 curly]</del>
| Always on
+
| Ignore
|
+
| 6.0
* ''Statement body should be inside '{ }' braces.'' (Orion)
+
| ''Statements should be enclosed in braces.''
* ''Expected '{'.'' (Regular JSLint)
+
| &nbsp;
|  
+
 
|-
 
|-
  
| dot-notation
+
!| dot-notation
| '''sub'''
+
| Warning
 +
| -
 
| ''{a} is better written in dot notation.''
 
| ''{a} is better written in dot notation.''
|  
+
| &nbsp;
 
|-
 
|-
  
| eqeqeq
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 eqeqeq]</del>
| '''eqeqeq''' or '''eqeq'''
+
| Warning
 +
| 5.0
 
|
 
|
 
* ''Expected '===' and saw '=='.''
 
* ''Expected '===' and saw '=='.''
 
* ''Expected '!==' and saw '!='.''
 
* ''Expected '!==' and saw '!='.''
|
+
| &nbsp;
* Newer versions of JSLint call this option '''eqeqeq'''.
+
* Orion's version calls it '''eqeq''', and inverts the flag's value.
+
 
|-
 
|-
  
| guard-for-in
+
!| guard-for-in
| '''forin'''
+
| Ignore
 +
| -
 
| ''The body of a <code>for in</code> should be wrapped in an <code>if</code> statement to filter unwanted properties from the prototype.''
 
| ''The body of a <code>for in</code> should be wrapped in an <code>if</code> statement to filter unwanted properties from the prototype.''
 +
| &nbsp;
 
|-
 
|-
  
| max-depth
+
!| max-depth
| Unsupported
+
| Ignore
|  
+
| -
 +
| &nbsp;
 
| Enforces max depth of nested blocks within a function.
 
| Enforces max depth of nested blocks within a function.
 
|-
 
|-
  
| max-len
+
!| max-len
| '''maxlen'''
+
| Ignore
| ''Line too long.''
+
| -
 +
| ''Line is too long.''
 
| Enforces a maximum line length.
 
| Enforces a maximum line length.
 
|-
 
|-
  
| max-params
+
!| max-params
| Unsupported
+
| Ignore
|
+
| -
 +
| &nbsp;
 +
| &nbsp;
 
|-
 
|-
  
| max-statements
+
!| max-statements
| Unsupported
+
| Ignore
|  
+
| -
 +
| &nbsp;
 +
| &nbsp;
 
|-
 
|-
  
| new-cap
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=424128 missing-doc]</del>
| '''newcap'''
+
| Ignore
 +
| 5.0
 +
| "Missing documentation for function '{name}.'"
 +
| Flags missing documentation nodes on function declarations and function expressions when they appear as object properties
 +
|-
 +
 
 +
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424204 missing-doc-items]
 +
| Ignore
 +
| -
 +
|&nbsp;
 +
| Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties
 +
|-
 +
 
 +
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428429 missing-nls]
 +
| Ignore
 +
| -
 +
| &nbsp;
 +
| Flags String literals that are not properly NLS'd
 +
|-
 +
 
 +
!| new-cap
 +
| Warning
 +
| -
 
| ''A constructor name should start with an uppercase letter.''
 
| ''A constructor name should start with an uppercase letter.''
 +
| &nbsp;
 
|-
 
|-
  
| new-parens
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]</del>
| Always on
+
| Error
| ''Missing '()' invoking a constructor.''
+
| 6.0
 +
| ''Missing parentheses invoking constructor.''
 
| Flags <code>new Whatever</code>  
 
| Flags <code>new Whatever</code>  
 
|-
 
|-
  
| no-alert
+
!| no-alert
| '''devel'''
+
| Ignore
 +
| -
 
| '''{alert, confirm, prompt}' is not defined.''
 
| '''{alert, confirm, prompt}' is not defined.''
|  
+
| &nbsp;
 
|-
 
|-
  
| no-bitwise
+
!| no-bitwise
| '''bitwise'''
+
| Warning
 +
| -
 
| ''Unexpected use of '{operator}'.''
 
| ''Unexpected use of '{operator}'.''
 
| JSLint disallows bitwise ops by default.
 
| JSLint disallows bitwise ops by default.
 
|-
 
|-
  
| no-caller
+
!| <del>no-caller</del>
| Unsupported
+
| Error
|  
+
| -
 +
| ''arguments.{callee, caller} is deprecated.''
 
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
 
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
 
|-
 
|-
  
| no-catch-shadow
+
!| no-catch-shadow
| Always on
+
| Warning
 +
| -
 
| '''{a}' is already defined.''
 
| '''{a}' is already defined.''
 
|
 
|
* Flags a <code>catch</code> clause's variable that shadows a variable declared in an outer scope. (In IE8 this [weblog.bocoup.com/the-catch-with-try-catch/ causes the outer variable to be overwritten]).
+
* Flags a <code>catch</code> clause's variable that shadows a variable declared in an upper scope. (In IE8 this [http://weblog.bocoup.com/the-catch-with-try-catch/ causes the upper variable to be overwritten]).
 
|-
 
|-
  
| no-comma-dangle
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455253 no-comma-dangle]</del>
| Always on
+
| Ignore
| ''Unexpected comma.''
+
| 8.0
| Flags trailing commas in object literals.
+
| ''Trailing commas in object expressions are discouraged.''
 +
| Flags trailing commas in object expressions.
 
|-
 
|-
  
| no-cond-assign
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455250 no-cond-assign]</del>
| Unsupported
+
| Error
|  
+
| 8.0
 +
| Expected a conditional expression and instead saw an assignment.
 
| Flags assignment in an <code>if/while/do..while/for</code> condition.
 
| Flags assignment in an <code>if/while/do..while/for</code> condition.
 
|-
 
|-
  
| no-console
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455371 no-console]</del>
| '''devel'''
+
| Error
|  
+
| 8.0
|  
+
| Discouraged use of console in browser-based code.
 +
| Flags the use of console in browser-based code
 
|-
 
|-
  
| no-control-regex
+
!| no-control-regex
| Unsupported
+
| Ignore
|  
+
| -
 +
| &nbsp;
 
| Flags control characters (U+0000–U+001F and U+007F) within the source argument to the RegExp constructor.
 
| Flags control characters (U+0000–U+001F and U+007F) within the source argument to the RegExp constructor.
 
|-
 
|-
  
| no-debugger
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-debugger]</del>
| '''debug'''
+
| Warning
| ''All 'debugger' statements should be removed.''
+
| 6.0
|  
+
| ''debugger' statement use is discouraged.''
 +
| &nbsp;
 
|-
 
|-
  
| no-delete-var
+
!| no-delete-var
| Always on
+
| Warning
| ''Expected '.' and instead saw ';'.''
+
| -
 +
| ''Deleting a local variable is discouraged.''
 
| Flags an attempt to <code>delete</code> a local variable.
 
| Flags an attempt to <code>delete</code> a local variable.
 
|-
 
|-
  
| no-div-regex
+
!| no-div-regex
| Always on
+
| Warning
 +
| -
 
| ''A regular expression literal can be confused with '/='.''
 
| ''A regular expression literal can be confused with '/='.''
 
| Flags a regex literal starting with <code>/=</code>
 
| Flags a regex literal starting with <code>/=</code>
 
|-
 
|-
  
| no-dupe-keys
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]</del>
| Always on
+
| Error
| ''Duplicate key '{a}'.''
+
| 6.0
 +
| ''Duplicate object key '{key}'.''
 
| Flags object literals that contain the same key more than once.
 
| Flags object literals that contain the same key more than once.
 
|-
 
|-
  
| no-else-return
+
!| no-else-return
| Unsupported
+
| Warning
|  
+
| -
 +
| &nbsp;
 
| Flags an <code>else</code> appearing after an <code>if</code> that contains a <code>return</code>.
 
| Flags an <code>else</code> appearing after an <code>if</code> that contains a <code>return</code>.
 
|-
 
|-
  
| no-empty-class
+
!| no-empty-class
| Always on
+
| Warning
 +
| -
 
| ''Empty class.''
 
| ''Empty class.''
 
| Flags an empty character class <code>[]</code> within a regular expression.
 
| Flags an empty character class <code>[]</code> within a regular expression.
 
|-
 
|-
  
| no-empty-label
+
!| no-empty-label
| Always on
+
| Warning
| ''Label '{a}' on statement.''
+
| -
 +
| ''Label '{a}' is not allowed on this statement.''
 
| Flags a labeled statement that is not a <code>switch</code>, <code>for</code>, or <code>while</code>.
 
| Flags a labeled statement that is not a <code>switch</code>, <code>for</code>, or <code>while</code>.
 
|-
 
|-
  
| no-empty
+
!| <del>no-empty</del>
| Unsupported
+
| Warning
|  
+
| -
 +
| &nbsp;
 
| Flags an empty block like <code>if (something) { }</code>.
 
| Flags an empty block like <code>if (something) { }</code>.
 
|-
 
|-
  
| no-eq-null
+
!| no-eq-null
| Always on
+
| Error
 +
| -
 
| ''Use '===' to compare with 'null'.''
 
| ''Use '===' to compare with 'null'.''
| JSLint produces a similar warning when comparing against <code>undefined</code>.
+
| &nbsp;
 
|-
 
|-
  
| no-eval
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]</del>
| '''evil'''
+
| Ignore
| ''eval is evil.''
+
| 6.0
 +
| '''eval' function calls are discouraged.''
 +
| &nbsp;
 
|-
 
|-
  
| no-ex-assign
+
!| no-ex-assign
| Always on
+
| Warning
 +
| -
 
| ''Do not assign to the exception parameter.''
 
| ''Do not assign to the exception parameter.''
 +
| &nbsp;
 
|-
 
|-
  
| no-extra-semi
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 no-extra-semi]</del>
| Always on
+
| Warning
 +
| 5.0
 
| ''Unnecessary semicolon.''
 
| ''Unnecessary semicolon.''
 +
| &nbsp;
 
|-
 
|-
  
| no-fallthrough
+
!| no-extra-strict
| Unsupported
+
| Warning
|  
+
| -
 +
| &nbsp;
 +
| Flags <code>"use strict"</code> on a function when the entire Program is already in strict mode.
 +
|-
 +
 
 +
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429815 no-fallthrough]</del>
 +
| Error
 +
| -
 +
| ''Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above''
 
| Flags a fallthrough case within a <code>switch</code> statement, unless it is explicitly commented.
 
| Flags a fallthrough case within a <code>switch</code> statement, unless it is explicitly commented.
 
|-
 
|-
  
| no-floating-decimal
+
!| no-floating-decimal
| Always on
+
| Warning
 +
| -
 
| ''A {leading, trailing} decimal point can be confused with a dot: '{n}'.''
 
| ''A {leading, trailing} decimal point can be confused with a dot: '{n}'.''
 
| Flags numeric literals that have a leading or trailing decimal point.
 
| Flags numeric literals that have a leading or trailing decimal point.
 
|-
 
|-
  
| no-func-assign
+
!| no-func-assign
| Unsupported
+
| Warning
|  
+
| -
 +
| &nbsp;
 
| Flags assignment to a variable that's already bound to a <code>FunctionExpression</code>.
 
| Flags assignment to a variable that's already bound to a <code>FunctionExpression</code>.
 
|-
 
|-
  
| no-global-strict
+
!| no-global-strict
| Unsupported
+
| Warning
|  
+
| -
 +
| &nbsp;
 
| Flags <code>"use strict"</code> applied to the entire Program.
 
| Flags <code>"use strict"</code> applied to the entire Program.
 
|-
 
|-
  
| no-implied-eval
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429707 no-implied-eval]</del>
| Always on
+
| Ignore
| ''Implied eval is evil. Pass a function instead of a string.''
+
| 6.0
| Flags calls to the string-argument form of <code>setTimeout</code> and <code>setInterval</code>, which implicitly perform <code>eval</code>.
+
| ''Implicit 'eval' function calls are discouraged.''
 +
| Flags calls to the string-argument form of <code>setTimeout</code> and <code>setInterval</code>, which implicitly perform <code>eval</code>. This rule logic was merged to be part of the <b>no-eval</b> rule.
 
|-
 
|-
  
| no-iterator
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455643 no-iterator]</del>
| Always on
+
| Error
| ''Reserved name '__iterator__'.''
+
| 8.0
 +
| '''Discouraged __iterator__ property use.'''
 
| Flags use of __iterator__ as an identifier name or property key.
 
| Flags use of __iterator__ as an identifier name or property key.
 
|-
 
|-
  
| no-label-var
+
!| no-label-var
| Always on
+
| Error
 +
| -
 
| '''{label}' is already defined.''
 
| '''{label}' is already defined.''
 
| Flags labels that collide with an identifier.
 
| Flags labels that collide with an identifier.
 
|-
 
|-
  
| no-loop-func
+
!| no-loop-func
| Always on
+
| Error
 +
| -
 
| ''Don't make functions within a loop.''
 
| ''Don't make functions within a loop.''
|
+
| &nbsp;
 
|-
 
|-
  
| no-mixed-requires
+
!| no-mixed-requires
|  
+
| Ignore
|  
+
| -
 +
| &nbsp;
 
| Flags Node.js <code>require()</code>s that mix different types of requires (core, module, file, computed).
 
| Flags Node.js <code>require()</code>s that mix different types of requires (core, module, file, computed).
 
|-
 
|-
  
| no-multi-str
+
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=425200 no-mixed-returns]
|  
+
| Error
|  
+
| -
 +
| &nbsp;
 +
| Flags functions that return more than one kind of item, for example returning String and Object
 +
|-
 +
 
 +
!| no-multi-str
 +
| Warning
 +
| -
 +
| &nbsp;
 
| Flags use of ES5 multiline string literals.
 
| Flags use of ES5 multiline string literals.
 
|-
 
|-
  
| no-native-reassign
+
!| no-native-reassign
| Always on
+
| Warning
 +
| -
 
|
 
|
 
* ''Read only.''
 
* ''Read only.''
Line 291: Line 378:
 
|-
 
|-
  
| no-negated-in-lhs
+
!| no-negated-in-lhs
| Unsupported
+
| Warning
|  
+
| -
 +
| &nbsp;
 
|
 
|
 
* Flags a unary <code>!</code> operator applied to the LHS of an in statement, which negates the LHS, not the <code>in</code>.  
 
* Flags a unary <code>!</code> operator applied to the LHS of an in statement, which negates the LHS, not the <code>in</code>.  
Line 299: Line 387:
 
|-
 
|-
  
| no-new-array
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-array]</del>
| Always on
+
| Warning
 +
| -
 
| ''Use the array literal notation [].''
 
| ''Use the array literal notation [].''
 
| Flags <code>new Array()</code>.
 
| Flags <code>new Array()</code>.
 
|-
 
|-
  
| no-new-func
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]</del>
| Always on
+
| Warning
 +
| -
 
| ''The Function constructor is eval.''
 
| ''The Function constructor is eval.''
|  
+
| Flags <code>new Function()</code>.
 
|-
 
|-
  
| no-new-object
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]</del>
| Always on
+
| Warning
 +
| -
 
| ''Use the object literal notation {}.''
 
| ''Use the object literal notation {}.''
 
| Flags <code>new Object()</code>.
 
| Flags <code>new Object()</code>.
 
|-
 
|-
  
| no-new-wrappers
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]</del>
|  
+
| Warning
 +
| -
 
| ''Do not use {String, Number, Boolean, Math, JSON} as a constructor.''
 
| ''Do not use {String, Number, Boolean, Math, JSON} as a constructor.''
 
| Flags <code>new</code> applied to any of those.
 
| Flags <code>new</code> applied to any of those.
 
|-
 
|-
  
| no-new
+
!| no-new
| Always on
+
| Error
 +
| -
 
| ''Do not use 'new' for side effects.''
 
| ''Do not use 'new' for side effects.''
 
| Flags uses of <code>new</code> operator in an expression that is not assigned to anything.
 
| Flags uses of <code>new</code> operator in an expression that is not assigned to anything.
 
|-
 
|-
  
| no-obj-calls
+
!| no-obj-calls
| Partial support
+
| Warning
 +
| -
 
| ''Math is not a function..''
 
| ''Math is not a function..''
 
|
 
|
 
* Flags attempts to call object properties of the global object (<code>Math</code>, <code>JSON</code>) as a function, like <code>Math()</code>.
 
* Flags attempts to call object properties of the global object (<code>Math</code>, <code>JSON</code>) as a function, like <code>Math()</code>.
* JSLint warns only on <code>Math()</code>.
 
 
|-
 
|-
  
| no-octal-escape
+
!| no-octal-escape
| Always on
+
| Warning
 +
| -
 
| ''Bad escapement.''
 
| ''Bad escapement.''
 
| Flags octal escapes in strings, for example <code>var x = "Copyright \251";</code>
 
| Flags octal escapes in strings, for example <code>var x = "Copyright \251";</code>
 
|-
 
|-
  
| no-octal
+
!| no-octal
| Always on
+
| Warning
 +
| -
 
| ''Don't use extra leading zeros '{n}'.''
 
| ''Don't use extra leading zeros '{n}'.''
 
| Flags number literals that begin with leading 0s, which indicate a (probably accidental) octal literal.
 
| Flags number literals that begin with leading 0s, which indicate a (probably accidental) octal literal.
 
|-
 
|-
  
| no-plusplus
+
!| no-plusplus
| '''plusplus'''
+
| Warning
 +
| -
 
|  
 
|  
 
* ''Unexpected use of '++'''
 
* ''Unexpected use of '++'''
 
* ''Unexpected use of '--'''
 
* ''Unexpected use of '--'''
 +
| &nbsp;
 
|-
 
|-
  
| no-proto
+
!| no-proto
| Always on
+
| Error
 +
| -
 
|
 
|
* ''Reserved name '__proto__'.'' (if used as an identifier)
+
* ''Reserved name '__proto__' should not be assigned."
* ''Stupid key '{a}'.'' (if used as a key)
+
* 'Reserved name '__proto__' should not be used as a key."
| Treated as a fatal parse error in JSLint.
+
| &nbsp;
 
|-
 
|-
  
| no-redeclare
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]</del>
| Always on
+
| Warning
 +
| 5.0
 
| '''{a}' is already defined.''
 
| '''{a}' is already defined.''
 
| Usually results from having two <code>for</code> loops in the same function that share a loop variable declaration like <code>var i=...</code>.
 
| Usually results from having two <code>for</code> loops in the same function that share a loop variable declaration like <code>var i=...</code>.
 
|-
 
|-
  
| no-return-assign
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455391 no-regex-spaces]</del>
| Unsupported
+
| Error
|  
+
| 8.0
 +
| Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead.
 +
| Flags regular expressions that have two or more subsequent spaces.
 +
|-
 +
 
 +
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455354 no-reserved-keys]</del>
 +
| Error
 +
| 8.0
 +
| ''Reserved words should not be used as property keys.''
 +
| Checks to see if a JavaScript reserved word is being used as a property key
 +
|-
 +
 
 +
!| no-return-assign
 +
| Warning
 +
| -
 +
| &nbsp;
 
|
 
|
 
* Prevents assignment in a <code>return</code> statement.
 
* Prevents assignment in a <code>return</code> statement.
Line 378: Line 492:
 
|-
 
|-
  
| no-script-url
+
!| no-script-url
| Always on
+
| Warning
| ''Script URL.''
+
| -
 +
| &nbsp;
 
|  
 
|  
 
* Flags string literals beginning with <code>javascript:</code>. (Script URLs are a form of <code>eval</code>.)
 
* Flags string literals beginning with <code>javascript:</code>. (Script URLs are a form of <code>eval</code>.)
* Fatal parse error in JSLint.
 
 
|-
 
|-
  
| no-self-compare
+
!| no-self-compare
| Unsupported
+
| Error
|
+
| -
 +
| &nbsp;
 
| Flags comparisons where the left- and right-hand sides are the same.
 
| Flags comparisons where the left- and right-hand sides are the same.
 
|-
 
|-
  
| no-shadow
+
!!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=438319 no-shadow]</del>
| Unsupported
+
| Warning
|  
+
| 8.0
| Flags variables that have the same name as a variable declared in an outer scope.
+
| '''{a}' is already declared in the upper scope.''
 +
| Flags variables that have the same name as a variable declared in an upper scope.
 
|-
 
|-
  
| no-spaced-func
+
!| no-spaced-func
|  
+
| Ignore
|  
+
| -
 +
| ''Unnecessary space in function call.''
 +
| Report on excess space in a function call, for example <code>myFunc ();</code> or <code>new MyObj ();</code>
 
|-
 
|-
  
| no-sync
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=426723 no-sparse-arrays]</del>
| '''stupid'''
+
| Warning
 +
| 8.0
 +
| ''Sparse array declarations should de avoided.''
 +
| Flags sparse arrays with null elements
 +
|-
 +
 
 +
!| no-sync
 +
| Ignore
 +
| -
 
| ''Unexpected sync method: '{a}'.''
 
| ''Unexpected sync method: '{a}'.''
 
|
 
|
Line 411: Line 537:
 
|-
 
|-
  
| no-ternary
+
!| no-ternary
| Unsupported
+
| Ignore
|  
+
| -
 +
| &nbsp;
 
| Flags any use of the ternary operator <code>cond ? thenExpr : elseExpr</code>
 
| Flags any use of the ternary operator <code>cond ? thenExpr : elseExpr</code>
 
|-
 
|-
  
| no-undef-init
+
!| no-undef-init
| Always on
+
| Warning
 +
| -
 
| ''It is not necessary to initialize '{variable}' to 'undefined'.''
 
| ''It is not necessary to initialize '{variable}' to 'undefined'.''
|  
+
| &nbsp;
 +
|-
 +
 
 +
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=427310 no-unused-params]</del>
 +
| Warning
 +
| -
 +
| "Parameter '{param}' is not used."
 +
| Flags parameters in function declarations / expressions if they are not being used
 
|-
 
|-
  
| no-undef
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-undef]</del>
| '''undef'''
+
| Error
 +
| 5.0
 
| '''{variable}' is not defined.''
 
| '''{variable}' is not defined.''
 
|
 
|
Line 431: Line 567:
 
|-
 
|-
  
| no-underscore-dangle
+
!| no-underscore-dangle
| '''nomen'''
+
| Ignore
 +
| -
 
| ''Dangling '_'''
 
| ''Dangling '_'''
 +
| &nbsp;
 
|-
 
|-
  
| no-unreachable
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=436986 no-unreachable]</del>
| Always on
+
| Error
| ''Unreachable '{statement}' after '{control flow statement}'.''
+
| -
 +
| ''Unreachable code.''
 
| Flags statements that occur after a <code>return</code>, <code>throw</code>, etc.
 
| Flags statements that occur after a <code>return</code>, <code>throw</code>, etc.
 
|-
 
|-
  
| no-unused-expressions
+
!| no-unused-expressions
| Always on
+
| Warning
 +
| -
 
| ''Expected an assignment or function call and instead saw an expression.''
 
| ''Expected an assignment or function call and instead saw an expression.''
 
| Flags expressions that appear in a statement context and don't cause side effects.
 
| Flags expressions that appear in a statement context and don't cause side effects.
 
|-
 
|-
  
| no-unused-vars
+
!| <deL>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-unused-vars]</del>
| Always on
+
| Warning
| ''Function declares unused variable '{a}'.'' (Orion)
+
| 5.0
| Newer JSlint versions have an '''unparam''' option which works similarly.
+
| ''Function declares unused variable '{a}'.''
 +
| &nbsp;
 
|-
 
|-
  
| no-use-before-define
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-use-before-define]</del>
| Always on
+
| Warning
 +
| 5.0
 
| '''{a}' was used before it was defined.''
 
| '''{a}' was used before it was defined.''
 +
| &nbsp;
 
|-
 
|-
  
| no-with
+
!| no-with
| Always on
+
| Warning
 +
| -
 
| ''Expected an identifier and instead saw 'with'.''
 
| ''Expected an identifier and instead saw 'with'.''
 
| Treated as fatal parse error in JSLint.
 
| Treated as fatal parse error in JSLint.
 
|-
 
|-
  
| no-wrap-func
+
!| no-wrap-func
| Always on
+
| Ignore
 +
| -
 
| ''Do not wrap function literals in parens unless they are to be immediately invoked.''
 
| ''Do not wrap function literals in parens unless they are to be immediately invoked.''
 
| Flags a parenthesized function literal that is not immediately invoked, eg. <code>(function fun(){})</code>
 
| Flags a parenthesized function literal that is not immediately invoked, eg. <code>(function fun(){})</code>
 
|-
 
|-
  
| one-var
+
!| object-prototype-external
| '''onevar'''
+
| Warning
 +
| -
 +
| &nbsp;
 +
| Flags calls to methods of <code>Object.prototype</code> that rely on the prototype chain. For example this code should be flagged:
 +
<source lang="javascript" line="line">
 +
foo.hasOwnProperty("bar")
 +
</source>
 +
 
 +
Example (1) is [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FObject%2FhasOwnProperty#hasOwnProperty_as_a_property unsafe], as <code>foo</code> may have a property named <code>hasOwnProperty</code>, or have been constructed via <code>Object.create(null)</code>.
 +
 
 +
As for this:
 +
 
 +
<source lang="javascript" line="line" start="2">
 +
Object.hasOwnProperty.call(foo, "bar")
 +
</source>
 +
 
 +
Example (2) technically relies on the prototype chain as well: the hasOwnProperty method is defined on Object.prototype, not Object. Object inherits the methods of Object.prototype [http://stackoverflow.com/questions/14817826/difference-between-an-object-and-its-prototype/14817913#14817913 through its prototype chain]. However (2) is unlikely to fail, as sane JavaScript programs will not modify the global objects' prototypes. If we choose to flag (2), it should only be for style.
 +
|-
 +
 
 +
!| one-var
 +
| Warning
 +
| -
 
| ''Too many var statements.''
 
| ''Too many var statements.''
 
| Allows only 1 <code>var</code> statement per function.
 
| Allows only 1 <code>var</code> statement per function.
 
|-
 
|-
  
| quote-props
+
!| quote-props
| Unsupported
+
| Warning
|  
+
| -
 +
| &nbsp;
 
| Requires object literal keys to be quoted with " or '.
 
| Requires object literal keys to be quoted with " or '.
 
|-
 
|-
  
| quotes
+
!| quotes
| Unsupported
+
| Ignore
|  
+
| -
 +
| &nbsp;
 
| Flags any use of single or double quote marks, depending on setting.
 
| Flags any use of single or double quote marks, depending on setting.
 
|-
 
|-
  
| radix
+
!| <del>radix</del>
| Always on
+
| Warning
 +
| -
 
| ''Missing radix parameter.''
 
| ''Missing radix parameter.''
| Affects parseInt().
+
| Warns when parseInt() called without the 2nd parameter (radix).
 
|-
 
|-
  
| regex-spaces
+
!| regex-spaces
| Always on
+
| Warning
 +
| -
 
| ''Spaces are hard to count. Use {n}.''
 
| ''Spaces are hard to count. Use {n}.''
 +
| &nbsp;
 
|-
 
|-
  
| semi
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=427930 semi]</del>
| Always on
+
| Warning
 +
| 5.0
 
| ''Missing semicolon.''
 
| ''Missing semicolon.''
|
+
| &nbsp;
 
|-
 
|-
  
| strict
+
!| strict
| '''strict'''
+
| Ignore
|  
+
| -
 +
| &nbsp;
 
| Flags any code that lacks the <code>"use strict"</code> pragma.
 
| Flags any code that lacks the <code>"use strict"</code> pragma.
 
|-
 
|-
  
| unnecessary-strict
+
!| <del>[http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=6e517847ef0742b090130748fb9a0329d33e16bf throw-error]</del>
| Unsupported
+
| Warning
|  
+
| 7.0
| Flags <code>"use strict"</code> on a function when the entire Program is already in strict mode.
+
| &nbsp;
 +
| Flags code that throws a non-Error, eg. <code>throw "a problem occurred";</code>
 
|-
 
|-
  
| use-isnan
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429711 use-isnan]</del>
| Always on
+
| Error
 +
| 6.0
 
| ''Use the isNaN function to compare with NaN.''
 
| ''Use the isNaN function to compare with NaN.''
|
+
| &nbsp;
 
|-
 
|-
  
| wrap-iife
+
!| wrap-iife
| '''immed'''
+
| Ignore
 +
| -
 
|
 
|
 
* ''Wrap the entire immediate function invocation in parens.''
 
* ''Wrap the entire immediate function invocation in parens.''
Line 532: Line 708:
 
|-
 
|-
  
| wrap-regex
+
!| wrap-regex
| Always on
+
| Warning
 +
| -
 
| ''Wrap the /regexp/ literal in parens to disambiguate the slash operator.''
 
| ''Wrap the /regexp/ literal in parens to disambiguate the slash operator.''
 +
| &nbsp;
 
|-
 
|-
  
Line 540: Line 718:
 
|}
 
|}
  
== New rules ==
+
=== Implementing a new rule ===
Ideas for new linting rules that we should write.
+
''This section explains how to implement a new linting rule. For brevity, all paths are given relative to <tt>bundles/org.eclipse.orion.client.javascript/web/</tt> in the client repo.''
  
{| class="wikitable" border="1" style="width: 100%;"
+
First, create the tests and rule:
! Name
+
# Create a new test file for the rule at: <tt>/eslint/tests/lib/rules/{rule-name}.js</tt>.
! Severity
+
# Link your test to the suite in <tt>/eslint/tests/load-tests.js</tt>.
! Description
+
# Implement the actual logic for your rule in <tt>/eslint/lib/load-rules-async.js</tt>.
|-
+
At this point you should [[#Runing the tests|run the JS bundle tests]] and ensure your rule works as intended. To get your rule running in the Orion product's validator, there are additional steps:
| object-prototype-external
+
| Warning
+
| Flags calls to methods of <code>Object.prototype</code> that rely on the prototype chain. For example this code should be flagged:
+
  
<source lang="javascript" line="line">
+
# Create strings for the validation message(s) generated by your rule in <tt>/javascript/nls/root/problems.js</tt>.
foo.hasOwnProperty("bar")
+
# Create a short string describing what your rule does in <tt>/javascript/nls/root/messages.js</tt>.
</source>
+
# Add an entry to the <tt>orion.core.setting</tt> declaration in <tt>/javascript/plugins/javascriptPlugin.js</tt>. This allows your rule to be configured from the JS validator settings page. Make sure it references the same <tt>nameKey</tt> used in <tt>messages.js</tt>.
 +
# Add a config entry for your rule to the default ESLint config object in <tt>/javascript/validator.js</tt>.
 +
# Add your rule to the #updated() handler in <tt>/javascript/validator.js</tt>.
  
Example (1) is [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FObject%2FhasOwnProperty#hasOwnProperty_as_a_property unsafe], as <code>foo</code> may have a property named <code>hasOwnProperty</code>, or have been constructed via <code>Object.create(null)</code>.
+
Reload the JS plugin, and your rule should now be configurable from the Settings page, and properly set up for translation too.
  
As for this:
+
== Tests ==
 +
* Every rule needs extensive unit tests.
 +
* Unit tests should use [http://mochajs.org Mocha].
  
<source lang="javascript" line="line" start="2">
+
=== Running the tests ===
Object.hasOwnProperty.call(foo, "bar")
+
* To run the ESLint tests as part of the main JavaScript tests suite load <tt>{orion-server-url}/javascript/js-tests/JsMochaSuite.html</tt> in your web browser.
</source>
+
** Click [https://orionhub.org/js-tests/javascript/JsMochaSuite.html here] to see the suite running on [https://orionhub.org orionhub].
 +
* To run just the ESLint rule tests, load <tt>{orion-server-url}/js-tests/javascript/JsMochaSuite.html?grep=ESLint%20Rule%20Tests</tt> in your browser.
 +
** Click [https://orionhub.org/js-tests/javascript/JsMochaSuite.html?grep=ESLint%20Rule%20Tests here] to see the suite running on [https://orionhub.org orionhub].
 +
* To run just the ESLint core tests, load <tt>{orion-server-url}/js-tests/javascript/JsMochaSuite.html?grep=ESLint%20Core%20Tests</tt> in your browser.
 +
** Click [https://orionhub.org/js-tests/javascript/JsMochaSuite.html?grep=ESLint%20Core%20Tests here] to see the suite running on [https://orionhub.org orionhub].
 +
* To run only a subset of the tests, add <tt>?grep=ESLint%20Rule%20Tests</tt> onto the test page URL.
  
Example (2) technically relies on the prototype chain as well: the hasOwnProperty method is defined on Object.prototype, not Object. Object inherits the methods of Object.prototype [http://stackoverflow.com/questions/14817826/difference-between-an-object-and-its-prototype/14817913#14817913 through its prototype chain]. However (2) is unlikely to fail, as sane JavaScript programs will not modify the global objects' prototypes. If we choose to flag (2), it should only be for style.
+
See [http://mochajs.org/#grep-query Mocha usage options] for more options.
|}
+
  
== Rule priority ==
+
== User interface ==
Here are the rules we want to support, grouped by priority:
+
* <del>Should we have a UI for configuring what rules are active?</del> [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424268 bug 424268].
 +
* Should we try to support <code>.eslintrc</code>? This would be an ideal project-scope setting.
 +
* <del>Should we try to honor equivalent JSLint/JSHint flags when possible? For example <code>/*jslint eqeqeq:false */</code> could disable the eqeqeq rule on a per-file basis.</del>
 +
** ESLint now has its own syntax for this: <code>/*eslint ..*/</code>, which we are using instead.
  
==== Critical ====
+
== i18n ==
* block-scoped-var
+
We need to support i18n. Pre-req is {{bug|422278}} (orion.edit.validator support for i18n).
* eqeqeq
+
* no-redeclare
+
* no-undef
+
* no-use-before-define
+
  
==== Important ====
+
[[Category:Orion]]
* guard-for-in
+
* no-dupe-keys
+
* no-octal
+
* no-unused-vars
+
* no-with
+
* radix
+
* wrap-iife
+
 
+
==== Nice to have ====
+
* dot-notation
+
* new-cap
+
* new-parens
+
* no-caller
+
* no-comma-dangle
+
* no-implied-eval
+
* no-new-array
+
* no-new-object
+
* no-undef-init
+
* no-unused-expressions
+
* no-wrap-func
+
* semi
+
* use-isnan
+
 
+
== Tests ==
+
We don't have legal approval to commit the ESLint tests, because I didn't include them in the CQ. Moreover, they are written using '''vows''', whereas Orion is converging on '''Mocha'''.
+

Revision as of 14:01, 18 December 2014

Orion 5.0 moved to ESLint as the validator that ships with Orion. This page captures ongoing issues.

Rules

The following table describes all of the rules currently available in Orion and ones that we plan to add in the future.

Rules that are currently available are struck out.

Rule Default Severity Available Since Problem Message Details
block-scoped-var Error - '{variable}' is already defined.
  • Occurs when a function-scoped variable is treated as if it was block scoped.
  • ESLint calls this error '{variable} used outside of binding context.'
brace-style Ignore -    
camelcase Ignore -    
complexity Ignore -    
consistent-this Ignore -    
curly Ignore 6.0 Statements should be enclosed in braces.  
dot-notation Warning - {a} is better written in dot notation.  
eqeqeq Warning 5.0
  • Expected '===' and saw '=='.
  • Expected '!==' and saw '!='.
 
guard-for-in Ignore - The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.  
max-depth Ignore -   Enforces max depth of nested blocks within a function.
max-len Ignore - Line is too long. Enforces a maximum line length.
max-params Ignore -    
max-statements Ignore -    
missing-doc Ignore 5.0 "Missing documentation for function '{name}.'" Flags missing documentation nodes on function declarations and function expressions when they appear as object properties
missing-doc-items Ignore -   Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties
missing-nls Ignore -   Flags String literals that are not properly NLS'd
new-cap Warning - A constructor name should start with an uppercase letter.  
new-parens Error 6.0 Missing parentheses invoking constructor. Flags new Whatever
no-alert Ignore - '{alert, confirm, prompt}' is not defined.  
no-bitwise Warning - Unexpected use of '{operator}'. JSLint disallows bitwise ops by default.
no-caller Error - arguments.{callee, caller} is deprecated. Flags references to arguments.callee and arguments.caller.
no-catch-shadow Warning - '{a}' is already defined.
no-comma-dangle Ignore 8.0 Trailing commas in object expressions are discouraged. Flags trailing commas in object expressions.
no-cond-assign Error 8.0 Expected a conditional expression and instead saw an assignment. Flags assignment in an if/while/do..while/for condition.
no-console Error 8.0 Discouraged use of console in browser-based code. Flags the use of console in browser-based code
no-control-regex Ignore -   Flags control characters (U+0000–U+001F and U+007F) within the source argument to the RegExp constructor.
no-debugger Warning 6.0 debugger' statement use is discouraged.  
no-delete-var Warning - Deleting a local variable is discouraged. Flags an attempt to delete a local variable.
no-div-regex Warning - A regular expression literal can be confused with '/='. Flags a regex literal starting with /=
no-dupe-keys Error 6.0 Duplicate object key '{key}'. Flags object literals that contain the same key more than once.
no-else-return Warning -   Flags an else appearing after an if that contains a return.
no-empty-class Warning - Empty class. Flags an empty character class [] within a regular expression.
no-empty-label Warning - Label '{a}' is not allowed on this statement. Flags a labeled statement that is not a switch, for, or while.
no-empty Warning -   Flags an empty block like if (something) { }.
no-eq-null Error - Use '===' to compare with 'null'.  
no-eval Ignore 6.0 'eval' function calls are discouraged.  
no-ex-assign Warning - Do not assign to the exception parameter.  
no-extra-semi Warning 5.0 Unnecessary semicolon.  
no-extra-strict Warning -   Flags "use strict" on a function when the entire Program is already in strict mode.
no-fallthrough Error - Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above Flags a fallthrough case within a switch statement, unless it is explicitly commented.
no-floating-decimal Warning - A {leading, trailing} decimal point can be confused with a dot: '{n}'. Flags numeric literals that have a leading or trailing decimal point.
no-func-assign Warning -   Flags assignment to a variable that's already bound to a FunctionExpression.
no-global-strict Warning -   Flags "use strict" applied to the entire Program.
no-implied-eval Ignore 6.0 Implicit 'eval' function calls are discouraged. Flags calls to the string-argument form of setTimeout and setInterval, which implicitly perform eval. This rule logic was merged to be part of the no-eval rule.
no-iterator Error 8.0 Discouraged __iterator__ property use. Flags use of __iterator__ as an identifier name or property key.
no-label-var Error - '{label}' is already defined. Flags labels that collide with an identifier.
no-loop-func Error - Don't make functions within a loop.  
no-mixed-requires Ignore -   Flags Node.js require()s that mix different types of requires (core, module, file, computed).
no-mixed-returns Error -   Flags functions that return more than one kind of item, for example returning String and Object
no-multi-str Warning -   Flags use of ES5 multiline string literals.
no-native-reassign Warning -
  • Read only.
  • Bad assignment. (if assigning to undefined)
Flags an attempt to reassign a native object like Math, Array, undefined, etc.
no-negated-in-lhs Warning -  
  • Flags a unary ! operator applied to the LHS of an in statement, which negates the LHS, not the in.
  • Eg. (!"key" in {key: 1}) (which always evaluates to false), will be flagged.
no-new-array Warning - Use the array literal notation []. Flags new Array().
no-new-func Warning - The Function constructor is eval. Flags new Function().
no-new-object Warning - Use the object literal notation {}. Flags new Object().
no-new-wrappers Warning - Do not use {String, Number, Boolean, Math, JSON} as a constructor. Flags new applied to any of those.
no-new Error - Do not use 'new' for side effects. Flags uses of new operator in an expression that is not assigned to anything.
no-obj-calls Warning - Math is not a function..
  • Flags attempts to call object properties of the global object (Math, JSON) as a function, like Math().
no-octal-escape Warning - Bad escapement. Flags octal escapes in strings, for example var x = "Copyright \251";
no-octal Warning - Don't use extra leading zeros '{n}'. Flags number literals that begin with leading 0s, which indicate a (probably accidental) octal literal.
no-plusplus Warning -
  • Unexpected use of '++'
  • Unexpected use of '--'
 
no-proto Error -
  • Reserved name '__proto__' should not be assigned."
  • 'Reserved name '__proto__' should not be used as a key."
 
no-redeclare Warning 5.0 '{a}' is already defined. Usually results from having two for loops in the same function that share a loop variable declaration like var i=....
no-regex-spaces Error 8.0 Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead. Flags regular expressions that have two or more subsequent spaces.
no-reserved-keys Error 8.0 Reserved words should not be used as property keys. Checks to see if a JavaScript reserved word is being used as a property key
no-return-assign Warning -  
  • Prevents assignment in a return statement.
  • Unsupported by JSLint, although JSLint does require parens around a return-assignment, eg: return (x = 2);
no-script-url Warning -  
  • Flags string literals beginning with javascript:. (Script URLs are a form of eval.)
no-self-compare Error -   Flags comparisons where the left- and right-hand sides are the same.
no-shadow Warning 8.0 '{a}' is already declared in the upper scope. Flags variables that have the same name as a variable declared in an upper scope.
no-spaced-func Ignore - Unnecessary space in function call. Report on excess space in a function call, for example myFunc (); or new MyObj ();
no-sparse-arrays Warning 8.0 Sparse array declarations should de avoided. Flags sparse arrays with null elements
no-sync Ignore - Unexpected sync method: '{a}'.
  • Flags Node.js's synchronous I/O methods.
  • The stupid option is supported only in newer versions of JSLint (not Orion's).
no-ternary Ignore -   Flags any use of the ternary operator cond ? thenExpr : elseExpr
no-undef-init Warning - It is not necessary to initialize '{variable}' to 'undefined'.  
no-unused-params Warning - "Parameter '{param}' is not used." Flags parameters in function declarations / expressions if they are not being used
no-undef Error 5.0 '{variable}' is not defined.
  • Flags references to a global variable that is not listed in a /*global*/ or /*globals*/ block.
  • Predefined environments (eg. node, browser) can be set in the /*jslint */ block.
no-underscore-dangle Ignore - Dangling '_'  
no-unreachable Error - Unreachable code. Flags statements that occur after a return, throw, etc.
no-unused-expressions Warning - Expected an assignment or function call and instead saw an expression. Flags expressions that appear in a statement context and don't cause side effects.
no-unused-vars Warning 5.0 Function declares unused variable '{a}'.  
no-use-before-define Warning 5.0 '{a}' was used before it was defined.  
no-with Warning - Expected an identifier and instead saw 'with'. Treated as fatal parse error in JSLint.
no-wrap-func Ignore - Do not wrap function literals in parens unless they are to be immediately invoked. Flags a parenthesized function literal that is not immediately invoked, eg. (function fun(){})
object-prototype-external Warning -   Flags calls to methods of Object.prototype that rely on the prototype chain. For example this code should be flagged:
  1. foo.hasOwnProperty("bar")

Example (1) is unsafe, as foo may have a property named hasOwnProperty, or have been constructed via Object.create(null).

As for this:

  1. Object.hasOwnProperty.call(foo, "bar")

Example (2) technically relies on the prototype chain as well: the hasOwnProperty method is defined on Object.prototype, not Object. Object inherits the methods of Object.prototype through its prototype chain. However (2) is unlikely to fail, as sane JavaScript programs will not modify the global objects' prototypes. If we choose to flag (2), it should only be for style.

one-var Warning - Too many var statements. Allows only 1 var statement per function.
quote-props Warning -   Requires object literal keys to be quoted with " or '.
quotes Ignore -   Flags any use of single or double quote marks, depending on setting.
radix Warning - Missing radix parameter. Warns when parseInt() called without the 2nd parameter (radix).
regex-spaces Warning - Spaces are hard to count. Use {n}.  
semi Warning 5.0 Missing semicolon.  
strict Ignore -   Flags any code that lacks the "use strict" pragma.
throw-error Warning 7.0   Flags code that throws a non-Error, eg. throw "a problem occurred";
use-isnan Error 6.0 Use the isNaN function to compare with NaN.  
wrap-iife Ignore -
  • Wrap the entire immediate function invocation in parens.
  • Move the invocation into the parens that contain the function.
Flags missing parens on immediately-invoked functions, eg. function(){ console.log('hi'); }();
wrap-regex Warning - Wrap the /regexp/ literal in parens to disambiguate the slash operator.  

Implementing a new rule

This section explains how to implement a new linting rule. For brevity, all paths are given relative to bundles/org.eclipse.orion.client.javascript/web/ in the client repo.

First, create the tests and rule:

  1. Create a new test file for the rule at: /eslint/tests/lib/rules/{rule-name}.js.
  2. Link your test to the suite in /eslint/tests/load-tests.js.
  3. Implement the actual logic for your rule in /eslint/lib/load-rules-async.js.

At this point you should run the JS bundle tests and ensure your rule works as intended. To get your rule running in the Orion product's validator, there are additional steps:

  1. Create strings for the validation message(s) generated by your rule in /javascript/nls/root/problems.js.
  2. Create a short string describing what your rule does in /javascript/nls/root/messages.js.
  3. Add an entry to the orion.core.setting declaration in /javascript/plugins/javascriptPlugin.js. This allows your rule to be configured from the JS validator settings page. Make sure it references the same nameKey used in messages.js.
  4. Add a config entry for your rule to the default ESLint config object in /javascript/validator.js.
  5. Add your rule to the #updated() handler in /javascript/validator.js.

Reload the JS plugin, and your rule should now be configurable from the Settings page, and properly set up for translation too.

Tests

  • Every rule needs extensive unit tests.
  • Unit tests should use Mocha.

Running the tests

  • To run the ESLint tests as part of the main JavaScript tests suite load {orion-server-url}/javascript/js-tests/JsMochaSuite.html in your web browser.
  • To run just the ESLint rule tests, load {orion-server-url}/js-tests/javascript/JsMochaSuite.html?grep=ESLint%20Rule%20Tests in your browser.
  • To run just the ESLint core tests, load {orion-server-url}/js-tests/javascript/JsMochaSuite.html?grep=ESLint%20Core%20Tests in your browser.
  • To run only a subset of the tests, add ?grep=ESLint%20Rule%20Tests onto the test page URL.

See Mocha usage options for more options.

User interface

  • Should we have a UI for configuring what rules are active? bug 424268.
  • Should we try to support .eslintrc? This would be an ideal project-scope setting.
  • Should we try to honor equivalent JSLint/JSHint flags when possible? For example /*jslint eqeqeq:false */ could disable the eqeqeq rule on a per-file basis.
    • ESLint now has its own syntax for this: /*eslint ..*/, which we are using instead.

i18n

We need to support i18n. Pre-req is bug 422278 (orion.edit.validator support for i18n).

Back to the top