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"

(Add link to quickfix for radix rule)
(193 intermediate revisions by 5 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 sortable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
| -
+
! width=13% | Rule
| '{variable}' is already defined.
+
! width=5% | Default Severity
| Occurs when a function-scoped variable is treated as if it was block scoped.<br>ESLint calls this error '{variable} used outside of binding context.'
+
! width=3% | Available Since
 +
! width=24% | Setting Message
 +
! width=24%| Problem Message
 +
! width=24% | Details
 +
! width=3% | Quick Fix?
 +
! width=3% | Fix All?
 
|-
 
|-
 
+
!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
|  
+
|Trailing commas in object expressions
 +
| ''Trailing commas in object expressions are discouraged.''
 +
| Flags trailing commas in object expressions.
 +
|style="text-align:center;" | ✔
 +
|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
|  
+
|Assignments in conditional expressions
 +
| ''Expected a conditional expression and instead saw an assignment.''
 +
| Flags assignment in an <code>if/while/do..while/for</code> condition.
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486129 Future]
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455371 no-console]
| complexity
+
| Ignore
|  
+
|style="text-align:center;"| 8.0
 +
|Discouraged console use in browser code
 +
| ''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]
| consistent-this
+
| Error
|  
+
|style="text-align:center;"| 8.0
|  
+
|Constant as conditional expression
 +
| ''Discouraged use of constant as a conditional expression.''
 +
| Flags the use of a constant as a conditional expression
 +
|
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-control-regex]
| curly
+
| Error
|  
+
|style="text-align:center;"| 11.0
|  
+
|Disallow control characters in regular expressions
 +
| ''Unexpected control character in regular expression''
 +
| Control characters are special, invisible characters in the ASCII range 0-31. These characters are rarely used in JavaScript strings so a regular expression containing these characters is most likely a mistake.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-debugger]
| dot-notation
+
| Warning
| '''sub'''
+
|style="text-align:center;"| 6.0
| {a} is better written in dot notation.
+
|Discouraged 'debugger' statement use
 +
| ''debugger' statement use is discouraged.''
 +
| Warns when the <code>debugger</code> keyword is used
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=485767 ✔]
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=485767 ✔]
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-dupe-args]
| eqeqeq
+
| Error
| '''eqeqeq'''<br>'''eqeq'''
+
|style="text-align:center;"|
| Expected '===' and saw '=='.<br>Expected '!==' and saw '!='.
+
|Duplicate parameter names
| '''eqeq''' only appears in old versions of JSLint (like Orion's), has opposite on/off state to '''eqeqeq'''.
+
| ''Duplicate param '${0}'''
 +
| Warns when there are duplicate function parameter names.
 +
| style="text-align:center;" | Future
 +
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]
| guard-for-in
+
| Error
| '''forin'''
+
|style="text-align:center;"| 6.0
| The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
+
|Duplicate object keys
 +
| ''Duplicate object key '{key}'.''
 +
| Flags object literals that contain the same key more than once.
 +
| style="text-align:center;" |[https://bugs.eclipse.org/bugs/show_bug.cgi?id=485953 ✔]
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-duplicate-case]
| max-depth
+
| Error
|  
+
|style="text-align:center;"| 11.0
|  
+
|Duplicate case
 +
| ''Duplicate case label.''
 +
| A switch statements with duplicate case labels is normally an indication of a programmer error.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=439366 no-empty-block]
| max-len
+
| Warning
| '''maxlen'''
+
|style="text-align:center;"| 7.0
| Line too long.
+
|Undocumented empty block
 +
| ''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=467903 no-empty-character-class]
| max-params
+
| Error
|  
+
|style="text-align:center;"| 11.0
|  
+
|Disallow empty character classes
 +
| ''Empty class.''
 +
| Empty character classes in regular expressions do not match anything and can result in code that may not work as intended.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-extra-boolean-cast]
| max-statements
+
| Error
|  
+
|style="text-align:center;"| 11.0
|  
+
|Discourage redundant double negation
 +
| [http://eslint.org/docs/rules/no-extra-boolean-cast no-extra-boolean-cast]
 +
| In contexts such as an if statement's test where the result of the expression will already be coerced to a Boolean, casting to a Boolean via double negation (!!) is unnecessary.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-extra-parens]
| new-cap
+
| Warning
| '''newcap'''
+
|style="text-align:center;"| 11.0
| A constructor name should start with an uppercase letter.
+
| Discourage redundant parentheses
 +
| ''Gratuitous parentheses around expression.''
 +
| This rule restricts the use of parentheses to only where they are necessary. It may be restricted to report only function expressions.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 no-extra-semi]
| new-parens
+
| Warning
| -
+
|style="text-align:center;"| 5.0
| Missing '()' invoking a constructor.
+
|Unnecessary semicolons
| Flags <code>new Whatever</code>
+
| ''Unnecessary semicolon.''
 +
| Warns when a semicolon is found where it is not needed
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429815 no-fallthrough]
| no-alert
+
| Error
|  
+
|style="text-align:center;" | 6.0
|  
+
|Switch case fall-through
 +
| ''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:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-invalid-regexp]
| no-bitwise
+
| Error
| '''bitwise'''
+
|style="text-align:center;"| 11.0
| Unexpected use of '{operator}'.
+
|Invalid regular expressions
| JSLint disallows bitwise ops by default.
+
| ''Invalid flags supplied to RegExp constructor '{${0}}'.'' or the error message from calling the constructor with the regex
 +
| This rule validates string arguments passed to the RegExp constructor.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=482616 no-irregular-whitespace]
| no-caller
+
| Ignore
| -
+
|style="text-align:center;"| 11.0
| (Not supported)
+
|Mixed spaces and tabs
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
+
| ''Irregular whitespace not allowed.''
 +
| Invalid or irregular whitespace causes issues with ECMAScript 5 parsers and also makes code harder to debug in a similar nature to mixed tabs and spaces.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-negated-in-lhs]
| no-catch-shadow
+
| Error
|  
+
|style="text-align:center;"| 11.0
|  
+
|Disallow negated left operand of in operator
 +
| ''The 'in' expression's left operand is negated.''
 +
| Disallow negated left operand of in operator
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-obj-calls]
| no-comma-dangle
+
| Error
| -
+
|style="text-align:center;"| 11.0
| Unexpected comma.
+
|Disallow global object as function calls
| Flags trailing commas in object literals.
+
| '' '{${0}}' is not a function.''
 +
| ECMAScript provides several global objects that are intended to be used as-is. Some of these objects look as if they could be constructors due their capitalization (such as Math and JSON) but will throw an error if you try to execute them as functions.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455391 no-regex-spaces]
| no-cond-assign
+
| Error
|  
+
|style="text-align:center;"| 8.0
|  
+
|Multiple spaces in regular expressions
 +
| ''Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead.''
 +
| Flags regular expressions that have two or more subsequent spaces.
 +
| style="text-align:center;" |
 +
| style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455354 no-reserved-keys]
| no-console
+
| Error
|  
+
|style="text-align:center;"| 8.0
|  
+
|Reserved words used as property keys
 +
| ''Reserved words should not be used as property keys.''
 +
| Checks to see if a JavaScript reserved word is being used as a property key
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=485980 ✔]
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=426723 no-sparse-arrays]
| no-control-regex
+
| Warning
|  
+
|style="text-align:center;"| 8.0
|  
+
|Sparse array declarations
 +
| ''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:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=436986 no-unreachable]
| no-debugger
+
| Error
|  
+
|style="text-align:center;"| 6.0
|  
+
|Unreachable code
 +
| ''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-delete-var
+
| Error
|  
+
|style="text-align:center;"| 6.0
|  
+
|NaN not compared with isNaN()
 +
| ''Use the isNaN function to compare with NaN.''
 +
| Warns when a comparison is done against NaN without using the <code>isNaN</code> function
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=470189 ✔]
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=485977 ✔]
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=447189 valid-typeof]
| no-div-regex
+
| Error
|  
+
|style="text-align:center;"| 7.0
 +
|Invalid 'typeof' comparison
 +
| ''Invalid typeof comparison.''
 +
| Warns when a typeof comparison uses an invalid type.
 
|  
 
|  
 +
|
 
|-
 
|-
 +
|}
  
| no-dupe-keys
+
=== Best Practices ===
| -
+
These rules are not necessarily problem with your code, but are warnings that you might be doing something
| Duplicate key '{a}'.
+
you probably should not be.
| Flags object literals that contain the same key more than once.
+
|-
+
  
| no-else-return
+
{| class="wikitable sortable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
|  
+
! width=13% | Rule
|  
+
! width=5% | Default Severity
 +
! width=3% | Available Since
 +
! width=24% | Setting Message
 +
! width=24%| Problem Message
 +
! width=24% | Details
 +
! width=3% | Quick Fix?
 +
! width=3% | Fix All?
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 accessor-pairs]
| no-empty-class
+
| Warning
|  
+
|style="text-align:center;"| 11.0
|  
+
|Getter and setter accessors not in pairs
 +
| ''Getter is not present'' or ''Setter is not present''
 +
| It's a common mistake in JavaScript to create an object with just a setter for a property but never have a corresponding getter defined for it. Without a getter, you cannot read the property, so it ends up not being used.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428433 block-scoped-var]
| no-empty-label
+
| Error
|  
+
|style="text-align:center;" | -
 +
|
 +
| '''{variable}' used outside of binding context.''
 +
|
 +
Occurs when a function-scoped variable (<tt>var</tt>) is treated as if it was block scoped.
 
|  
 
|  
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429722 curly]
| no-empty
+
| Ignore
| -
+
|style="text-align:center;" | 6.0
| (Not supported)
+
|Statements not enclosed in braces
| Flags an empty block like if (..) { }
+
| ''Statements should be enclosed in braces.''
 +
| Warns when statements should be enclosed in braces, for example <code>if(something) foo();</code>
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=454641 ✔]
 +
| style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 eqeqeq]
| no-eq-null
+
| Warning
|  
+
|style="text-align:center;" | 5.0
|  
+
|Discouraged '==' use
 +
|
 +
* ''Expected '===' and saw '=='.''
 +
* ''Expected '!==' and saw '!='.''
 +
| Warns when <code>==</code> or <code>!=</code> is used
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=460976 no-caller]
| no-eval
+
| Error
| '''evil'''
+
|style="text-align:center;" | 9.0
| eval is evil.
+
|Discouraged 'arguments.caller' or 'arguments.callee' use
 +
| ''arguments.{callee, caller} is deprecated.''
 +
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=459934 Future]
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-else-return]
| no-ex-assign
+
| Warning
| -
+
|style="text-align:center;"| 11.0
| Do not assign to the exception parameter.
+
|Unnecessary else after return
 +
| ''Unexpected 'else' after 'return'.''
 +
| If an if block contains a return statement, the else block becomes unnecessary. Its contents can be placed outside of the block.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-empty-label]
| no-extra-semi
+
| Error
| -
+
|style="text-align:center;"| 11.0
| Unnecessary semicolon.
+
|No empty labels
 +
| ''Unexpected label "{${0}}"''
 +
| Labeled statements are only used in conjunction with labeled break and continue statements. ECMAScript has no goto statement.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=467903 no-eq-null]
| no-fallthrough
+
| Error
|  
+
|style="text-align:center;"| 11.0
|  
+
|Disallow null comparisons
 +
| ''Use ‘===’ to compare with ‘null’.'' or ''Use ‘!==’ to compare with ‘null’.''
 +
| Comparing to null without a type-checking operator (== or !=), can have unintended results as the comparison will evaluate to true when comparing to not just a null, but also an undefined value.
 +
|style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=485171 ✔]
 +
|style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=485171 ✔]
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]
| no-floating-decimal
+
| Ignore
|  
+
|style="text-align:center;" | 6.0
|  
+
|Discouraged 'eval()' use
 +
| '''eval' function calls are discouraged.''
 +
| Warns when the <code>eval()</code> function is used
 +
|
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486766 no-extend-native]
| no-func-assign
+
| Error
|  
+
|style="text-align:center;" |
|  
+
|Discouraged built-in object modification
 +
| '''${0}' prototype is read only, properties should not be added.''
 +
| Warns when directly modifying the prototype of builtin objects.
 +
|
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486765 no-extra-bind]
| no-global-strict
+
| Warning
|  
+
|style="text-align:center;" |
|  
+
|Unnecessary 'bind()' use
 +
| ''The function binding is unnecessary.''
 +
| Warns about unnecessary use of bind()
 +
|
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486764 no-implicit-coercion]
| no-implied-eval
+
| Warning
|  
+
|style="text-align:center;" |
|  
+
|Discouraged implicit coercion use
 +
| ''use `${0}` instead.'' Example: ''use `Boolean(foo)` instead.''
 +
| Warns when shorter notations are used for the type conversion, then suggest a more self-explanatory notation.
 +
| style="text-align:center;" | Future
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461929 no-implied-eval]
| no-iterator
+
| Ignore
|  
+
|style="text-align:center;" | 6.0
 +
|Discouraged implied 'eval()' use
 +
| ''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=486763 no-invalid-this]
| no-label-var
+
| Warning
|  
+
|style="text-align:center;" |
 +
|Discouraged 'this' use
 +
| ''Unexpected `this`''
 +
| This rule aims to flag usage of 'this' keywords outside of classes or class-like objects
 
|  
 
|  
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455643 no-iterator]
| no-loop-func
+
| Error
|  
+
|style="text-align:center;" | 8.0
 +
|Discouraged __iterator__ property use
 +
| ''Discouraged __iterator__ property use.''
 +
| Flags use of <code>__iterator__</code> as an identifier name or property key.
 
|  
 
|  
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486761 no-lone-blocks]
| no-mixed-requires
+
| Warning
|  
+
|style="text-align:center;" |
|  
+
|Discouraged lone block use
 +
| ''Block is redundant.'' or ''Nested block is redundant.''
 +
| Flags use of unnecessary and potentially confusing blocks at the top level of a script or within other blocks.
 +
| style="text-align:center;" | Future
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486760 no-native-reassign]
| no-multi-str
+
| Error
|  
+
|style="text-align:center;" |
 +
|Discouraged built-in native object reassignment
 +
| '''${0}' is a read-only native object.''
 +
| Flags reassignment of built-in native objects like Object and String.
 
|  
 
|  
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-array]
| no-native-reassign
+
| Warning
|  
+
|style="text-align:center;" | 6.0
|  
+
|Discouraged 'new Array()'
 +
| ''Use the array literal notation [].''
 +
| Flags <code>new Array()</code>. ESLint calls this rule <code>no-array-constructor</code>
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]
| no-negated-in-lhs
+
| Warning
|  
+
|style="text-align:center;" | 6.0
|  
+
|Discouraged 'new Function()'
 +
| ''The Function constructor is eval.''
 +
| Flags <code>new Function()</code>.
 +
| style="text-align:center;" |
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]
| no-new-array
+
| Warning
| -
+
|style="text-align:center;" | 6.0
| Use the array literal notation [].
+
|Discouraged 'new Object()'
| Flags <code>new Array()</code>
+
| ''Use the object literal notation {}.''
 +
| Flags <code>new Object()</code>.
 +
| style="text-align:center;" |
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]
| no-new-func
+
| Warning
| -
+
|style="text-align:center;" | 6.0
| Do not use 'new' for side effects.
+
|Discouraged wrapper objects
| Flags uses of <code>new</code> operator in an expression that is not assigned to anything.
+
| ''Do not use {String, Number, Boolean, Math, JSON} as a constructor.''
 +
| Flags <code>new</code> applied to any of those.
 +
| style="text-align:center;" |[https://bugs.eclipse.org/bugs/show_bug.cgi?id=485877 ✔]
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486758 no-param-reassign]
| no-new-object
+
| Error
| -
+
|style="text-align:center;" |
| Use the object literal notation {}.
+
|Discouraged parameter reassignment
 +
| ''Assignment to function parameter '${0}'.''
 +
| Flags function parameters that are reassigned
 +
| style="text-align:center;" |Future
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461848 no-proto]
| no-new-wrappers
+
| Error
 +
|style="text-align:center;" | 9.0
 +
|Discouraged __proto__ property use
 +
|
 +
* ''Reserved name '__proto__' should not be assigned.''
 +
* ''Reserved name '__proto__' should not be used as a key.''
 +
| Flags use of the property <code>__proto__</code> as object keys or in assignments
 
|  
 
|  
| Do not use {String, Number, Boolean, Math, JSON} as a constructor.
+
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]
| no-new
+
| Warning
|  
+
|style="text-align:center;" | 5.0
|  
+
|Variable re-declarations
 +
| '''{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>.
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486123 Future]
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=463490 no-self-assign]
| no-obj-calls
+
| Error
|  
+
|style="text-align:center;" | 11.0
|  
+
|Disallow self assignment
 +
| ''Assigning to itself is pointless.''
 +
| Warns when a variable is being assigned to itself
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486124 ✔]
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486124 ✔]
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461850 no-self-compare]
| no-octal-escape
+
| Error
|  
+
|style="text-align:center;"| 11.0
|  
+
|Disallow self compare
 +
| ''Comparing to itself is potentially pointless.''
 +
| Comparing a variable against itself is usually an error, either an typo or refactoring error. It is confusing to the reader and may potentially introduce a runtime error.
 +
|style="text-align:center;" |
 +
|style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438319 no-shadow]
| no-octal
+
| Warning
|  
+
|style="text-align:center;" | 8.0
|  
+
|Variable shadowing
 +
| '''{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:center;" | ✔
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461321 no-shadow-global]
| no-plusplus
+
| Warning
| '''plusplus'''
+
|style="text-align:center;" | 9.0
| Unexpected use of '{++, --}'
+
|Global shadowing
 +
| '''{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:center;" | ✔
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=6e517847ef0742b090130748fb9a0329d33e16bf no-throw-literal]
| no-proto
+
| Warning
| -
+
|style="text-align:center;" | 9.0
| "Reserved name '__proto__'. (if used as an identifier)<br>Stupid key '{a}' (if used as a key)
+
|Literal used in 'throw'
| Treated as a fatal parse error in JSLint.
+
| ''Throw an Error instead.''
 +
| Flags code that throws a literal, eg. <code>throw "a problem occurred";</code>
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-undef]
| no-redeclare
+
| Error
| -
+
|style="text-align:center;" | 5.0
| "'{a}' is already defined."
+
|Undeclared global reference
| Usually results from having two <code>for</code> loops in the same function that share a loop variable declaration like <code>var i=...</code>.
+
| '''{variable}' is not defined.''
 +
|
 +
* Flags references to a global variable that is not listed in a <tt>/*global*/</tt> or <tt>/*globals*/</tt> block.
 +
* Predefined environments (eg. '''node''', '''browser''', '''amd''') can be set in a <tt>/*eslint-env*/</tt> block.
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461852 no-undef-init]
| no-return-assign
+
| Warning
| -
+
|style="text-align:center;" | 9.0
| (Not supported)
+
|Explicitly initializing variables to undefined
| Prevents assignment in a <code>return</code> statement.
+
| ''Avoid explicitly initializing variables to 'undefined'.''
 +
| Warns when an explicit assignment to undefined is done, for example <code>var foo = undefined;</code>
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486128 ✔]
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486128 ✔]
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486757 no-unused-expressions]
| no-script-url
+
| Warning
|  
+
|style="text-align:center;" |
 +
|Unused expressions
 +
| ''Expected an assignment or function call and instead saw an expression.''
 +
| Flags expressions that have no effect on the running code
 +
| style="text-align:center;" | Future
 
|  
 
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=427310 no-unused-params]
| no-self-compare
+
| Warning
|  
+
|style="text-align:center;" | 6.0
 +
|Unused parameters
 +
| ''Parameter '{param}' is not used.''
 +
| Flags parameters in function declarations / expressions if they are not being used
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" |
 +
|-
 +
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-unused-vars]
 +
| Warning
 +
|style="text-align:center;" | 5.0
 +
|Unused variables
 
|  
 
|  
 +
*'''{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:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-use-before-define]
| no-shadow
+
| Warning
|  
+
|style="text-align:center;" | 5.0
 +
|Member used before definition
 +
| '''{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=486755 no-void]
| no-spaced-func
+
| Warning
|  
+
|style="text-align:center;" |
 +
|Discouraged 'void' statement use
 +
| ''Expected 'undefined' and instead saw 'void'.''
 +
| Warns when the void keyword is used
 
|  
 
|  
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461854 no-with]
| no-sync
+
| Warning
| '''stupid'''
+
|style="text-align:center;" | 9.0
| Unexpected sync method: '{a}'.
+
|Discouraged 'with' statement use
| Flags Node.js's synchronous I/O methods.<br>The '''stupid''' option is supported only in newer versions of JSLint (not Orion's).
+
| ''Expected an identifier and instead saw 'with'.''
|-
+
| Treated as fatal parse error in JSLint.
 
+
| no-ternary
+
|
+
 
|  
 
|  
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=f61bdaf06ac2f40eaca4daed39520cd60c41f5f3 radix]
| no-undef-init
+
| Warning
| -
+
|style="text-align:center;" | 8.0
| It is not necessary to initialize 'x' to 'undefined'.
+
|Missing radix parameter to parseInt()
 +
| ''Missing radix parameter.''
 +
| Warns when parseInt() called without the 2nd parameter (radix).
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=487695 ✔]
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=487695 ✔]
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486754 yoda]
| no-undef
+
| Ignore
| '''undef'''
+
|style="text-align:center;" |
| '{variable}' is not defined.
+
|Yoda conditions
| Flags references to a global variable that is not listed in a /*global*/ or /*globals*/ block.<br>Predefined environments (eg. '''node''', '''browser''') can be set as /*jslint */ block.
+
| ''Expected literal to be on the right side of ${0}''
 +
| Warns when the literal value of a conditional expression does not come first
 +
| style="text-align:center;" | Future
 +
|
 
|-
 
|-
 +
|}
  
| no-underscore-dangle
+
=== Code Style ===
| '''nomen'''
+
These rules are not problems in any way but will warn based on certain accepted styles for coding.
| dangling '_'
+
|-
+
  
| no-unreachable
+
{| class="wikitable sortable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
|  
+
! width=13% | Rule
|  
+
! width=5% | Default Severity
 +
! width=3% | Available Since
 +
! width=24% | Setting Message
 +
! width=24%| Problem Message
 +
! width=24% | Details
 +
! width=3% | Quick Fix?
 +
! width=3% | Fix All?
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424128 missing-doc]
| no-unused-expressions
+
| Ignore
| -
+
|style="text-align:center;" | 5.0
| Expected an assignment or function call and instead saw an expression.
+
|Missing JSDoc
| Flags expressions that appear in a statement context and don't cause side effects.
+
| ''Missing documentation for function '{name}'.''
 +
| Flags missing documentation nodes on function declarations and function expressions when they appear as object properties
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486125 ✔]
 +
| style="text-align:center;" |
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424204 missing-doc-items]
| no-unused-vars
+
| Ignore
| '''unparam''' (newer JSLint versions only)
+
|style="text-align:center;" | -
| Function declares unused variable '{a}'.
+
|
 +
| ''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]
| no-use-before-define
+
| Ignore
| -
+
|style="text-align:center;" | 9.0
| '{a}' was used before it was defined.
+
|Non-externalized string literals (missing $NON-NLS$ tag)
 +
| ''Non-externalized string literal '{a}'.''
 +
| Flags String literals that are not properly NLS'd
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486126 ✔]
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=483010 unnecessary-nls]
| no-with
+
| Ignore
| -
+
|style="text-align:center;" | 11.0
| Expected an identifier and instead saw 'with'.
+
|Unnecessary $NON-NLS$ tags
| Treated as fatal parse error in JSLint.
+
| ''Unnecessary $NON-NLS$ tag.''
 +
| Flags $NON-NLS$ comments that are not needed to exclude a string literal
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]
| no-wrap-func
+
| Error
|  
+
|style="text-align:center;" | 6.0
|  
+
|Missing parentheses in constructor call
 +
| ''Missing parentheses invoking constructor.''
 +
| Flags <code>new Whatever</code>
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=486127 ✔]
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438095 no-jslint]
| one-var
+
| Warning
|  
+
|style="text-align:center;" | 7.0
|  
+
|Unsupported environment directive
 +
| ''The 'jslint' directive is unsupported, please use eslint-env.''
 +
| Flags use of the /* jslint */ directive
 +
| style="text-align:center;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=453322 Future]
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=425200 no-mixed-returns]
| quote-props
+
| Error
|  
+
|style="text-align:center;" | -
 +
|
 +
| ''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=427930 semi]
| quotes
+
| Warning
|  
+
|style="text-align:center;" | 5.0
| Strings must use doublequote.
+
|Missing semicolons
| Only if "jsonmode"
+
| ''Missing semicolon.''
 +
| Warns when a semicolon should be used but is not
 +
| style="text-align:center;" | ✔
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 +
|}
  
| radix
+
== Implementing a new rule ==
| -
+
''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.''
| Missing radix parameter.
+
| Affects parseInt()
+
|-
+
  
| regex-spaces
+
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.
| Spaces are hard to count. Use {n}.
+
# [[#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.
  
| semi
+
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>.
| Missing semicolon.
+
# 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 <tt>/javascript/ruleData.js</tt>.
 +
# Add your rule to the #updated() handler in <tt>/javascript/validator.js</tt>.
  
| strict
+
Reload the JS plugin, and your rule should now be configurable from the Settings page, and properly set up for translation too.
| '''strict'''
+
|
+
| Requires <code>"use strict"</code> pragma.
+
|-
+
  
| unnecessary-strict
+
== Tests ==
|
+
* Every rule needs extensive unit tests.
|
+
* Unit tests should use [http://mochajs.org Mocha].
|-
+
  
| use-isnan
+
=== 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.
| Use the isNaN function to compare with NaN.
+
** 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.
  
| wrap-iife
+
See [http://mochajs.org/#grep-query Mocha usage options] for more options.
| '''immed'''
+
| Wrap the entire immediate function invocation in parens.<br>Do not wrap function literals in parens unless they are to be immediately invoked.<br>Move the invocation into the parens that contain the function.
+
|
+
|-
+
  
| wrap-regex
+
== 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].
| Wrap the /regexp/ literal in parens to disambiguate the slash operator.
+
* Should we try to support <code>.eslintrc</code>? This would be an ideal project-scope setting, and is being tracked in [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461228 bug 461228].
|-
+
* <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>
  
|}
+
[[Category:Orion]]
 
+
== Rule priority ==
+
Here are the rules we want, in order of priority:
+
# no-undef
+

Revision as of 18:01, 11 February 2016

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 Setting Message Problem Message Details Quick Fix? Fix All?
no-comma-dangle Ignore 8.0 Trailing commas in object expressions Trailing commas in object expressions are discouraged. Flags trailing commas in object expressions.
no-cond-assign Error 8.0 Assignments in conditional expressions Expected a conditional expression and instead saw an assignment. Flags assignment in an if/while/do..while/for condition. Future
no-console Ignore 8.0 Discouraged console use in browser code Discouraged use of console in browser-based code. Flags the use of console in browser-based code
no-constant-condition Error 8.0 Constant as conditional expression Discouraged use of constant as a conditional expression. Flags the use of a constant as a conditional expression
no-control-regex Error 11.0 Disallow control characters in regular expressions Unexpected control character in regular expression Control characters are special, invisible characters in the ASCII range 0-31. These characters are rarely used in JavaScript strings so a regular expression containing these characters is most likely a mistake.
no-debugger Warning 6.0 Discouraged 'debugger' statement use debugger' statement use is discouraged. Warns when the debugger keyword is used
no-dupe-args Error Duplicate parameter names Duplicate param '${0}' Warns when there are duplicate function parameter names. Future
no-dupe-keys Error 6.0 Duplicate object keys Duplicate object key '{key}'. Flags object literals that contain the same key more than once.
no-duplicate-case Error 11.0 Duplicate case Duplicate case label. A switch statements with duplicate case labels is normally an indication of a programmer error.
no-empty-block Warning 7.0 Undocumented empty block Empty block should be removed or commented. Flags an empty block like if (something) { }.
no-empty-character-class Error 11.0 Disallow empty character classes Empty class. Empty character classes in regular expressions do not match anything and can result in code that may not work as intended.
no-extra-boolean-cast Error 11.0 Discourage redundant double negation no-extra-boolean-cast In contexts such as an if statement's test where the result of the expression will already be coerced to a Boolean, casting to a Boolean via double negation (!!) is unnecessary.
no-extra-parens Warning 11.0 Discourage redundant parentheses Gratuitous parentheses around expression. This rule restricts the use of parentheses to only where they are necessary. It may be restricted to report only function expressions.
no-extra-semi Warning 5.0 Unnecessary semicolons Unnecessary semicolon. Warns when a semicolon is found where it is not needed
no-fallthrough Error 6.0 Switch case fall-through 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-invalid-regexp Error 11.0 Invalid regular expressions Invalid flags supplied to RegExp constructor '{${0}}'. or the error message from calling the constructor with the regex This rule validates string arguments passed to the RegExp constructor.
no-irregular-whitespace Ignore 11.0 Mixed spaces and tabs Irregular whitespace not allowed. Invalid or irregular whitespace causes issues with ECMAScript 5 parsers and also makes code harder to debug in a similar nature to mixed tabs and spaces.
no-negated-in-lhs Error 11.0 Disallow negated left operand of in operator The 'in' expression's left operand is negated. Disallow negated left operand of in operator
no-obj-calls Error 11.0 Disallow global object as function calls '{${0}}' is not a function. ECMAScript provides several global objects that are intended to be used as-is. Some of these objects look as if they could be constructors due their capitalization (such as Math and JSON) but will throw an error if you try to execute them as functions.
no-regex-spaces Error 8.0 Multiple spaces in regular expressions 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 used as property keys 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 Sparse array declarations should be avoided. Flags sparse arrays with null elements like var arr = [1, ,2]
no-unreachable Error 6.0 Unreachable code Unreachable code. Flags statements that occur after a return, throw, etc.
use-isnan Error 6.0 NaN not compared with isNaN() 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 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 Setting Message Problem Message Details Quick Fix? Fix All?
accessor-pairs Warning 11.0 Getter and setter accessors not in pairs Getter is not present or Setter is not present It's a common mistake in JavaScript to create an object with just a setter for a property but never have a corresponding getter defined for it. Without a getter, you cannot read the property, so it ends up not being used.
block-scoped-var Error - '{variable}' used outside of binding context.

Occurs when a function-scoped variable (var) is treated as if it was block scoped.

curly Ignore 6.0 Statements not enclosed in braces Statements should be enclosed in braces. Warns when statements should be enclosed in braces, for example if(something) foo();
eqeqeq Warning 5.0 Discouraged '==' use
  • Expected '===' and saw '=='.
  • Expected '!==' and saw '!='.
Warns when == or != is used
no-caller Error 9.0 Discouraged 'arguments.caller' or 'arguments.callee' use arguments.{callee, caller} is deprecated. Flags references to arguments.callee and arguments.caller. Future
no-else-return Warning 11.0 Unnecessary else after return Unexpected 'else' after 'return'. If an if block contains a return statement, the else block becomes unnecessary. Its contents can be placed outside of the block.
no-empty-label Error 11.0 No empty labels Unexpected label "{${0}}" Labeled statements are only used in conjunction with labeled break and continue statements. ECMAScript has no goto statement.
no-eq-null Error 11.0 Disallow null comparisons Use ‘===’ to compare with ‘null’. or Use ‘!==’ to compare with ‘null’. Comparing to null without a type-checking operator (== or !=), can have unintended results as the comparison will evaluate to true when comparing to not just a null, but also an undefined value.
no-eval Ignore 6.0 Discouraged 'eval()' use 'eval' function calls are discouraged. Warns when the eval() function is used
no-extend-native Error Discouraged built-in object modification '${0}' prototype is read only, properties should not be added. Warns when directly modifying the prototype of builtin objects.
no-extra-bind Warning Unnecessary 'bind()' use The function binding is unnecessary. Warns about unnecessary use of bind()
no-implicit-coercion Warning Discouraged implicit coercion use use `${0}` instead. Example: use `Boolean(foo)` instead. Warns when shorter notations are used for the type conversion, then suggest a more self-explanatory notation. Future
no-implied-eval Ignore 6.0 Discouraged implied 'eval()' use 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-invalid-this Warning Discouraged 'this' use Unexpected `this` This rule aims to flag usage of 'this' keywords outside of classes or class-like objects
no-iterator Error 8.0 Discouraged __iterator__ property use Discouraged __iterator__ property use. Flags use of __iterator__ as an identifier name or property key.
no-lone-blocks Warning Discouraged lone block use Block is redundant. or Nested block is redundant. Flags use of unnecessary and potentially confusing blocks at the top level of a script or within other blocks. Future
no-native-reassign Error Discouraged built-in native object reassignment '${0}' is a read-only native object. Flags reassignment of built-in native objects like Object and String.
no-new-array Warning 6.0 Discouraged 'new Array()' Use the array literal notation []. Flags new Array(). ESLint calls this rule no-array-constructor
no-new-func Warning 6.0 Discouraged 'new Function()' The Function constructor is eval. Flags new Function().
no-new-object Warning 6.0 Discouraged 'new Object()' Use the object literal notation {}. Flags new Object().
no-new-wrappers Warning 6.0 Discouraged wrapper objects Do not use {String, Number, Boolean, Math, JSON} as a constructor. Flags new applied to any of those.
no-param-reassign Error Discouraged parameter reassignment Assignment to function parameter '${0}'. Flags function parameters that are reassigned Future
no-proto Error 9.0 Discouraged __proto__ property use
  • 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 Variable re-declarations '{a}' is already defined. Usually results from having two for loops in the same function that share a loop variable declaration like var i=.... Future
no-self-assign Error 11.0 Disallow self assignment Assigning to itself is pointless. Warns when a variable is being assigned to itself
no-self-compare Error 11.0 Disallow self compare Comparing to itself is potentially pointless. Comparing a variable against itself is usually an error, either an typo or refactoring error. It is confusing to the reader and may potentially introduce a runtime error.
no-shadow Warning 8.0 Variable shadowing '{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 Global shadowing '{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 Literal used in 'throw' Throw an Error instead. Flags code that throws a literal, eg. throw "a problem occurred";
no-undef Error 5.0 Undeclared global reference '{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-undef-init Warning 9.0 Explicitly initializing variables to undefined Avoid explicitly initializing variables to 'undefined'. Warns when an explicit assignment to undefined is done, for example var foo = undefined;
no-unused-expressions Warning Unused expressions Expected an assignment or function call and instead saw an expression. Flags expressions that have no effect on the running code Future
no-unused-params Warning 6.0 Unused parameters Parameter '{param}' is not used. Flags parameters in function declarations / expressions if they are not being used
no-unused-vars Warning 5.0 Unused variables
  • '{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 Member used before definition '{a}' was used before it was defined. Warns when a variable or function is used before it is defined
no-void Warning Discouraged 'void' statement use Expected 'undefined' and instead saw 'void'. Warns when the void keyword is used
no-with Warning 9.0 Discouraged 'with' statement use Expected an identifier and instead saw 'with'. Treated as fatal parse error in JSLint.
radix Warning 8.0 Missing radix parameter to parseInt() Missing radix parameter. Warns when parseInt() called without the 2nd parameter (radix).
yoda Ignore Yoda conditions Expected literal to be on the right side of ${0} Warns when the literal value of a conditional expression does not come first Future

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 Setting Message Problem Message Details Quick Fix? Fix All?
missing-doc Ignore 5.0 Missing JSDoc 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 literals (missing $NON-NLS$ tag) Non-externalized string literal '{a}'. Flags String literals that are not properly NLS'd
unnecessary-nls Ignore 11.0 Unnecessary $NON-NLS$ tags Unnecessary $NON-NLS$ tag. Flags $NON-NLS$ comments that are not needed to exclude a string literal
new-parens Error 6.0 Missing parentheses in constructor call Missing parentheses invoking constructor. Flags new Whatever
no-jslint Warning 7.0 Unsupported environment directive The 'jslint' directive is unsupported, please use eslint-env. Flags use of the /* jslint */ directive Future
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
semi Warning 5.0 Missing semicolons 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 /javascript/ruleData.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, and is being tracked in bug 461228.
  • 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