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: document quick fix status)
Line 14: Line 14:
 
! width=35%| Problem Message
 
! width=35%| Problem Message
 
! 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455253 no-comma-dangle]
Line 20: Line 21:
 
| ''Trailing commas in object expressions are discouraged.''
 
| ''Trailing commas in object expressions are discouraged.''
 
| Flags trailing commas in object expressions.
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455250 no-cond-assign]
Line 26: Line 28:
 
| ''Expected a conditional expression and instead saw an assignment.''
 
| ''Expected a conditional expression and instead saw an assignment.''
 
| Flags assignment in an <code>if/while/do..while/for</code> condition.
 
| Flags assignment in an <code>if/while/do..while/for</code> condition.
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455371 no-console]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455371 no-console]
Line 32: Line 35:
 
| ''Discouraged use of console in browser-based code.''
 
| ''Discouraged use of console in browser-based code.''
 
| Flags the 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455680 no-constant-condition]
Line 38: Line 42:
 
| ''Discouraged use of constant as a conditional expression.''
 
| ''Discouraged use of constant as a conditional expression.''
 
| Flags the use of a 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=429690 no-debugger]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-debugger]
Line 44: Line 49:
 
| ''debugger' statement use is discouraged.''
 
| ''debugger' statement use is discouraged.''
 
| Warns when the <code>debugger</code> keyword is used
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]
Line 50: Line 56:
 
| ''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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=439366 no-empty-block]
Line 56: Line 63:
 
| ''Empty block should be removed or commented.''
 
| ''Empty block should be removed or commented.''
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 no-extra-semi]
Line 61: Line 69:
 
|style="text-align:center;"| 5.0
 
|style="text-align:center;"| 5.0
 
| ''Unnecessary semicolon.''
 
| ''Unnecessary semicolon.''
| Warns when a semi colon is found where it is not needed
+
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429815 no-fallthrough]
Line 68: Line 77:
 
| ''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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455391 no-regex-spaces]
Line 74: Line 84:
 
| ''Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead.''
 
| ''Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead.''
 
| Flags regular expressions that have two or more subsequent spaces.
 
| Flags regular expressions that have two or more subsequent spaces.
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455354 no-reserved-keys]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455354 no-reserved-keys]
Line 80: Line 91:
 
| ''Reserved words should not be 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
 
| Checks to see if a JavaScript reserved word is being used as a property key
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=426723 no-sparse-arrays]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=426723 no-sparse-arrays]
Line 86: Line 98:
 
| ''Sparse array declarations should be avoided.''
 
| ''Sparse array declarations should be avoided.''
 
| Flags sparse arrays with null elements like <code>var arr = [1, ,2]</code>
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=436986 no-unreachable]
Line 92: Line 105:
 
| ''Unreachable code.''
 
| ''Unreachable code.''
 
| Flags statements that occur after a <code>return</code>, <code>throw</code>, etc.
 
| Flags statements that occur after a <code>return</code>, <code>throw</code>, etc.
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429711 use-isnan]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429711 use-isnan]
Line 98: Line 112:
 
| ''Use the isNaN function to compare with NaN.''
 
| ''Use the isNaN function to compare with NaN.''
 
| Warns when a comparison is done against NaN without using the <code>isNaN</code> function
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=447189 valid-typeof]
Line 104: Line 119:
 
| ''Invalid typeof comparison.''
 
| ''Invalid typeof comparison.''
 
| Warns when a typeof comparison uses an invalid type.
 
| Warns when a typeof comparison uses an invalid type.
 +
|
 
|-
 
|-
 
|}
 
|}
Line 117: Line 133:
 
! width=35%| Problem Message
 
! width=35%| Problem Message
 
! width=40% | Details
 
! width=40% | Details
 +
! width=5% | Quick Fix?
 
|-
 
|-
  
Line 124: Line 141:
 
| '''{variable}' is already defined.''
 
| '''{variable}' is already defined.''
 
|
 
|
* Occurs when a function-scoped variable is treated as if it was block scoped.
+
* 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.'
 
* 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429722 curly]
Line 132: Line 150:
 
| ''Statements should be enclosed in braces.''
 
| ''Statements should be enclosed in braces.''
 
| Warns when statements should be enclosed in braces, for example <code>if(something) foo();</code>
 
| Warns when statements should be enclosed in braces, for example <code>if(something) foo();</code>
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 eqeqeq]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 eqeqeq]
Line 140: Line 159:
 
* ''Expected '!==' and saw '!='.''
 
* ''Expected '!==' and saw '!='.''
 
| Warns when <code>==</code> or <code>!=</code> is used
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=460976 no-caller]
Line 146: Line 166:
 
| ''arguments.{callee, caller} is deprecated.''
 
| ''arguments.{callee, caller} is deprecated.''
 
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
 
| Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>.
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]
Line 158: Line 179:
 
| ''Implicit 'eval' function calls are discouraged.''
 
| ''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.
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=455643 no-iterator]
Line 164: Line 186:
 
| ''Discouraged __iterator__ property use.''
 
| ''Discouraged __iterator__ property use.''
 
| Flags use of <code>__iterator__</code> as an identifier name or property key.
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-array]
Line 170: Line 193:
 
| ''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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]
Line 176: Line 200:
 
| ''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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]
Line 182: Line 207:
 
| ''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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]
Line 188: Line 214:
 
| ''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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461848 no-proto]
Line 196: Line 223:
 
* ''Reserved name '__proto__' should not be used as a key.''
 
* ''Reserved name '__proto__' should not be used as a key.''
 
| Flags use of the property <code>__proto__</code> as object keys or in assignments
 
| Flags use of the property <code>__proto__</code> as object keys or in assignments
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]
Line 202: Line 230:
 
| '''{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>.
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461850 no-self-compare]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461850 no-self-compare]
Line 208: Line 237:
 
| ''Comparing a value to itself has no effect.''
 
| ''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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438319 no-shadow]
Line 214: Line 244:
 
| '''{a}' is already declared in the upper scope.''
 
| '''{a}' is already declared in the upper scope.''
 
| Flags variables that have the same name as a variable declared in an upper scope.
 
| Flags variables that have the same name as a variable declared in an upper scope.
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461321 no-shadow-global]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461321 no-shadow-global]
Line 220: Line 251:
 
| '''{a}' shadows a global member.''
 
| '''{a}' shadows a global member.''
 
| Flags variables that have the same name as a variable declared in the global scope or specified environments.
 
| 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]
 
!style="text-align:left;"| [http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=6e517847ef0742b090130748fb9a0329d33e16bf no-throw-literal]
Line 226: Line 258:
 
| ''Throw an Error instead.''
 
| ''Throw an Error instead.''
 
| Flags code that throws a literal, eg. <code>throw "a problem occurred";</code>
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-undef]
Line 234: Line 267:
 
* 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''', '''amd''') can be set in a /*eslint-env */ 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=427310 no-unused-params]
Line 240: Line 274:
 
| ''Parameter '{param}' is not used.''
 
| ''Parameter '{param}' is not used.''
 
| Flags parameters in function declarations / expressions if they are not being used
 
| Flags parameters in function declarations / expressions if they are not being used
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-unused-vars]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-unused-vars]
Line 248: Line 283:
 
*'''{a}' is read-only.''
 
*'''{a}' is read-only.''
 
| Warns when a variable is created and not used (read) or a variable that is read-only is assigned to.
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-use-before-define]
Line 254: Line 290:
 
| '''{a}' was used before it was defined.''
 
| '''{a}' was used before it was defined.''
 
| Warns when a variable or function is used before it is defined
 
| Warns when a variable or function is used before it is defined
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461854 no-with]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461854 no-with]
Line 260: Line 297:
 
| ''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]
 
!style="text-align:left;"| [http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=f61bdaf06ac2f40eaca4daed39520cd60c41f5f3 radix]
Line 266: Line 304:
 
| ''Missing radix parameter.''
 
| ''Missing radix parameter.''
 
| Warns when parseInt() called without the 2nd parameter (radix).
 
| Warns when parseInt() called without the 2nd parameter (radix).
 +
|
 
|-
 
|-
 
|}
 
|}
Line 278: Line 317:
 
! width=35%| Problem Message
 
! width=35%| Problem Message
 
! width=40% | Details
 
! width=40% | Details
 +
! width=5% | Quick Fix?
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424128 missing-doc]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424128 missing-doc]
Line 284: Line 324:
 
| ''Missing documentation for function '{name}'.''
 
| ''Missing documentation for function '{name}'.''
 
| Flags missing documentation nodes on function declarations and function expressions when they appear as object properties
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=424204 missing-doc-items]
Line 290: Line 331:
 
| ''Missing '{a}' tag for '{b}'.''  
 
| ''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
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428429 missing-nls]
Line 296: Line 338:
 
| ''Non externalized string literal '{a}'.''
 
| ''Non externalized string literal '{a}'.''
 
| Flags String literals that are not properly NLS'd
 
| Flags String literals that are not properly NLS'd
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]
Line 302: Line 345:
 
| ''Missing parentheses invoking constructor.''
 
| ''Missing parentheses invoking constructor.''
 
| Flags <code>new Whatever</code>  
 
| Flags <code>new Whatever</code>  
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438095 no-jslint]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438095 no-jslint]
Line 308: Line 352:
 
| ''The 'jslint' directive is unsupported, please use eslint-env.''
 
| ''The 'jslint' directive is unsupported, please use eslint-env.''
 
| Flags use of the /* jslint */ directive
 
| Flags use of the /* jslint */ directive
 +
|
 
|-
 
|-
 
!style="text-align:left;"| [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=425200 no-mixed-returns]
Line 314: Line 359:
 
| ''Mixed return types should be avoided.''
 
| ''Mixed return types should be avoided.''
 
| Flags functions that return more than one kind of item, for example returning String and Object
 
| 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]
 
!style="text-align:left;"| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461852 no-undef-init]
Line 320: Line 366:
 
| ''It is not necessary to initialize '{variable}' to 'undefined'.''
 
| ''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>
 
| Warns when an explicit assignment to undefined is done, for example <code>var foo = undefined;</code>
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
!style="text-align:left;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=427930 semi]
 
!style="text-align:left;" | [https://bugs.eclipse.org/bugs/show_bug.cgi?id=427930 semi]
Line 326: Line 373:
 
| ''Missing semicolon.''
 
| ''Missing semicolon.''
 
| Warns when a semicolon should be used but is not
 
| Warns when a semicolon should be used but is not
 +
| style="text-align:center;" | ✔
 
|-
 
|-
 
|}
 
|}

Revision as of 14:25, 1 April 2015

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

Rules

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

Potential Programming Problems

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

Rule Default Severity Available Since Problem Message Details Quick Fix?
no-comma-dangle Ignore 8.0 Trailing commas in object expressions are discouraged. Flags trailing commas in object expressions.
no-cond-assign Error 8.0 Expected a conditional expression and instead saw an assignment. Flags assignment in an if/while/do..while/for condition.
no-console Error 8.0 Discouraged use of console in browser-based code. Flags the use of console in browser-based code
no-constant-condition Error 8.0 Discouraged use of constant as a conditional expression. Flags the use of a constant as a conditional expression
no-debugger Warning 6.0 debugger' statement use is discouraged. Warns when the debugger keyword is used
no-dupe-keys Error 6.0 Duplicate object key '{key}'. Flags object literals that contain the same key more than once.
no-empty-block Warning 7.0 Empty block should be removed or commented. Flags an empty block like if (something) { }.
no-extra-semi Warning 5.0 Unnecessary semicolon. Warns when a semicolon is found where it is not needed
no-fallthrough Error 6.0 Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above Flags a fallthrough case within a switch statement, unless it is explicitly commented.
no-regex-spaces Error 8.0 Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead. Flags regular expressions that have two or more subsequent spaces.
no-reserved-keys Error 8.0 Reserved words should not be used as property keys. Checks to see if a JavaScript reserved word is being used as a property key
no-sparse-arrays Warning 8.0 Sparse array declarations should be avoided. Flags sparse arrays with null elements like var arr = [1, ,2]
no-unreachable Error 6.0 Unreachable code. Flags statements that occur after a return, throw, etc.
use-isnan Error 6.0 Use the isNaN function to compare with NaN. Warns when a comparison is done against NaN without using the isNaN function
valid-typeof Error 7.0 Invalid typeof comparison. Warns when a typeof comparison uses an invalid type.

Best Practices

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

Rule Default Severity Available Since Problem Message Details Quick Fix?
block-scoped-var Error - '{variable}' is already defined.
  • Occurs when a function-scoped variable (var) is treated as if it was block scoped.
  • ESLint calls this error '{variable} used outside of binding context.'
curly Ignore 6.0 Statements should be enclosed in braces. Warns when statements should be enclosed in braces, for example if(something) foo();
eqeqeq Warning 5.0
  • Expected '===' and saw '=='.
  • Expected '!==' and saw '!='.
Warns when == or != is used
no-caller Error 9.0 arguments.{callee, caller} is deprecated. Flags references to arguments.callee and arguments.caller.
no-eval Ignore 6.0 'eval' function calls are discouraged. Warns when the eval() function is used
no-implied-eval Ignore 6.0 Implicit 'eval' function calls are discouraged. Flags calls to the string-argument form of setTimeout and setInterval, which implicitly perform eval. This rule logic was merged to be part of the no-eval rule.
no-iterator Error 8.0 Discouraged __iterator__ property use. Flags use of __iterator__ as an identifier name or property key.
no-new-array Warning 6.0 Use the array literal notation []. Flags new Array().
no-new-func Warning 6.0 The Function constructor is eval. Flags new Function().
no-new-object Warning 6.0 Use the object literal notation {}. Flags new Object().
no-new-wrappers Warning 6.0 Do not use {String, Number, Boolean, Math, JSON} as a constructor. Flags new applied to any of those.
no-proto Error -
  • Reserved name '__proto__' should not be assigned.
  • Reserved name '__proto__' should not be used as a key.
Flags use of the property __proto__ as object keys or in assignments
no-redeclare Warning 5.0 '{a}' is already defined. Usually results from having two for loops in the same function that share a loop variable declaration like var i=....
no-self-compare Error - Comparing a value to itself has no effect. Flags comparisons where the left- and right-hand sides are the same.
no-shadow Warning 8.0 '{a}' is already declared in the upper scope. Flags variables that have the same name as a variable declared in an upper scope.
no-shadow-global Warning 9.0 '{a}' shadows a global member. Flags variables that have the same name as a variable declared in the global scope or specified environments.
no-throw-literal Warning 9.0 Throw an Error instead. Flags code that throws a literal, eg. throw "a problem occurred";
no-undef Error 5.0 '{variable}' is not defined.
  • Flags references to a global variable that is not listed in a /*global*/ or /*globals*/ block.
  • Predefined environments (eg. node, browser, amd) can be set in a /*eslint-env */ block.
no-unused-params Warning 6.0 Parameter '{param}' is not used. Flags parameters in function declarations / expressions if they are not being used
no-unused-vars Warning 5.0
  • '{a}' is not read.
  • '{a}' is read-only.
Warns when a variable is created and not used (read) or a variable that is read-only is assigned to.
no-use-before-define Warning 5.0 '{a}' was used before it was defined. Warns when a variable or function is used before it is defined
no-with Warning - Expected an identifier and instead saw 'with'. Treated as fatal parse error in JSLint.
radix Warning 8.0 Missing radix parameter. Warns when parseInt() called without the 2nd parameter (radix).

Code Style

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

Rule Default Severity Available Since Problem Message Details Quick Fix?
missing-doc Ignore 5.0 Missing documentation for function '{name}'. Flags missing documentation nodes on function declarations and function expressions when they appear as object properties
missing-doc-items Ignore - Missing '{a}' tag for '{b}'. Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties
missing-nls Ignore - 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).

Copyright © Eclipse Foundation, Inc. All Rights Reserved.