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)
(Best Practices)
(45 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Orion 5.0 moved to [https://github.com/nzakas/eslint/ ESLint] as the validator that ships with Orion. 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 ==  
The following table describes all of the rules currently available in Orion and ones that we plan to add in the future.
+
The following sections describe all of the rules currently available in Orion and ones that we plan to add in the future.
  
Rules that are currently available are <del>struck out</del>.
+
=== 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.
  
 
{| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
 
{| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
! style="background:#efefef;" width=5% | Rule
+
! width=12% | Rule
! style="background:#efefef;" width=5% | Default Severity
+
! width=6% | Default Severity
! style="background:#efefef;" width=5% | Available Since
+
! width=5% | Available Since
! style="background:#efefef;" width=40%| Problem Message
+
! width=35%| Problem Message
! style="background:#efefef;" width=40% | Details
+
! width=40% | Details
 +
! width=5% | Quick Fix?
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455253 no-comma-dangle]
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428433 block-scoped-var]
+
| Error
+
| -
+
| '''{variable}' is already defined.''
+
|
+
* Occurs when a function-scoped variable is treated as if it was block scoped.
+
* ESLint calls this error '{variable} used outside of binding context.'
+
|-
+
 
+
!| brace-style
+
 
| Ignore
 
| Ignore
| -
+
|style="text-align:center;"| 8.0
| &nbsp;
+
| ''Trailing commas in object expressions are discouraged.''
| &nbsp;
+
| 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
+
| Ignore
+
| -
+
| &nbsp;
+
| &nbsp;
+
|-
+
 
+
!| complexity
+
| Ignore
+
|  -
+
| &nbsp;
+
| &nbsp;
+
|-
+
 
+
!| consistent-this
+
| Ignore
+
|  -
+
| &nbsp;
+
| &nbsp;
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429722 curly]</del>
+
| Ignore
+
| 6.0
+
| ''Statements should be enclosed in braces.''
+
| &nbsp;
+
|-
+
 
+
!| dot-notation
+
| Warning
+
| -
+
| ''{a} is better written in dot notation.''
+
| &nbsp;
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 eqeqeq]</del>
+
| Warning
+
| 5.0
+
|
+
* ''Expected '===' and saw '=='.''
+
* ''Expected '!==' and saw '!='.''
+
| &nbsp;
+
|-
+
 
+
!| guard-for-in
+
| Ignore
+
| -
+
| ''The body of a <code>for in</code> should be wrapped in an <code>if</code> statement to filter unwanted properties from the prototype.''
+
| &nbsp;
+
|-
+
 
+
!| max-depth
+
| Ignore
+
| -
+
| &nbsp;
+
| Enforces max depth of nested blocks within a function.
+
|-
+
 
+
!| max-len
+
| Ignore
+
| -
+
| ''Line is too long.''
+
| Enforces a maximum line length.
+
|-
+
 
+
!| max-params
+
| Ignore
+
| -
+
| &nbsp;
+
| &nbsp;
+
|-
+
 
+
!| max-statements
+
| Ignore
+
| -
+
| &nbsp;
+
| &nbsp;
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=424128 missing-doc]</del>
+
| Ignore
+
| 5.0
+
| "Missing documentation for function '{name}.'"
+
| Flags missing documentation nodes on function declarations and function expressions when they appear as object properties
+
|-
+
 
+
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424204 missing-doc-items]
+
| Ignore
+
| -
+
|&nbsp;
+
| Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties
+
|-
+
 
+
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428429 missing-nls]
+
| Ignore
+
| -
+
| &nbsp;
+
| Flags String literals that are not properly NLS'd
+
|-
+
 
+
!| new-cap
+
| Warning
+
| -
+
| ''A constructor name should start with an uppercase letter.''
+
| &nbsp;
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]</del>
+
 
| Error
 
| Error
| 6.0
+
|style="text-align:center;"| 8.0
| ''Missing parentheses invoking constructor.''
+
| ''Expected a conditional expression and instead saw an assignment.''
| Flags <code>new Whatever</code>
+
|-
+
 
+
!| no-alert
+
| Ignore
+
| -
+
| '''{alert, confirm, prompt}' is not defined.''
+
| &nbsp;
+
|-
+
 
+
!| no-bitwise
+
| Warning
+
| -
+
| ''Unexpected use of '{operator}'.''
+
| JSLint disallows bitwise ops by default.
+
|-
+
 
+
!| no-caller
+
| Ignore
+
| -
+
| &nbsp;
+
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
+
|-
+
 
+
!| no-catch-shadow
+
| Warning
+
| -
+
| '''{a}' is already defined.''
+
|
+
* Flags a <code>catch</code> clause's variable that shadows a variable declared in an outer scope. (In IE8 this [http://weblog.bocoup.com/the-catch-with-try-catch/ causes the outer variable to be overwritten]).
+
|-
+
 
+
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=426723 no-comma-dangle]
+
| Warning
+
| -
+
| ''Unexpected comma.''
+
| Flags trailing commas in object literals and array declarations.
+
|-
+
 
+
!| no-cond-assign
+
| Ignore
+
| -
+
| &nbsp;
+
 
| Flags assignment in an <code>if/while/do..while/for</code> condition.
 
| Flags assignment in an <code>if/while/do..while/for</code> condition.
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455371 no-console]
!| no-console
+
| Error
| Ignore
+
|style="text-align:center;"| 8.0
| -
+
| ''Discouraged use of console in browser-based code.''
| &nbsp;
+
| Flags the use of console in browser-based code
| &nbsp;
+
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455680 no-constant-condition]
!| no-control-regex
+
| Error
| Ignore
+
|style="text-align:center;"| 8.0
| -
+
| ''Discouraged use of constant as a conditional expression.''
| &nbsp;
+
| Flags the use of a constant as a conditional expression
| Flags control characters (U+0000–U+001F and U+007F) within the source argument to the RegExp constructor.
+
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-debugger]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-debugger]</del>
+
 
| Warning
 
| Warning
| 6.0
+
|style="text-align:center;"| 6.0
 
| ''debugger' statement use is discouraged.''
 
| ''debugger' statement use is discouraged.''
| &nbsp;
+
| Warns when the <code>debugger</code> keyword is used
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]
!| no-delete-var
+
| Warning
+
| -
+
| ''Deleting a local variable is discouraged.''
+
| Flags an attempt to <code>delete</code> a local variable.
+
|-
+
 
+
!| no-div-regex
+
| Warning
+
| -
+
| ''A regular expression literal can be confused with '/='.''
+
| Flags a regex literal starting with <code>/=</code>
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]</del>
+
 
| Error
 
| Error
| 6.0
+
|style="text-align:center;"| 6.0
 
| ''Duplicate object key '{key}'.''
 
| ''Duplicate object key '{key}'.''
 
| Flags object literals that contain the same key more than once.
 
| Flags object literals that contain the same key more than once.
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=439366 no-empty-block]
!| no-else-return
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;"| 7.0
| &nbsp;
+
| ''Empty block should be removed or commented.''
| Flags an <code>else</code> appearing after an <code>if</code> that contains a <code>return</code>.
+
|-
+
 
+
!| no-empty-class
+
| Warning
+
| -
+
| ''Empty class.''
+
| Flags an empty character class <code>[]</code> within a regular expression.
+
|-
+
 
+
!| no-empty-label
+
| Warning
+
| -
+
| ''Label '{a}' is not allowed on this statement.''
+
| Flags a labeled statement that is not a <code>switch</code>, <code>for</code>, or <code>while</code>.
+
|-
+
 
+
!| no-empty
+
| Warning
+
| -
+
| &nbsp;
+
 
| Flags an empty block like <code>if (something) { }</code>.
 
| 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-eq-null
+
| Error
+
| -
+
| ''Use '===' to compare with 'null'.''
+
| &nbsp;
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]</del>
+
| Ignore
+
| 6.0
+
| '''eval' function calls are discouraged.''
+
| &nbsp;
+
|-
+
 
+
!| no-ex-assign
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;"| 5.0
| ''Do not assign to the exception parameter.''
+
| &nbsp;
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 no-extra-semi]</del>
+
| Warning
+
| 5.0
+
 
| ''Unnecessary semicolon.''
 
| ''Unnecessary semicolon.''
| &nbsp;
+
| 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]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429815 no-fallthrough]</del>
+
 
| Error
 
| Error
| -
+
|style="text-align:center;" | 6.0
 
| ''Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above''
 
| ''Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above''
 
| Flags a fallthrough case within a <code>switch</code> statement, unless it is explicitly commented.
 
| Flags a fallthrough case within a <code>switch</code> statement, unless it is explicitly commented.
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455391 no-regex-spaces]
!| no-floating-decimal
+
| Error
| Warning
+
|style="text-align:center;"| 8.0
| -
+
| ''Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead.''
| ''A {leading, trailing} decimal point can be confused with a dot: '{n}'.''
+
| Flags regular expressions that have two or more subsequent spaces.
| Flags numeric literals that have a leading or trailing decimal point.
+
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455354 no-reserved-keys]
!| no-func-assign
+
| Error
| Warning
+
|style="text-align:center;"| 8.0
| -
+
| ''Reserved words should not be used as property keys.''
| &nbsp;
+
| Checks to see if a JavaScript reserved word is being used as a property key
| Flags assignment to a variable that's already bound to a <code>FunctionExpression</code>.
+
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=426723 no-sparse-arrays]
!| no-global-strict
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;"| 8.0
| &nbsp;
+
| ''Sparse array declarations should be avoided.''
| Flags <code>"use strict"</code> applied to the entire Program.
+
| 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]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429707 no-implied-eval]</del>
+
| Ignore
+
| 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.
+
|-
+
 
+
!| no-iterator
+
 
| Error
 
| Error
| -
+
|style="text-align:center;"| 6.0
| ''Reserved name '__iterator__'.''
+
| ''Unreachable code.''
| Flags use of __iterator__ as an identifier name or property key.
+
| 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-label-var
+
 
| Error
 
| Error
| -
+
|style="text-align:center;"| 6.0
| '''{label}' is already defined.''
+
| ''Use the isNaN function to compare with NaN.''
| Flags labels that collide with an identifier.
+
| Warns when a comparison is done against NaN without using the <code>isNaN</code> function
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=447189 valid-typeof]
!| no-loop-func
+
 
| Error
 
| Error
| -
+
|style="text-align:center;"| 7.0
| ''Don't make functions within a loop.''
+
| ''Invalid typeof comparison.''
| &nbsp;
+
| Warns when a typeof comparison uses an invalid type.
 +
|
 
|-
 
|-
 +
|}
  
!| no-mixed-requires
+
=== Best Practices ===
| Ignore
+
These rules are not necessarily problem with your code, but are warnings that you might be doing something
| -
+
you probably should not be.
| &nbsp;
+
 
| Flags Node.js <code>require()</code>s that mix different types of requires (core, module, file, computed).
+
{| 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?
 
|-
 
|-
  
!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=425200 no-mixed-returns]
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428433 block-scoped-var]
 
| Error
 
| Error
| -
+
|style="text-align:center;" | -
| &nbsp;
+
| '''{variable}' is already defined.''
| Flags functions that return more than one kind of item, for example returning String and Object
+
|
 +
* 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.'
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429722 curly]
!| no-multi-str
+
| Ignore
| Warning
+
|style="text-align:center;" | 6.0
| -
+
| ''Statements should be enclosed in braces.''
| &nbsp;
+
| Warns when statements should be enclosed in braces, for example <code>if(something) foo();</code>
| Flags use of ES5 multiline string literals.
+
|  
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 eqeqeq]
!| no-native-reassign
+
 
| Warning
 
| 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
| Warning
+
|style="text-align:center;" | 9.0
| -
+
| ''arguments.{callee, caller} is deprecated.''
| &nbsp;
+
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
|
+
|
* Flags a unary <code>!</code> operator applied to the LHS of an in statement, which negates the LHS, not the <code>in</code>.
+
* Eg. <code>(!"key" in {key: 1})</code> (which always evaluates to false), will be flagged.
+
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-array]</del>
+
| Ignore
 +
|style="text-align:center;" | 6.0
 +
| '''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=461929 no-implied-eval]
 +
| 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]
 +
| Error
 +
|style="text-align:center;" | 8.0
 +
| ''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=429817 no-new-array]
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 6.0
 
| ''Use the array literal notation [].''
 
| ''Use the array literal notation [].''
 
| Flags <code>new Array()</code>.
 
| Flags <code>new Array()</code>.
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]</del>
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 6.0
 
| ''The Function constructor is eval.''
 
| ''The Function constructor is eval.''
 
| Flags <code>new Function()</code>.
 
| Flags <code>new Function()</code>.
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]</del>
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 6.0
 
| ''Use the object literal notation {}.''
 
| ''Use the object literal notation {}.''
 
| Flags <code>new Object()</code>.
 
| Flags <code>new Object()</code>.
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]</del>
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 6.0
 
| ''Do not use {String, Number, Boolean, Math, JSON} as a constructor.''
 
| ''Do not use {String, Number, Boolean, Math, JSON} as a constructor.''
 
| Flags <code>new</code> applied to any of those.
 
| Flags <code>new</code> applied to any of those.
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461848 no-proto]
!| no-new
+
 
| Error
 
| Error
| -
+
|style="text-align:center;" | 9.0
| ''Do not use 'new' for side effects.''
+
| Flags uses of <code>new</code> operator in an expression that is not assigned to anything.
+
|-
+
 
+
!| no-obj-calls
+
| Warning
+
| -
+
| ''Math is not a function..''
+
 
|
 
|
* Flags attempts to call object properties of the global object (<code>Math</code>, <code>JSON</code>) as a function, like <code>Math()</code>.
+
* ''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
!| no-octal-escape
+
| Warning
+
| -
+
| ''Bad escapement.''
+
| Flags octal escapes in strings, for example <code>var x = "Copyright \251";</code>
+
|-
+
 
+
!| no-octal
+
| Warning
+
| -
+
| ''Don't use extra leading zeros '{n}'.''
+
| Flags number literals that begin with leading 0s, which indicate a (probably accidental) octal literal.
+
|-
+
 
+
!| no-plusplus
+
| Warning
+
| -
+
 
|  
 
|  
* ''Unexpected use of '++'''
 
* ''Unexpected use of '--'''
 
| &nbsp;
 
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]
!| no-proto
+
| Error
+
| -
+
|
+
* ''Reserved name '__proto__' should not be assigned."
+
* 'Reserved name '__proto__' should not be used as a key."
+
| &nbsp;
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]</del>
+
 
| Warning
 
| Warning
| 5.0
+
|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
 
| Warning
 
| -
 
| &nbsp;
 
|
 
* Prevents assignment in a <code>return</code> statement.
 
* Unsupported by JSLint, although JSLint does require parens around a return-assignment, eg: <code>return (x = 2);</code>
 
|-
 
 
!| no-script-url
 
| Warning
 
| -
 
| &nbsp;
 
 
|  
 
|  
* Flags string literals beginning with <code>javascript:</code>. (Script URLs are a form of <code>eval</code>.)
 
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461850 no-self-compare]
!| no-self-compare
+
 
| Error
 
| Error
| -
+
|style="text-align:center;" | -
| &nbsp;
+
| ''Comparing a value to itself has no effect.''
 
| Flags comparisons where the left- and right-hand sides are the same.
 
| 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]
!!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438319 no-shadow]
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 8.0
| &nbsp;
+
| '''{a}' is already declared in the upper scope.''
| Flags variables that have the same name as a variable declared in an outer 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
+
| Ignore
+
| -
+
| ''Unnecessary space in function call.''
+
| Report on excess space in a function call, for example <code>myFunc ();</code> or <code>new MyObj ();</code>
+
|-
+
 
+
!| no-sync
+
| Ignore
+
| -
+
| ''Unexpected sync method: '{a}'.''
+
|
+
* Flags Node.js's synchronous I/O methods.
+
* The '''stupid''' option is supported only in newer versions of JSLint (not Orion's).
+
|-
+
 
+
!| no-ternary
+
| Ignore
+
| -
+
| &nbsp;
+
| Flags any use of the ternary operator <code>cond ? thenExpr : elseExpr</code>
+
|-
+
 
+
!| no-undef-init
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 9.0
| ''It is not necessary to initialize '{variable}' to 'undefined'.''
+
| '''{a}' shadows a global member.''
| &nbsp;
+
| 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]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=427310 no-unused-params]</del>
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 9.0
| "Parameter '{param}' is not used."
+
| ''Throw an Error instead.''
| Flags parameters in function declarations / expressions if they are not being used
+
| Flags code that throws a literal, eg. <code>throw "a problem occurred";</code>
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-undef]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-undef]</del>
+
 
| Error
 
| Error
| 5.0
+
|style="text-align:center;" | 5.0
 
| '''{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
+
| Ignore
+
| -
+
| ''Dangling '_'''
+
| &nbsp;
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=436986 no-unreachable]</del>
+
| Error
+
| -
+
| ''Unreachable code.''
+
| Flags statements that occur after a <code>return</code>, <code>throw</code>, etc.
+
|-
+
 
+
!| no-unused-expressions
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 6.0
| ''Expected an assignment or function call and instead saw an expression.''
+
| ''Parameter '{param}' is not used.''
| Flags expressions that appear in a statement context and don't cause side effects.
+
| 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]
!| <deL>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-unused-vars]</del>
+
 
| Warning
 
| Warning
| 5.0
+
|style="text-align:center;" | 5.0
| ''Function declares unused variable '{a}'.''
+
|  
| &nbsp;
+
*'''{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]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-use-before-define]</del>
+
 
| Warning
 
| Warning
| 5.0
+
|style="text-align:center;" | 5.0
 
| '''{a}' was used before it was defined.''
 
| '''{a}' was used before it was defined.''
| &nbsp;
+
| 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-with
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 9.0
 
| ''Expected an identifier and instead saw 'with'.''
 
| ''Expected an identifier and instead saw 'with'.''
 
| Treated as fatal parse error in JSLint.
 
| Treated as fatal parse error in JSLint.
 +
|
 
|-
 
|-
 
+
!style="text-align:left;"| [http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=f61bdaf06ac2f40eaca4daed39520cd60c41f5f3 radix]
!| no-wrap-func
+
| Ignore
+
| -
+
| ''Do not wrap function literals in parens unless they are to be immediately invoked.''
+
| Flags a parenthesized function literal that is not immediately invoked, eg. <code>(function fun(){})</code>
+
|-
+
 
+
!| object-prototype-external
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 8.0
| &nbsp;
+
| ''Missing radix parameter.''
| Flags calls to methods of <code>Object.prototype</code> that rely on the prototype chain. For example this code should be flagged:
+
| Warns when parseInt() called without the 2nd parameter (radix).
<source lang="javascript" line="line">
+
|
foo.hasOwnProperty("bar")
+
</source>
+
 
+
Example (1) is [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FObject%2FhasOwnProperty#hasOwnProperty_as_a_property unsafe], as <code>foo</code> may have a property named <code>hasOwnProperty</code>, or have been constructed via <code>Object.create(null)</code>.
+
 
+
As for this:
+
 
+
<source lang="javascript" line="line" start="2">
+
Object.hasOwnProperty.call(foo, "bar")
+
</source>
+
 
+
Example (2) technically relies on the prototype chain as well: the hasOwnProperty method is defined on Object.prototype, not Object. Object inherits the methods of Object.prototype [http://stackoverflow.com/questions/14817826/difference-between-an-object-and-its-prototype/14817913#14817913 through its prototype chain]. However (2) is unlikely to fail, as sane JavaScript programs will not modify the global objects' prototypes. If we choose to flag (2), it should only be for style.
+
 
|-
 
|-
 +
|}
  
!| one-var
+
=== Code Style ===
| Warning
+
These rules are not problems in any way but will warn based on certain accepted styles for coding.
| -
+
| ''Too many var statements.''
+
| Allows only 1 <code>var</code> statement per function.
+
|-
+
  
!| quote-props
+
{| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;"
| Warning
+
! width=12% | Rule
| -
+
! width=6% | Default Severity
| &nbsp;
+
! width=5% | Available Since
| Requires object literal keys to be quoted with " or '.
+
! 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]
!| quotes
+
 
| Ignore
 
| Ignore
| -
+
|style="text-align:center;" | 5.0
| &nbsp;
+
| ''Missing documentation for function '{name}'.''
| Flags any use of single or double quote marks, depending on setting.
+
| 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]
!| radix
+
| Ignore
| Warning
+
|style="text-align:center;" | -
| -
+
| ''Missing '{a}' tag for '{b}'.''  
| ''Missing radix parameter.''
+
| Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties
| Affects parseInt().
+
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428429 missing-nls]
!| regex-spaces
+
| Ignore
| Warning
+
|style="text-align:center;" | 9.0
| -
+
| ''Non-externalized string literal '{a}'.''
| ''Spaces are hard to count. Use {n}.''
+
| Flags String literals that are not properly NLS'd
| &nbsp;
+
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=427930 semi]</del>
+
| Error
| Warning
+
|style="text-align:center;" | 6.0
| 5.0
+
| ''Missing parentheses invoking constructor.''
| ''Missing semicolon.''
+
| Flags <code>new Whatever</code>
| &nbsp;
+
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438095 no-jslint]
!| strict
+
| warning
| Ignore
+
|style="text-align:center;" | 7.0
| -
+
| ''The 'jslint' directive is unsupported, please use eslint-env.''
| &nbsp;
+
| Flags use of the /* jslint */ directive
| Flags any code that lacks the <code>"use strict"</code> pragma.
+
|
 
|-
 
|-
 
+
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=425200 no-mixed-returns]
!| unnecessary-strict
+
| Warning
+
| -
+
| &nbsp;
+
| Flags <code>"use strict"</code> on a function when the entire Program is already in strict mode.
+
|-
+
 
+
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429711 use-isnan]</del>
+
 
| Error
 
| Error
| 6.0
+
|style="text-align:center;" | -
| ''Use the isNaN function to compare with NaN.''
+
| ''Mixed return types should be avoided.''
| &nbsp;
+
| 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]
!| wrap-iife
+
| Warning
| Ignore
+
|style="text-align:center;" | -
| -
+
| ''It is not necessary to initialize '{variable}' to 'undefined'.''
|
+
| Warns when an explicit assignment to undefined is done, for example <code>var foo = undefined;</code>
* ''Wrap the entire immediate function invocation in parens.''
+
| style="text-align:center;" | ✔
* ''Move the invocation into the parens that contain the function.''
+
| Flags missing parens on immediately-invoked functions, eg. <code>function(){ console.log('hi'); }();</code>
+
 
|-
 
|-
 
+
!style="text-align:left;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=427930 semi]
!| wrap-regex
+
 
| Warning
 
| Warning
| -
+
|style="text-align:center;" | 5.0
| ''Wrap the /regexp/ literal in parens to disambiguate the slash operator.''
+
| ''Missing semicolon.''
| &nbsp;
+
| Warns when a semicolon should be used but is not
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
 
 
|}
 
|}
  
== Tests ==
+
== Implementing a new rule ==
* Every rule needs extensive unit tests
+
''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.''
* Unit tests should use Mocha
+
  
Currently the tests are run from Node.js. They do not run in the browser (yet).
+
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.
  
=== Test requirements ===
+
To get your rule running in the Orion product's validator, there are additional steps:
First install [http://nodejs.org/ Node.js]. Then open a console and install Mocha globally:
+
# Create strings for the validation message(s) generated by your rule in <tt>/javascript/nls/root/problems.js</tt>.
 +
# 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>.
  
$ npm install mocha -g
+
Reload the JS plugin, and your rule should now be configurable from the Settings page, and properly set up for translation too.
  
Then from your Orion client repository, run these commands to install eslint's dependencies:
+
== Tests ==
 
+
* Every rule needs extensive unit tests.
$ cd bundles/org.eclipse.orion.client.javascript/web/eslint/
+
* Unit tests should use [http://mochajs.org Mocha].
$ npm install
+
  
 
=== Running the tests ===
 
=== Running the tests ===
From the <code>bundles/org.eclipse.orion.client.javascript/web/eslint/</code> directory, simply run <code>npm test</code>:
+
* 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].
$ npm test
+
* 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].
> eslint@0.2.0-dev test c:\Users\mamacdon\code\orion\client\bundles\org.eclipse.orion.client.javascript\web\eslint
+
* 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.
> bash scripts/test.sh
+
** 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.  
+
  ......................................................................
+
  ...............
+
+
  85 passing (106ms)
+
 
+
To run only a subset of the tests, launch mocha from the command line, passing the test file:
+
 
+
$ mocha tests/lib/rules/semi.js
+
+
  ............
+
+
  12 passing (17ms)
+
 
+
You can also pass an entire directory:
+
 
+
$ mocha tests/lib/rules
+
+
  ......................................................................
+
  ..........
+
+
  80 passing (104ms)
+
 
+
To run only some tests from a file, use the --grep option:
+
 
+
$ mocha tests/lib/rules/semi.js --grep VariableDeclaration
+
+
  .
+
+
  1 passing (5ms)
+
  
See [http://visionmedia.github.io/mocha/#usage Mocha usage options] for more.
+
See [http://mochajs.org/#grep-query Mocha usage options] for more options.
  
 
== User interface ==
 
== 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].
 
* <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.
 
* Should we try to support <code>.eslintrc</code>? This would be an ideal project-scope setting.
* 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>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>
** This would give compatibility with Orion codebase which uses these flags.
+
** ESLint now has its own syntax for this: <code>/*eslint ..*/</code>, which we are using instead.
** OTOH, eslint now has its own syntax for this: <code>/*eslint ..*/</code>, which we should perhaps use instead.
+
  
 
== i18n ==
 
== i18n ==
We need to support i18n. Pre-req is {{bug|422278}} (orion.edit.validator support for i18n).
+
<del>We need to support i18n. Pre-req is {{bug|422278}} (orion.edit.validator support for i18n).</del>
  
 
[[Category:Orion]]
 
[[Category:Orion]]

Revision as of 14:21, 8 May 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 9.0
  • 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 9.0 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