Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Orion/ESLint"
(→Rules) |
(→Rules) |
||
Line 5: | Line 5: | ||
Rules that are currently available are <del>struck out</del>. | 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%;" | ||
Line 13: | Line 17: | ||
! style="background:#efefef;" width=40% | Details | ! style="background:#efefef;" width=40% | Details | ||
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455253 no-comma-dangle]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455253 no-comma-dangle]</del> | ||
| Ignore | | Ignore | ||
Line 179: | Line 23: | ||
| Flags trailing commas in object expressions. | | Flags trailing commas in object expressions. | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455250 no-cond-assign]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455250 no-cond-assign]</del> | ||
| Error | | Error | ||
Line 186: | Line 29: | ||
| Flags assignment in an <code>if/while/do..while/for</code> condition. | | Flags assignment in an <code>if/while/do..while/for</code> condition. | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455371 no-console]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455371 no-console]</del> | ||
| Error | | Error | ||
Line 193: | Line 35: | ||
| Flags the use of console in browser-based code | | Flags the use of console in browser-based code | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455680 no-constant-condition]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455680 no-constant-condition]</del> | ||
| Error | | Error | ||
Line 200: | Line 41: | ||
| Flags the use of a constant as a conditional expression | | Flags the use of a constant as a conditional expression | ||
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-debugger]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429690 no-debugger]</del> | ||
| Warning | | Warning | ||
Line 214: | Line 47: | ||
| | | | ||
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]</del> | ||
| Error | | Error | ||
Line 235: | Line 53: | ||
| Flags object literals that contain the same key more than once. | | Flags object literals that contain the same key more than once. | ||
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=439366 no-empty-block]</del> | |
− | !| no- | + | |
| Warning | | Warning | ||
− | | | + | | 7.0 |
| | | | ||
− | | Flags an | + | | Flags an empty block like <code>if (something) { }</code>. |
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 no-extra-semi]</del> | |
− | !| no- | + | |
| Warning | | Warning | ||
− | | | + | | 5.0 |
− | | '' | + | | ''Unnecessary semicolon.'' |
− | | | + | | |
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455391 no-regex-spaces]</del> | |
− | !| no- | + | | Error |
+ | | 8.0 | ||
+ | | Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead. | ||
+ | | Flags regular expressions that have two or more subsequent spaces. | ||
+ | |- | ||
+ | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455354 no-reserved-keys]</del> | ||
+ | | Error | ||
+ | | 8.0 | ||
+ | | ''Reserved words should not be used as property keys.'' | ||
+ | | Checks to see if a JavaScript reserved word is being used as a property key | ||
+ | |- | ||
+ | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=426723 no-sparse-arrays]</del> | ||
| Warning | | Warning | ||
− | | | + | | 8.0 |
− | | '' | + | | ''Sparse array declarations should de avoided.'' |
− | | Flags | + | | Flags sparse arrays with null elements |
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=436986 no-unreachable]</del> | |
− | !| <del>no- | + | | Error |
− | | | + | |
| - | | - | ||
+ | | ''Unreachable code.'' | ||
+ | | Flags statements that occur after a <code>return</code>, <code>throw</code>, etc. | ||
+ | |- | ||
+ | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429711 use-isnan]</del> | ||
+ | | Error | ||
+ | | 6.0 | ||
+ | | ''Use the isNaN function to compare with NaN.'' | ||
| | | | ||
− | |||
|- | |- | ||
+ | |} | ||
− | !| | + | === 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. | ||
+ | |||
+ | {| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;" | ||
+ | ! style="background:#efefef;" width=5% | Rule | ||
+ | ! style="background:#efefef;" width=5% | Default Severity | ||
+ | ! style="background:#efefef;" width=5% | Available Since | ||
+ | ! style="background:#efefef;" width=40%| Problem Message | ||
+ | ! style="background:#efefef;" width=40% | Details | ||
+ | |- | ||
+ | |||
+ | !| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428433 block-scoped-var] | ||
| Error | | 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.' | ||
|- | |- | ||
− | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id= | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429722 curly]</del> |
| Ignore | | Ignore | ||
| 6.0 | | 6.0 | ||
− | | '' | + | | ''Statements should be enclosed in braces.'' |
| | | | ||
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 eqeqeq]</del> | |
− | !| | + | |
| Warning | | Warning | ||
− | | | + | | 5.0 |
− | | '' | + | | |
+ | * ''Expected '===' and saw '=='.'' | ||
+ | * ''Expected '!==' and saw '!='.'' | ||
| | | | ||
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=424128 missing-doc]</del> | |
− | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id= | + | | Ignore |
− | | | + | |
| 5.0 | | 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 |
− | | | + | |
| - | | - | ||
+ | | | ||
+ | | Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties | ||
+ | |- | ||
+ | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=460976 no-caller]</del> | ||
+ | | Error | ||
+ | | 9.0 | ||
+ | | ''arguments.{callee, caller} is deprecated.'' | ||
+ | | Flags references to <code>arguments.callee</code> and <code>arguments.caller</code>. | ||
+ | |- | ||
+ | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]</del> | ||
+ | | Ignore | ||
+ | | 6.0 | ||
+ | | '''eval' function calls are discouraged.'' | ||
| | | | ||
− | |||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429815 no-fallthrough]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429815 no-fallthrough]</del> | ||
| Error | | Error | ||
Line 305: | Line 162: | ||
| 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. | ||
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429707 no-implied-eval]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429707 no-implied-eval]</del> | ||
| Ignore | | Ignore | ||
Line 333: | Line 168: | ||
| 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. | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455643 no-iterator]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=455643 no-iterator]</del> | ||
| Error | | Error | ||
Line 340: | Line 174: | ||
| Flags use of __iterator__ as an identifier name or property key. | | Flags use of __iterator__ as an identifier name or property key. | ||
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-array]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-array]</del> | ||
| Warning | | Warning | ||
− | | | + | | 6.0 |
| ''Use the array literal notation [].'' | | ''Use the array literal notation [].'' | ||
| Flags <code>new Array()</code>. | | Flags <code>new Array()</code>. | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]</del> | ||
| Warning | | Warning | ||
− | | | + | | 6.0 |
| ''The Function constructor is eval.'' | | ''The Function constructor is eval.'' | ||
| Flags <code>new Function()</code>. | | Flags <code>new Function()</code>. | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]</del> | ||
| Warning | | Warning | ||
− | | | + | | 6.0 |
| ''Use the object literal notation {}.'' | | ''Use the object literal notation {}.'' | ||
| Flags <code>new Object()</code>. | | Flags <code>new Object()</code>. | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]</del> | ||
| Warning | | Warning | ||
− | | | + | | 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. | ||
|- | |- | ||
− | + | !| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461848 no-proto] | |
− | !| | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
| Error | | Error | ||
| - | | - | ||
Line 468: | Line 206: | ||
| | | | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-redeclare]</del> | ||
| Warning | | Warning | ||
Line 475: | Line 212: | ||
| 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>. | ||
|- | |- | ||
− | + | !| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461850 no-self-compare] | |
− | !| | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
| Error | | Error | ||
| - | | - | ||
Line 513: | Line 218: | ||
| Flags comparisons where the left- and right-hand sides are the same. | | Flags comparisons where the left- and right-hand sides are the same. | ||
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=438319 no-shadow]</del> | |
− | + | ||
| Warning | | Warning | ||
| 8.0 | | 8.0 | ||
Line 520: | Line 224: | ||
| 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. | ||
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=461321 no-shadow-global]</del> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id= | + | |
| Warning | | Warning | ||
− | | | + | | 9.0 |
− | | '' | + | | '''{a}' shadows a global member.'' |
− | | Flags | + | | Flags variables that have the same name as a variable declared in the global scope or specified environments. |
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-undef]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-undef]</del> | ||
| Error | | Error | ||
Line 573: | Line 238: | ||
* Predefined environments (eg. '''node''', '''browser''') can be set in the /*jslint */ block. | * Predefined environments (eg. '''node''', '''browser''') can be set in the /*jslint */ block. | ||
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=427310 no-unused-params]</del> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id= | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
| Warning | | Warning | ||
| - | | - | ||
− | | '' | + | | "Parameter '{param}' is not used." |
− | | Flags expressions | + | | Flags parameters in function declarations / expressions if they are not being used |
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-unused-vars]</del> | |
− | !| < | + | |
| Warning | | Warning | ||
| 5.0 | | 5.0 | ||
Line 601: | Line 250: | ||
| | | | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-use-before-define]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=414779 no-use-before-define]</del> | ||
| Warning | | Warning | ||
Line 608: | Line 256: | ||
| | | | ||
|- | |- | ||
− | + | !| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461854 no-with] | |
− | !| no-with | + | |
| Warning | | Warning | ||
| - | | - | ||
Line 615: | Line 262: | ||
| Treated as fatal parse error in JSLint. | | Treated as fatal parse error in JSLint. | ||
|- | |- | ||
− | + | !| <del>[http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=f61bdaf06ac2f40eaca4daed39520cd60c41f5f3 radix]</del> | |
− | !| | + | | Warning |
− | | | + | | 8.0 |
− | | | + | | ''Missing radix parameter.'' |
− | | '' | + | | Warns when parseInt() called without the 2nd parameter (radix). |
− | | | + | |
|- | |- | ||
− | + | !| <del>[http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=6e517847ef0742b090130748fb9a0329d33e16bf throw-error]</del> | |
− | !| | + | |
| Warning | | Warning | ||
− | | | + | | 7.0 |
| | | | ||
− | | Flags | + | | Flags code that throws a non-Error, eg. <code>throw "a problem occurred";</code> |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </ | + | |
− | + | ||
− | + | ||
|- | |- | ||
+ | |} | ||
− | + | === Code Style === | |
− | + | These rules are not problems in any way but will warn based on certain accepted styles for coding. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | {| class="wikitable" border="1" cellpadding="5" cellspacing="0" style="width: 100%;" | |
− | | | + | ! style="background:#efefef;" width=5% | Rule |
− | | | + | ! style="background:#efefef;" width=5% | Default Severity |
− | + | ! style="background:#efefef;" width=5% | Available Since | |
− | | | + | ! style="background:#efefef;" width=40%| Problem Message |
+ | ! style="background:#efefef;" width=40% | Details | ||
|- | |- | ||
− | + | !| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=428429 missing-nls] | |
− | !| | + | |
| Ignore | | Ignore | ||
| - | | - | ||
| | | | ||
− | | Flags | + | | Flags String literals that are not properly NLS'd |
|- | |- | ||
− | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]</del> | |
− | !| <del> | + | | Error |
− | | | + | | 6.0 |
+ | | ''Missing parentheses invoking constructor.'' | ||
+ | | Flags <code>new Whatever</code> | ||
+ | |- | ||
+ | !| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=425200 no-mixed-returns] | ||
+ | | Error | ||
| - | | - | ||
− | | | + | | |
− | | | + | | Flags functions that return more than one kind of item, for example returning String and Object |
|- | |- | ||
− | + | !| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=461852 no-undef-init] | |
− | !| | + | |
| Warning | | Warning | ||
| - | | - | ||
− | | '' | + | | ''It is not necessary to initialize '{variable}' to 'undefined'.'' |
| | | | ||
|- | |- | ||
− | |||
!| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=427930 semi]</del> | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=427930 semi]</del> | ||
| Warning | | Warning | ||
Line 684: | Line 316: | ||
| | | | ||
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|} | |} | ||
− | + | == 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.'' | ''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.'' | ||
Revision as of 12:23, 10 March 2015
Orion 5.0 moved to ESLint as the validator that ships with Orion. This page captures ongoing issues.
Contents
Rules
The following table describes all of the rules currently available in Orion and ones that we plan to add in the future.
Rules that are currently available are struck out.
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 |
---|---|---|---|---|
|
Ignore | 8.0 | Trailing commas in object expressions are discouraged. | Flags trailing commas in object expressions. |
|
Error | 8.0 | Expected a conditional expression and instead saw an assignment. | Flags assignment in an if/while/do..while/for condition.
|
|
Error | 8.0 | Discouraged use of console in browser-based code. | Flags the use of console in browser-based code |
|
Error | 8.0 | Discouraged use of constant as a conditional expression. | Flags the use of a constant as a conditional expression |
|
Warning | 6.0 | debugger' statement use is discouraged. | |
|
Error | 6.0 | Duplicate object key '{key}'. | Flags object literals that contain the same key more than once. |
|
Warning | 7.0 | Flags an empty block like if (something) { } .
| |
|
Warning | 5.0 | Unnecessary semicolon. | |
|
Error | 8.0 | Avoid using multiple spaces in regular expressions. Use ' {${0}}' instead. | Flags regular expressions that have two or more subsequent spaces. |
|
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 |
|
Warning | 8.0 | Sparse array declarations should de avoided. | Flags sparse arrays with null elements |
|
Error | - | Unreachable code. | Flags statements that occur after a return , throw , etc.
|
|
Error | 6.0 | Use the isNaN function to compare with NaN. |
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 |
---|---|---|---|---|
block-scoped-var | Error | - | '{variable}' is already defined. |
|
|
Ignore | 6.0 | Statements should be enclosed in braces. | |
|
Warning | 5.0 |
|
|
|
Ignore | 5.0 | "Missing documentation for function '{name}.'" | Flags missing documentation nodes on function declarations and function expressions when they appear as object properties |
missing-doc-items | Ignore | - | Flags missing documentation for parameters, returns, throws, etc on function declarations and function expressions when they appear as object properties | |
|
Error | 9.0 | arguments.{callee, caller} is deprecated. | Flags references to arguments.callee and arguments.caller .
|
|
Ignore | 6.0 | 'eval' function calls are discouraged. | |
|
Error | - | Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above | Flags a fallthrough case within a switch statement, unless it is explicitly commented.
|
|
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.
|
|
Error | 8.0 | Discouraged __iterator__ property use. | Flags use of __iterator__ as an identifier name or property key. |
|
Warning | 6.0 | Use the array literal notation []. | Flags new Array() .
|
|
Warning | 6.0 | The Function constructor is eval. | Flags new Function() .
|
|
Warning | 6.0 | Use the object literal notation {}. | Flags new Object() .
|
|
Warning | 6.0 | Do not use {String, Number, Boolean, Math, JSON} as a constructor. | Flags new applied to any of those.
|
no-proto | Error | - |
|
|
|
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 | - | Flags comparisons where the left- and right-hand sides are the same. | |
|
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. |
|
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. |
|
Error | 5.0 | '{variable}' is not defined. |
|
|
Warning | - | "Parameter '{param}' is not used." | Flags parameters in function declarations / expressions if they are not being used |
|
Warning | 5.0 | Function declares unused variable '{a}'. | |
|
Warning | 5.0 | '{a}' was used before it was defined. | |
no-with | Warning | - | Expected an identifier and instead saw 'with'. | Treated as fatal parse error in JSLint. |
|
Warning | 8.0 | Missing radix parameter. | Warns when parseInt() called without the 2nd parameter (radix). |
|
Warning | 7.0 | Flags code that throws a non-Error, eg. throw "a problem occurred";
|
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 |
---|---|---|---|---|
missing-nls | Ignore | - | Flags String literals that are not properly NLS'd | |
|
Error | 6.0 | Missing parentheses invoking constructor. | Flags new Whatever
|
no-mixed-returns | Error | - | 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'. | |
|
Warning | 5.0 | Missing semicolon. |
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:
- Create a new test file for the rule at: /eslint/tests/lib/rules/{rule-name}.js.
- Link your test to the suite in /eslint/tests/load-tests.js.
- Implement the actual logic for your rule in /eslint/lib/load-rules-async.js.
At this point you should run the JS bundle tests and ensure your rule works as intended. To get your rule running in the Orion product's validator, there are additional steps:
- Create strings for the validation message(s) generated by your rule in /javascript/nls/root/problems.js.
- Create a short string describing what your rule does in /javascript/nls/root/messages.js.
- 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.
- Add a config entry for your rule to the default ESLint config object in /javascript/validator.js.
- 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.
- ESLint now has its own syntax for this:
i18n
We need to support i18n. Pre-req is bug 422278 (orion.edit.validator support for i18n).