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"

(Rules)
(Code Style)
(121 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Orion 5.0 will replace our current [http://www.jslint.com/ JSLint validator] with [https://github.com/nzakas/eslint/ ESLint]. This page captures ongoing issues.
+
Orion 5.0 introduced [https://github.com/nzakas/eslint/ ESLint] as the validator that ships with Orion. This page captures ongoing issues.
  
 
== Rules ==  
 
== Rules ==  
Here's a table showing the equivalent validation rules in JSLint and ESLint. If a rule has no "JSLint option", then JSLint always enforces it and it cannot be disabled.
+
The following sections describe 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%;"
+
=== Potential Programming Problems ===
! ESLint rule
+
These rules report about problems with your code that might have undesired or incorrect results. Warnings from these
! JSLint option
+
rules should be addressed.
! JSLint message
+
! Details
+
|-
+
  
| block-scoped-var
+
{| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
| -
+
! width=12% | Rule
| '''{variable}' is already defined.''
+
! width=6% | Default Severity
|
+
! width=5% | Available Since
* Occurs when a function-scoped variable is treated as if it was block scoped.
+
! width=35%| Problem Message
* ESLint calls this error '{variable} used outside of binding context.'
+
! width=40% | Details
 +
! width=5% | Quick Fix?
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455253 no-comma-dangle]
| brace-style
+
| Ignore
| -
+
|style="text-align:center;"| 8.0
| (Not supported)
+
| ''Trailing commas in object expressions are discouraged.''
 +
| Flags trailing commas in object expressions.
 +
|style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455250 no-cond-assign]
| camelcase
+
| Error
| -
+
|style="text-align:center;"| 8.0
| (Not supported)
+
| ''Expected a conditional expression and instead saw an assignment.''
|-
+
| Flags assignment in an <code>if/while/do..while/for</code> condition.
 
+
| complexity
+
| -
+
| (Not supported)
+
|-
+
 
+
| consistent-this
+
| -
+
| (Not supported)
+
|-
+
 
+
| curly
+
| -
+
|
+
* ''Statement body should be inside '{ }' braces.'' (Orion)
+
* ''Expected '{'.'' (Regular JSLint)
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455371 no-console]
| dot-notation
+
| Error
| '''sub'''
+
|style="text-align:center;"| 8.0
| ''{a} is better written in dot notation.''
+
| ''Discouraged use of console in browser-based code.''
 +
| Flags the use of console in browser-based code
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455680 no-constant-condition]
| eqeqeq
+
| Error
| '''eqeqeq''' or '''eqeq'''
+
|style="text-align:center;"| 8.0
|
+
| ''Discouraged use of constant as a conditional expression.''
* ''Expected '===' and saw '=='.''
+
| Flags the use of a constant as a conditional expression
* ''Expected '!==' and saw '!='.''
+
|
+
* Newer versions of JSLint call this option '''eqeqeq'''.
+
* Orion's version calls it '''eqeq''', and inverts the flag's value.
+
|-
+
 
+
| guard-for-in
+
| '''forin'''
+
| ''The body of a <code>for in</code> should be wrapped in an <code>if</code> statement to filter unwanted properties from the prototype.''
+
|-
+
 
+
| max-depth
+
| -
+
| (Not supported)
+
| Enforces max depth of nested blocks within a function.
+
|-
+
 
+
| max-len
+
| '''maxlen'''
+
| ''Line too long.''
+
| Enforces a maximum line length.
+
|-
+
 
+
| max-params
+
| -
+
| (Not supported)
+
|-
+
 
+
| max-statements
+
| -
+
| (Not supported)
+
|-
+
 
+
| new-cap
+
| '''newcap'''
+
| A constructor name should start with an uppercase letter.
+
|-
+
 
+
| new-parens
+
| -
+
| ''Missing '()' invoking a constructor.''
+
| Flags <code>new Whatever</code>
+
|-
+
 
+
| no-alert
+
| '''devel'''
+
| '''{alert, confirm, prompt}' is not defined.''
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-debugger]
| no-bitwise
+
| Warning
| '''bitwise'''
+
|style="text-align:center;"| 6.0
| Unexpected use of '{operator}'.
+
| ''debugger' statement use is discouraged.''
| JSLint disallows bitwise ops by default.
+
| Warns when the <code>debugger</code> keyword is used
|-
+
 
+
| no-caller
+
| -
+
| (Not supported)
+
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
+
|-
+
 
+
| no-catch-shadow
+
|
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]
| no-comma-dangle
+
| Error
| -
+
|style="text-align:center;"| 6.0
| Unexpected comma.
+
| ''Duplicate object key '{key}'.''
| Flags trailing commas in object literals.
+
| Flags object literals that contain the same key more than once.
|-
+
 
+
| no-cond-assign
+
|
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=439366 no-empty-block]
| no-console
+
| Warning
| '''devel'''
+
|style="text-align:center;"| 7.0
|  
+
| ''Empty block should be removed or commented.''
 +
| Flags an empty block like <code>if (something) { }</code>.
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 no-extra-semi]
| no-control-regex
+
| Warning
|  
+
|style="text-align:center;"| 5.0
|  
+
| ''Unnecessary semicolon.''
 +
| Warns when a semicolon is found where it is not needed
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429815 no-fallthrough]
| no-debugger
+
| Error
| '''debug'''
+
|style="text-align:center;" | 6.0
| ''All 'debugger' statements should be removed.''
+
| ''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.
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455391 no-regex-spaces]
| no-delete-var
+
| Error
| -
+
|style="text-align:center;"| 8.0
| ''Expected '.' and instead saw ';'.''
+
| ''Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead.''
| Flags an attempt to <code>delete</code> a local variable.
+
| Flags regular expressions that have two or more subsequent spaces.
|-
+
 
+
| no-div-regex
+
|
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455354 no-reserved-keys]
| no-dupe-keys
+
| Error
| -
+
|style="text-align:center;"| 8.0
| ''Duplicate key '{a}'.''
+
| ''Reserved words should not be used as property keys.''
| Flags object literals that contain the same key more than once.
+
| Checks to see if a JavaScript reserved word is being used as a property key
|-
+
 
+
| no-else-return
+
|
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=426723 no-sparse-arrays]
| no-empty-class
+
| Warning
|  
+
|style="text-align:center;"| 8.0
|  
+
| ''Sparse array declarations should be avoided.''
 +
| Flags sparse arrays with null elements like <code>var arr = [1, ,2]</code>
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=436986 no-unreachable]
| no-empty-label
+
| Error
|  
+
|style="text-align:center;"| 6.0
|  
+
| ''Unreachable code.''
 +
| Flags statements that occur after a <code>return</code>, <code>throw</code>, etc.
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429711 use-isnan]
| no-empty
+
| Error
| -
+
|style="text-align:center;"| 6.0
| (Not supported)
+
| ''Use the isNaN function to compare with NaN.''
| Flags an empty block like <code>if (something) { }</code>
+
| Warns when a comparison is done against NaN without using the <code>isNaN</code> function
|-
+
 
+
| no-eq-null
+
| -
+
| ''Use '===' to compare with 'null'.''
+
| JSLint produces a similar warning when comparing against <code>undefined</code>.
+
|-
+
 
+
| no-eval
+
| '''evil'''
+
| ''eval is evil.''
+
|-
+
 
+
| no-ex-assign
+
| -
+
| ''Do not assign to the exception parameter.''
+
|-
+
 
+
| no-extra-semi
+
| -
+
| ''Unnecessary semicolon.''
+
|-
+
 
+
| no-fallthrough
+
|
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=447189 valid-typeof]
| no-floating-decimal
+
| Error
|  
+
|style="text-align:center;"| 7.0
 +
| ''Invalid typeof comparison.''
 +
| Warns when a typeof comparison uses an invalid type.
 
|  
 
|  
 
|-
 
|-
 +
|}
  
| no-func-assign
+
=== Best Practices ===
|
+
These rules are not necessarily problem with your code, but are warnings that you might be doing something
|
+
you probably should not be.
|-
+
  
| no-global-strict
+
{| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
|  
+
! width=12% | Rule
|  
+
! width=6% | Default Severity
 +
! width=5% | Available Since
 +
! width=35%| Problem Message
 +
! width=40% | Details
 +
! width=5% | Quick Fix?
 
|-
 
|-
  
| no-implied-eval
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428433 block-scoped-var]
|
+
| Error
|
+
|style="text-align:center;" | -
|-
+
| '''{variable}' is already defined.''
 
+
| no-iterator
+
|
+
|  
+
|-
+
 
+
| no-label-var
+
| -
+
| '''{label}' is already defined.''
+
| Flags labels that collide with an identifier.
+
|-
+
 
+
| no-loop-func
+
| -
+
| ''Don't make functions within a loop.''
+
 
|
 
|
|-
+
* Occurs when a function-scoped variable (<tt>var</tt>) is treated as if it was block scoped.
 
+
* ESLint calls this error '{variable} used outside of binding context.'
| no-mixed-requires
+
|
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429722 curly]
| no-multi-str
+
| Ignore
|  
+
|style="text-align:center;" | 6.0
 +
| ''Statements should be enclosed in braces.''
 +
| Warns when statements should be enclosed in braces, for example <code>if(something) foo();</code>
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 eqeqeq]
| no-native-reassign
+
| Warning
| -
+
|style="text-align:center;" | 5.0
 
|
 
|
* ''Read only.''
+
* ''Expected '===' and saw '=='.''
* ''Bad assignment.'' (if assigning to <code>undefined</code>)
+
* ''Expected '!==' and saw '!='.''
| Flags an attempt to reassign a native object like <code>Math</code>, Array, <code>undefined</code>, etc.
+
| Warns when <code>==</code> or <code>!=</code> is used
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=460976 no-caller]
| no-negated-in-lhs
+
| Error
|  
+
|style="text-align:center;" | 9.0
 +
| ''arguments.{callee, caller} is deprecated.''
 +
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]
| no-new-array
+
| Ignore
| -
+
|style="text-align:center;" | 6.0
| ''Use the array literal notation [].''
+
| '''eval' function calls are discouraged.''
| Flags <code>new Array()</code>
+
| Warns when the <code>eval()</code> function is used
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461929 no-implied-eval]
| no-new-func
+
| Ignore
|  
+
|style="text-align:center;" | 6.0
 +
| ''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.
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455643 no-iterator]
| no-new-object
+
| Error
| -
+
|style="text-align:center;" | 8.0
| ''Use the object literal notation {}.''
+
| ''Discouraged __iterator__ property use.''
|-
+
| Flags use of <code>__iterator__</code> as an identifier name or property key.
 
+
| no-new-wrappers
+
 
|  
 
|  
| Do not use {String, Number, Boolean, Math, JSON} as a constructor.
 
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-array]
| no-new
+
| Warning
| -
+
|style="text-align:center;" | 6.0
| ''Do not use 'new' for side effects.''
+
| ''Use the array literal notation [].''
| Flags uses of <code>new</code> operator in an expression that is not assigned to anything.
+
| Flags <code>new Array()</code>.
|-
+
 
+
| no-obj-calls
+
|
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]
| no-octal-escape
+
| Warning
|  
+
|style="text-align:center;" | 6.0
 +
| ''The Function constructor is eval.''
 +
| Flags <code>new Function()</code>.
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]
| no-octal
+
| Warning
|  
+
|style="text-align:center;" | 6.0
 +
| ''Use the object literal notation {}.''
 +
| Flags <code>new Object()</code>.
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]
| no-plusplus
+
| Warning
| '''plusplus'''
+
|style="text-align:center;" | 6.0
 +
| ''Do not use {String, Number, Boolean, Math, JSON} as a constructor.''
 +
| Flags <code>new</code> applied to any of those.
 
|  
 
|  
* ''Unexpected use of '++'''
 
* ''Unexpected use of '--'''
 
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461848 no-proto]
| no-proto
+
| Error
| -
+
|style="text-align:center;" | -
 
|
 
|
* ''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.
+
| Flags use of the property <code>__proto__</code> as object keys or in assignments
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]
| no-redeclare
+
| Warning
| -
+
|style="text-align:center;" | 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
 
| -
 
| (Not supported)
 
| Prevents assignment in a <code>return</code> statement.
 
|-
 
 
| no-script-url
 
|
 
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461850 no-self-compare]
| no-self-compare
+
| Error
|  
+
|style="text-align:center;" | -
 +
| ''Comparing a value to itself has no effect.''
 +
| Flags comparisons where the left- and right-hand sides are the same.
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438319 no-shadow]
| no-shadow
+
| Warning
|  
+
|style="text-align:center;" | 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.
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461321 no-shadow-global]
| no-spaced-func
+
| Warning
|  
+
|style="text-align:center;" | 9.0
 +
| '''{a}' shadows a global member.''
 +
| Flags variables that have the same name as a variable declared in the global scope or specified environments.
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=6e517847ef0742b090130748fb9a0329d33e16bf no-throw-literal]
| no-sync
+
| Warning
| '''stupid'''
+
|style="text-align:center;" | 9.0
| ''Unexpected sync method: '{a}'.''
+
| ''Throw an Error instead.''
|
+
| Flags code that throws a literal, eg. <code>throw "a problem occurred";</code>
* Flags Node.js's synchronous I/O methods.
+
* The '''stupid''' option is supported only in newer versions of JSLint (not Orion's).
+
|-
+
 
+
| no-ternary
+
|
+
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-undef]
| no-undef-init
+
| Error
| -
+
|style="text-align:center;" | 5.0
| ''It is not necessary to initialize '{variable}' to 'undefined'.''
+
|  
+
|-
+
 
+
| no-undef
+
| '''undef'''
+
 
| '''{variable}' is not defined.''
 
| '''{variable}' is not defined.''
 
|
 
|
 
* Flags references to a global variable that is not listed in a /*global*/ or /*globals*/ block.
 
* 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.
+
* Predefined environments (eg. '''node''', '''browser''', '''amd''') can be set in a /*eslint-env */ block.
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=427310 no-unused-params]
| no-underscore-dangle
+
| Warning
| '''nomen'''
+
|style="text-align:center;" | 6.0
| ''Dangling '_'''
+
| ''Parameter '{param}' is not used.''
 +
| Flags parameters in function declarations / expressions if they are not being used
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-unused-vars]
| no-unreachable
+
| Warning
 +
|style="text-align:center;" | 5.0
 
|  
 
|  
 +
*'''{a}' is not read.''
 +
*'''{a}' is read-only.''
 +
| Warns when a variable is created and not used (read) or a variable that is read-only is assigned to.
 +
| style="text-align:center;" | ✔
 +
|-
 +
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-use-before-define]
 +
| Warning
 +
|style="text-align:center;" | 5.0
 +
| '''{a}' was used before it was defined.''
 +
| Warns when a variable or function is used before it is defined
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461854 no-with]
| no-unused-expressions
+
| Warning
| -
+
|style="text-align:center;" | -
| ''Expected an assignment or function call and instead saw an expression.''
+
| ''Expected an identifier and instead saw 'with'.''
| Flags expressions that appear in a statement context and don't cause side effects.
+
| Treated as fatal parse error in JSLint.
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=f61bdaf06ac2f40eaca4daed39520cd60c41f5f3 radix]
| no-unused-vars
+
| Warning
| -
+
|style="text-align:center;" | 8.0
| ''Function declares unused variable '{a}'.'' (Orion)
+
| ''Missing radix parameter.''
| Newer JSlint versions have an '''unparam''' option which works similarly.
+
| Warns when parseInt() called without the 2nd parameter (radix).
 +
|  
 
|-
 
|-
 +
|}
  
| no-use-before-define
+
=== Code Style ===
| -
+
These rules are not problems in any way but will warn based on certain accepted styles for coding.
| '''{a}' was used before it was defined.''
+
|-
+
  
| no-with
+
{| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
| -
+
! width=12% | Rule
| Expected an identifier and instead saw 'with'.
+
! width=6% | Default Severity
| Treated as fatal parse error in JSLint.
+
! width=5% | Available Since
 +
! width=35%| Problem Message
 +
! width=40% | Details
 +
! width=5% | Quick Fix?
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424128 missing-doc]
| no-wrap-func
+
| Ignore
 +
|style="text-align:center;" | 5.0
 +
| ''Missing documentation for function '{name}'.''
 +
| Flags missing documentation nodes on function declarations and function expressions when they appear as object properties
 
|  
 
|  
 +
|-
 +
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424204 missing-doc-items]
 +
| Ignore
 +
|style="text-align:center;" | -
 +
| ''Missing '{a}' tag for '{b}'.''
 +
| Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428429 missing-nls]
| one-var
+
| Ignore
| '''vars'''
+
|style="text-align:center;" | 9.0
 +
| ''Non-externalized string literal '{a}'.''
 +
| Flags String literals that are not properly NLS'd
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]
| quote-props
+
| Error
 +
|style="text-align:center;" | 6.0
 +
| ''Missing parentheses invoking constructor.''
 +
| Flags <code>new Whatever</code>
 
|  
 
|  
 +
|-
 +
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438095 no-jslint]
 +
| warning
 +
|style="text-align:center;" | 7.0
 +
| ''The 'jslint' directive is unsupported, please use eslint-env.''
 +
| Flags use of the /* jslint */ directive
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=425200 no-mixed-returns]
| quotes
+
| Error
| -
+
|style="text-align:center;" | -
| (Not supported)
+
| ''Mixed return types should be avoided.''
 +
| Flags functions that return more than one kind of item, for example returning String and Object
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461852 no-undef-init]
| radix
+
| Warning
| -
+
|style="text-align:center;" | -
| ''Missing radix parameter.''
+
| ''It is not necessary to initialize '{variable}' to 'undefined'.''
| Affects parseInt().
+
| Warns when an explicit assignment to undefined is done, for example <code>var foo = undefined;</code>
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=427930 semi]
| regex-spaces
+
| Warning
| -
+
|style="text-align:center;" | 5.0
| ''Spaces are hard to count. Use {n}.''
+
|-
+
 
+
| semi
+
| -
+
 
| ''Missing semicolon.''
 
| ''Missing semicolon.''
|
+
| Warns when a semicolon should be used but is not
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 +
|}
  
| strict
+
== Implementing a new rule ==
| '''strict'''
+
''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.''
|
+
| Flags any code that lacks the <code>"use strict"</code> pragma.
+
|-
+
  
| unnecessary-strict
+
First, create the tests and rule:
|  
+
# Create a new <tt>describe("{rule-name}")</tt> block in: <tt>/js-tests/javascript/eslintRuleTests.js</tt>. Add several tests to it.
|
+
# [[#Running the tests|Run the JS bundle tests]] and ensure that your new tests fail.
|-
+
# Implement the actual logic for your rule in <tt>/eslint/lib/load-rules-async.js</tt>.
 +
# Run the tests again. This time they should all pass.
  
| use-isnan
+
To get your rule running in the Orion product's validator, there are additional steps:
| -
+
# Create strings for the validation message(s) generated by your rule in <tt>/javascript/nls/root/problems.js</tt>.
| ''Use the isNaN function to compare with NaN.''
+
# Create a short string describing what your rule does in <tt>/javascript/nls/root/messages.js</tt>.
|-
+
# 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>.
  
| wrap-iife
+
Reload the JS plugin, and your rule should now be configurable from the Settings page, and properly set up for translation too.
| '''immed'''
+
|
+
* ''Wrap the entire immediate function invocation in parens.''
+
* ''Do not wrap function literals in parens unless they are to be immediately invoked.''
+
* ''Move the invocation into the parens that contain the function.''
+
|
+
|-
+
  
| wrap-regex
+
== Tests ==
| -
+
* Every rule needs extensive unit tests.
| ''Wrap the /regexp/ literal in parens to disambiguate the slash operator.''
+
* Unit tests should use [http://mochajs.org Mocha].
|-
+
  
 +
=== Running the tests ===
 +
* 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.
 +
** 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.
  
|}
+
See [http://mochajs.org/#grep-query Mocha usage options] for more options.
 +
 
 +
== User interface ==
 +
* <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.
 +
 
 +
== i18n ==
 +
<del>We need to support i18n. Pre-req is {{bug|422278}} (orion.edit.validator support for i18n).</del>
  
== Rule priority ==
+
[[Category:Orion]]
Here are the rules we want, in order of priority:
+
# no-undef
+

Revision as of 17:07, 14 April 2015

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

Rules

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

Potential Programming Problems

These rules report about problems with your code that might have undesired or incorrect results. Warnings from these rules should be addressed.

Rule Default Severity Available Since Problem Message Details Quick Fix?
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-constant-condition Error 8.0 Discouraged use of constant as a conditional expression. Flags the use of a constant as a conditional expression
no-debugger Warning 6.0 debugger' statement use is discouraged. Warns when the debugger keyword is used
no-dupe-keys Error 6.0 Duplicate object key '{key}'. Flags object literals that contain the same key more than once.
no-empty-block Warning 7.0 Empty block should be removed or commented. Flags an empty block like if (something) { }.
no-extra-semi Warning 5.0 Unnecessary semicolon. Warns when a semicolon is found where it is not needed
no-fallthrough Error 6.0 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-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-sparse-arrays Warning 8.0 Sparse array declarations should be avoided. Flags sparse arrays with null elements like var arr = [1, ,2]
no-unreachable Error 6.0 Unreachable code. Flags statements that occur after a return, throw, etc.
use-isnan Error 6.0 Use the isNaN function to compare with NaN. Warns when a comparison is done against NaN without using the isNaN function
valid-typeof Error 7.0 Invalid typeof comparison. Warns when a typeof comparison uses an invalid type.

Best Practices

These rules are not necessarily problem with your code, but are warnings that you might be doing something you probably should not be.

Rule Default Severity Available Since Problem Message Details Quick Fix?
block-scoped-var Error - '{variable}' is already defined.
  • Occurs when a function-scoped variable (var) is treated as if it was block scoped.
  • ESLint calls this error '{variable} used outside of binding context.'
curly Ignore 6.0 Statements should be enclosed in braces. Warns when statements should be enclosed in braces, for example if(something) foo();
eqeqeq Warning 5.0
  • Expected '===' and saw '=='.
  • Expected '!==' and saw '!='.
Warns when == or != is used
no-caller Error 9.0 arguments.{callee, caller} is deprecated. Flags references to arguments.callee and arguments.caller.
no-eval Ignore 6.0 'eval' function calls are discouraged. Warns when the eval() function is used
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-new-array Warning 6.0 Use the array literal notation []. Flags new Array().
no-new-func Warning 6.0 The Function constructor is eval. Flags new Function().
no-new-object Warning 6.0 Use the object literal notation {}. Flags new Object().
no-new-wrappers Warning 6.0 Do not use {String, Number, Boolean, Math, JSON} as a constructor. Flags new applied to any of those.
no-proto Error -
  • Reserved name '__proto__' should not be assigned.
  • Reserved name '__proto__' should not be used as a key.
Flags use of the property __proto__ as object keys or in assignments
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-self-compare Error - Comparing a value to itself has no effect. 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-shadow-global Warning 9.0 '{a}' shadows a global member. Flags variables that have the same name as a variable declared in the global scope or specified environments.
no-throw-literal Warning 9.0 Throw an Error instead. Flags code that throws a literal, eg. throw "a problem occurred";
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, amd) can be set in a /*eslint-env */ block.
no-unused-params Warning 6.0 Parameter '{param}' is not used. Flags parameters in function declarations / expressions if they are not being used
no-unused-vars Warning 5.0
  • '{a}' is not read.
  • '{a}' is read-only.
Warns when a variable is created and not used (read) or a variable that is read-only is assigned to.
no-use-before-define Warning 5.0 '{a}' was used before it was defined. Warns when a variable or function is used before it is defined
no-with Warning - Expected an identifier and instead saw 'with'. Treated as fatal parse error in JSLint.
radix Warning 8.0 Missing radix parameter. Warns when parseInt() called without the 2nd parameter (radix).

Code Style

These rules are not problems in any way but will warn based on certain accepted styles for coding.

Rule Default Severity Available Since Problem Message Details Quick Fix?
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 - Missing '{a}' tag for '{b}'. Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties
missing-nls Ignore 9.0 Non-externalized string literal '{a}'. Flags String literals that are not properly NLS'd
new-parens Error 6.0 Missing parentheses invoking constructor. Flags new Whatever
no-jslint warning 7.0 The 'jslint' directive is unsupported, please use eslint-env. Flags use of the /* jslint */ directive
no-mixed-returns Error - Mixed return types should be avoided. Flags functions that return more than one kind of item, for example returning String and Object
no-undef-init Warning - It is not necessary to initialize '{variable}' to 'undefined'. Warns when an explicit assignment to undefined is done, for example var foo = undefined;
semi Warning 5.0 Missing semicolon. Warns when a semicolon should be used but is not

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 describe("{rule-name}") block in: /js-tests/javascript/eslintRuleTests.js. Add several tests to it.
  2. Run the JS bundle tests and ensure that your new tests fail.
  3. Implement the actual logic for your rule in /eslint/lib/load-rules-async.js.
  4. Run the tests again. This time they should all pass.

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