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.
Difference between revisions of "Orion/ESLint"
(→Rule priority) |
|||
(23 intermediate revisions by 2 users not shown) | |||
Line 51: | Line 51: | ||
|- | |- | ||
− | !| curly | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429722 curly]</del> |
− | | | + | | Ignore |
− | | | + | | 6.0 |
− | | '' | + | | ''Statements should be enclosed in braces.'' |
| | | | ||
|- | |- | ||
Line 107: | Line 107: | ||
| | | | ||
| | | | ||
+ | |- | ||
+ | |||
+ | !| <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 | ||
+ | | - | ||
+ | | | ||
+ | | 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 | ||
+ | | - | ||
+ | | | ||
+ | | Flags String literals that are not properly NLS'd | ||
|- | |- | ||
Line 116: | Line 137: | ||
|- | |- | ||
− | !| new-parens | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429801 new-parens]</del> |
| Error | | Error | ||
− | | | + | | 6.0 |
− | | ''Missing | + | | ''Missing parentheses invoking constructor.'' |
| Flags <code>new Whatever</code> | | Flags <code>new Whatever</code> | ||
|- | |- | ||
Line 149: | Line 170: | ||
| '''{a}' is already defined.'' | | '''{a}' is already defined.'' | ||
| | | | ||
− | * Flags a <code>catch</code> clause's variable that shadows a variable declared in an outer scope. (In IE8 this [weblog.bocoup.com/the-catch-with-try-catch/ causes the outer variable to be overwritten]). | + | * 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]). |
|- | |- | ||
Line 183: | Line 204: | ||
| Warning | | Warning | ||
| 6.0 | | 6.0 | ||
− | | | + | | ''debugger' statement use is discouraged.'' |
| | | | ||
|- | |- | ||
Line 190: | Line 211: | ||
| Warning | | Warning | ||
| - | | - | ||
− | | '' | + | | ''Deleting a local variable is discouraged.'' |
| Flags an attempt to <code>delete</code> a local variable. | | Flags an attempt to <code>delete</code> a local variable. | ||
|- | |- | ||
Line 201: | Line 222: | ||
|- | |- | ||
− | !| [https://bugs.eclipse.org/bugs/show_bug.cgi?id= | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=428430 no-dupe-keys]</del> |
| Error | | Error | ||
− | | | + | | 6.0 |
− | | ''Duplicate 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. | ||
|- | |- | ||
Line 229: | Line 250: | ||
|- | |- | ||
− | !| no-empty | + | !| <del>no-empty</del> |
| Warning | | Warning | ||
| - | | - | ||
Line 243: | Line 264: | ||
|- | |- | ||
− | !| no-eval | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429702 no-eval]</del> |
| Ignore | | Ignore | ||
− | | | + | | 6.0 |
− | | '''eval' | + | | '''eval' function calls are discouraged.'' |
| | | | ||
|- | |- | ||
Line 264: | Line 285: | ||
|- | |- | ||
− | !| no-fallthrough | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429815 no-fallthrough]</del> |
− | | | + | | 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 <code>switch</code> statement, unless it is explicitly commented. | | Flags a fallthrough case within a <code>switch</code> statement, unless it is explicitly commented. | ||
|- | |- | ||
Line 292: | Line 313: | ||
|- | |- | ||
− | !| no-implied-eval | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429707 no-implied-eval]</del> |
| Ignore | | 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>. | + | | 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. |
|- | |- | ||
Line 325: | Line 346: | ||
| | | | ||
| Flags Node.js <code>require()</code>s that mix different types of requires (core, module, file, computed). | | Flags Node.js <code>require()</code>s that mix different types of requires (core, module, file, computed). | ||
+ | |- | ||
+ | |||
+ | !| [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 | ||
|- | |- | ||
Line 352: | Line 380: | ||
|- | |- | ||
− | !| no-new-array | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-array]</del> |
| Warning | | Warning | ||
| - | | - | ||
Line 359: | Line 387: | ||
|- | |- | ||
− | !| no-new-func | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-func]</del> |
| Warning | | Warning | ||
| - | | - | ||
Line 366: | Line 394: | ||
|- | |- | ||
− | !| no-new-object | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-object]</del> |
| Warning | | Warning | ||
| - | | - | ||
Line 373: | Line 401: | ||
|- | |- | ||
− | !| no-new-wrappers | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=429817 no-new-wrappers]</del> |
| Warning | | Warning | ||
| - | | - | ||
Line 458: | Line 486: | ||
|- | |- | ||
− | !!| no-shadow | + | !!| [https://bugs.eclipse.org/bugs/show_bug.cgi?id=438319 no-shadow] |
| Warning | | Warning | ||
| - | | - | ||
Line 466: | Line 494: | ||
!| no-spaced-func | !| 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> | ||
|- | |- | ||
Line 491: | Line 521: | ||
| ''It is not necessary to initialize '{variable}' to 'undefined'.'' | | ''It is not necessary to initialize '{variable}' to 'undefined'.'' | ||
| | | | ||
+ | |- | ||
+ | |||
+ | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=427310 no-unused-params]</del> | ||
+ | | Warning | ||
+ | | - | ||
+ | | "Parameter '{param}' is not used." | ||
+ | | Flags parameters in function declarations / expressions if they are not being used | ||
|- | |- | ||
Line 509: | Line 546: | ||
|- | |- | ||
− | !| no-unreachable | + | !| <del>[https://bugs.eclipse.org/bugs/show_bug.cgi?id=436986 no-unreachable]</del> |
| Error | | Error | ||
| - | | - | ||
− | | ''Unreachable | + | | ''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. | ||
|- | |- | ||
Line 549: | Line 586: | ||
| ''Do not wrap function literals in parens unless they are to be immediately invoked.'' | | ''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> | | Flags a parenthesized function literal that is not immediately invoked, eg. <code>(function fun(){})</code> | ||
+ | |- | ||
+ | |||
+ | !| object-prototype-external | ||
+ | | Warning | ||
+ | | - | ||
+ | | | ||
+ | | Flags calls to methods of <code>Object.prototype</code> that rely on the prototype chain. For example this code should be flagged: | ||
+ | <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. | ||
|- | |- | ||
Line 594: | Line 651: | ||
!| strict | !| strict | ||
− | | | + | | Ignore |
| - | | - | ||
| | | | ||
| Flags any code that lacks the <code>"use strict"</code> pragma. | | Flags any code that lacks the <code>"use strict"</code> pragma. | ||
|- | |- | ||
+ | |||
+ | !| <del>[http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=6e517847ef0742b090130748fb9a0329d33e16bf throw-error]</del> | ||
+ | | Warning | ||
+ | | 7.0 | ||
+ | | | ||
+ | | Flags code that throws a non-Error, eg. <code>throw "a problem occurred";</code> | ||
+ | |- | ||
+ | |||
!| unnecessary-strict | !| unnecessary-strict | ||
Line 607: | Line 672: | ||
|- | |- | ||
− | !| use-isnan | + | !| <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.'' | | ''Use the isNaN function to compare with NaN.'' | ||
| | | | ||
Line 631: | Line 696: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|} | |} | ||
Revision as of 20:00, 29 October 2014
Orion 5.0 moved to ESLint as the validator that ships with Orion. This page captures ongoing issues.
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.
Rule | Default Severity | Available Since | Problem Message | Details |
---|---|---|---|---|
block-scoped-var | Error | - | '{variable}' is already defined. |
|
brace-style | Ignore | - | ||
camelcase | Ignore | - | ||
complexity | Ignore | - | ||
consistent-this | Ignore | - | ||
|
Ignore | 6.0 | Statements should be enclosed in braces. | |
dot-notation | Warning | - | {a} is better written in dot notation. | |
|
Warning | 5.0 |
|
|
guard-for-in | Ignore | - | The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
|
|
max-depth | Ignore | - | Enforces max depth of nested blocks within a function. | |
max-len | Ignore | - | Line is too long. | Enforces a maximum line length. |
max-params | Ignore | - | ||
max-statements | Ignore | - | ||
|
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 | |
missing-nls | Ignore | - | Flags String literals that are not properly NLS'd | |
new-cap | Warning | - | A constructor name should start with an uppercase letter. | |
|
Error | 6.0 | Missing parentheses invoking constructor. | Flags new Whatever
|
no-alert | Ignore | - | '{alert, confirm, prompt}' is not defined. | |
no-bitwise | Warning | - | Unexpected use of '{operator}'. | JSLint disallows bitwise ops by default. |
no-caller | Ignore | - | Flags references to arguments.callee and arguments.caller .
| |
no-catch-shadow | Warning | - | '{a}' is already defined. |
|
no-comma-dangle | Warning | - | Unexpected comma. | Flags trailing commas in object literals and array declarations. |
no-cond-assign | Ignore | - | Flags assignment in an if/while/do..while/for condition.
| |
no-console | Ignore | - | ||
no-control-regex | Ignore | - | Flags control characters (U+0000–U+001F and U+007F) within the source argument to the RegExp constructor. | |
|
Warning | 6.0 | debugger' statement use is discouraged. | |
no-delete-var | Warning | - | Deleting a local variable is discouraged. | Flags an attempt to delete a local variable.
|
no-div-regex | Warning | - | A regular expression literal can be confused with '/='. | Flags a regex literal starting with /=
|
|
Error | 6.0 | Duplicate object key '{key}'. | Flags object literals that contain the same key more than once. |
no-else-return | Warning | - | Flags an else appearing after an if that contains a return .
| |
no-empty-class | Warning | - | Empty class. | Flags an empty character class [] within a regular expression.
|
no-empty-label | Warning | - | Label '{a}' is not allowed on this statement. | Flags a labeled statement that is not a switch , for , or while .
|
|
Warning | - | Flags an empty block like if (something) { } .
| |
no-eq-null | Error | - | Use '===' to compare with 'null'. | |
|
Ignore | 6.0 | 'eval' function calls are discouraged. | |
no-ex-assign | Warning | - | Do not assign to the exception parameter. | |
|
Warning | 5.0 | Unnecessary semicolon. | |
|
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.
|
no-floating-decimal | Warning | - | A {leading, trailing} decimal point can be confused with a dot: '{n}'. | Flags numeric literals that have a leading or trailing decimal point. |
no-func-assign | Warning | - | Flags assignment to a variable that's already bound to a FunctionExpression .
| |
no-global-strict | Warning | - | Flags "use strict" applied to the entire Program.
| |
|
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 | - | Reserved name '__iterator__'. | Flags use of __iterator__ as an identifier name or property key. |
no-label-var | Error | - | '{label}' is already defined. | Flags labels that collide with an identifier. |
no-loop-func | Error | - | Don't make functions within a loop. | |
no-mixed-requires | Ignore | - | Flags Node.js require() s that mix different types of requires (core, module, file, computed).
| |
no-mixed-returns | Error | - | Flags functions that return more than one kind of item, for example returning String and Object | |
no-multi-str | Warning | - | Flags use of ES5 multiline string literals. | |
no-native-reassign | Warning | - |
|
Flags an attempt to reassign a native object like Math , Array, undefined , etc.
|
no-negated-in-lhs | Warning | - |
| |
|
Warning | - | Use the array literal notation []. | Flags new Array() .
|
|
Warning | - | The Function constructor is eval. | Flags new Function() .
|
|
Warning | - | Use the object literal notation {}. | Flags new Object() .
|
|
Warning | - | Do not use {String, Number, Boolean, Math, JSON} as a constructor. | Flags new applied to any of those.
|
no-new | Error | - | Do not use 'new' for side effects. | Flags uses of new operator in an expression that is not assigned to anything.
|
no-obj-calls | Warning | - | Math is not a function.. |
|
no-octal-escape | Warning | - | Bad escapement. | Flags octal escapes in strings, for example var x = "Copyright \251";
|
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 | - |
|
|
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-return-assign | Warning | - |
| |
no-script-url | Warning | - |
| |
no-self-compare | Error | - | Flags comparisons where the left- and right-hand sides are the same. | |
no-shadow | Warning | - | Flags variables that have the same name as a variable declared in an outer scope. | |
no-spaced-func | Ignore | - | Unnecessary space in function call. | Report on excess space in a function call, for example myFunc (); or new MyObj ();
|
no-sync | Ignore | - | Unexpected sync method: '{a}'. |
|
no-ternary | Ignore | - | Flags any use of the ternary operator cond ? thenExpr : elseExpr
| |
no-undef-init | Warning | - | It is not necessary to initialize '{variable}' to 'undefined'. | |
|
Warning | - | "Parameter '{param}' is not used." | Flags parameters in function declarations / expressions if they are not being used |
|
Error | 5.0 | '{variable}' is not defined. |
|
no-underscore-dangle | Ignore | - | Dangling '_' | |
|
Error | - | Unreachable code. | Flags statements that occur after a return , throw , etc.
|
no-unused-expressions | Warning | - | Expected an assignment or function call and instead saw an expression. | Flags expressions that appear in a statement context and don't cause side effects. |
|
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. |
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. (function fun(){})
|
object-prototype-external | Warning | - | Flags calls to methods of Object.prototype that rely on the prototype chain. For example this code should be flagged:
Example (1) is unsafe, as As for this:
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 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 | Warning | - | Too many var statements. | Allows only 1 var statement per function.
|
quote-props | Warning | - | Requires object literal keys to be quoted with " or '. | |
quotes | Ignore | - | Flags any use of single or double quote marks, depending on setting. | |
radix | Warning | - | Missing radix parameter. | Affects parseInt(). |
regex-spaces | Warning | - | Spaces are hard to count. Use {n}. | |
|
Warning | 5.0 | Missing semicolon. | |
strict | Ignore | - | Flags any code that lacks the "use strict" pragma.
| |
|
Warning | 7.0 | Flags code that throws a non-Error, eg. throw "a problem occurred";
| |
unnecessary-strict | Warning | - | Flags "use strict" on a function when the entire Program is already in strict mode.
| |
|
Error | 6.0 | Use the isNaN function to compare with NaN. | |
wrap-iife | Ignore | - |
|
Flags missing parens on immediately-invoked functions, eg. function(){ console.log('hi'); }();
|
wrap-regex | Warning | - | Wrap the /regexp/ literal in parens to disambiguate the slash operator. |
Tests
- Every rule needs extensive unit tests
- Unit tests should use Mocha
Currently the tests are run from Node.js. They do not run in the browser (yet).
Test requirements
First install Node.js. Then open a console and install Mocha globally:
$ npm install mocha -g
Then from your Orion client repository, run these commands to install eslint's dependencies:
$ cd bundles/org.eclipse.orion.client.javascript/web/eslint/ $ npm install
Running the tests
From the bundles/org.eclipse.orion.client.javascript/web/eslint/
directory, simply run npm test
:
$ npm test > eslint@0.2.0-dev test c:\Users\mamacdon\code\orion\client\bundles\org.eclipse.orion.client.javascript\web\eslint > bash scripts/test.sh ...................................................................... ............... 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 Mocha usage options for more.
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.- This would give compatibility with Orion codebase which uses these flags.
- OTOH, eslint now has its own syntax for this:
/*eslint ..*/
, which we should perhaps use instead.
i18n
We need to support i18n. Pre-req is bug 422278 (orion.edit.validator support for i18n).