Permalink
Browse files

Docs: Distinguish examples in rules under Possible Errors part 2

  • Loading branch information...
pedrottimark committed Mar 2, 2016
1 parent 1b9d012 commit 5319b4a458f0af7edf536845580a3439634a2ee8
@@ -8,7 +8,7 @@ JavaScript will more or less let you put semicolons after any statement without
This rule is aimed at eliminating extra unnecessary semicolons. While not technically an error, extra semicolons can be a source of confusion when reading code.
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-extra-semi: 2*/
@@ -21,7 +21,7 @@ function foo() {
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-extra-semi: 2*/
@@ -11,7 +11,7 @@ foo = bar;
This rule is aimed at flagging probable mistakes and issues in the form of overwriting a function that was written as a FunctionDeclaration. As such it will warn when this issue is encountered.
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-func-assign: 2*/
@@ -24,7 +24,7 @@ function foo() {
}
```
Unlike the same rule in JSHint, the following pattern is also considered a warning:
Examples of **incorrect** code for this rule, unlike the corresponding rule in JSHint:
```js
/*eslint no-func-assign: 2*/
@@ -33,7 +33,7 @@ foo = bar;
function foo() {}
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-func-assign: 2*/
@@ -68,7 +68,9 @@ You can set the option in configuration like this:
"no-inner-declarations": [2, "both"]
```
The following patterns are considered problems:
### functions
Examples of **incorrect** code for the default `"functions"` option:
```js
/*eslint no-inner-declarations: 2*/
@@ -84,7 +86,30 @@ function doSomethingElse() {
}
```
With `"both"` option to check variable declarations, the following are considered problems:
Examples of **correct** code for the default `"functions"` option:
```js
/*eslint no-inner-declarations: 2*/
function doSomething() { }
function doSomethingElse() {
function doAnotherThing() { }
}
if (test) {
asyncCall(id, function (err, data) { });
}
var fn;
if (test) {
fn = function fnExpression() { };
}
```
### both
Examples of **incorrect** code for the `"both"` option:
```js
/*eslint no-inner-declarations: [2, "both"]*/
@@ -100,27 +125,12 @@ function doAnotherThing() {
}
```
The following patterns are considered valid:
Examples of **correct** code for the `"both"` option:
```js
/*eslint no-inner-declarations: 2*/
/*eslint-env es6*/
function doSomething() { }
function doSomethingElse() {
function doAnotherThing() { }
}
if (test) {
asyncCall(id, function (err, data) { });
}
var fn;
if (test) {
fn = function fnExpression() { };
}
var bar = 42;
if (test) {
@@ -4,7 +4,7 @@ This rule validates string arguments passed to the `RegExp` constructor.
## Rule Details
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-invalid-regexp: 2*/
@@ -16,7 +16,7 @@ RegExp('.', 'z')
new RegExp('\\')
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-invalid-regexp: 2*/
@@ -43,7 +43,7 @@ With this rule enabled the following characters will cause warnings outside of s
\u205f - Medium Mathematical Space
\u3000 - Ideographic Space
The following examples are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-irregular-whitespace: 2*/
@@ -73,7 +73,7 @@ function thing() {
}
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-irregular-whitespace: 2*/
@@ -106,7 +106,7 @@ The `no-irregular-whitespace` rule has no required option and has one optional o
For example, to specify that you want to skip checking for irregular whitespace within comments, use the following configuration:
```json
"no-irregular-whitespace": [2, {"skipComments": true}]
"no-irregular-whitespace": [2, { "skipComments": true }]
```
## When Not To Use It
@@ -26,7 +26,7 @@ if(('' + !a) in b) {
}
```
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-negated-in-lhs: 2*/
@@ -36,7 +36,7 @@ if(!a in b) {
}
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-negated-in-lhs: 2*/
@@ -10,7 +10,7 @@ The [ECMAScript 5 specification](http://es5.github.io/#x15.8) makes it clear tha
This rule is aimed at preventing the accidental calling of global objects as functions.
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-obj-calls: 2*/
@@ -19,7 +19,7 @@ var x = Math();
var y = JSON();
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-obj-calls: 2*/
@@ -18,15 +18,15 @@ Now it is very clear that three spaces are expected to be matched.
This rule aims to eliminate errors due to multiple spaces inside of a regular expression. As such, it warns whenever more than one space in a row is found inside of a regular expression literal.
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-regex-spaces: 2*/
var re = /foo bar/;
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-regex-spaces: 2*/
@@ -20,7 +20,7 @@ The confusion around sparse arrays defined in this manner is enough that it's re
This rule aims to eliminate sparse arrays that are defined by extra commas.
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-sparse-arrays: 2*/
@@ -29,7 +29,7 @@ var items = [,];
var colors = [ "red",, "blue" ];
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-sparse-arrays: 2*/
@@ -4,18 +4,18 @@ Semicolons are optional in JavaScript, via a process called automatic semicolon
The rules for ASI are relatively straightforward: In short, as once described by Isaac Schlueter, a `\n` character always ends a statement (just like a semicolon) unless one of the following is true:
1. The statement has an unclosed paren, array literal, or object literal or ends in some other way that is not a valid way to end a statement. (For instance, ending with `.` or `,`.)
2. The line is `--` or `++` (in which case it will decrement/increment the next token.)
3. It is a `for()`, `while()`, `do`, `if()`, or `else`, and there is no `{`
4. The next line starts with `[`, `(`, `+`, `*`, `/`, `-`, `,`, `.`, or some other binary operator that can only be found between two tokens in a single expression.
* The statement has an unclosed paren, array literal, or object literal or ends in some other way that is not a valid way to end a statement. (For instance, ending with `.` or `,`.)
* The line is `--` or `++` (in which case it will decrement/increment the next token.)
* It is a `for()`, `while()`, `do`, `if()`, or `else`, and there is no `{`
* The next line starts with `[`, `(`, `+`, `*`, `/`, `-`, `,`, `.`, or some other binary operator that can only be found between two tokens in a single expression.
This particular rule aims to spot scenarios where a newline looks like it is ending a statement, but is not.
## Rule Details
This rule is aimed at ensuring that two unrelated consecutive lines are not accidentally interpreted as a single expression.
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-unexpected-multiline: 2*/
@@ -34,7 +34,7 @@ x
`hello`
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint no-unexpected-multiline: 2*/
@@ -14,7 +14,7 @@ function fn() {
This rule is aimed at detecting unreachable code. It produces an error when a statements exist after a `return`, `throw`, `break`, or `continue` statement.
The following are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint no-unreachable: 2*/
@@ -50,7 +50,7 @@ for (;;) {}
console.log("done");
```
The following patterns are not considered problems (due to JavaScript function and variable hoisting):
Examples of **correct** code for this rule, because of JavaScript function and variable hoisting:
```js
/*eslint no-unreachable: 2*/
View
@@ -6,7 +6,7 @@ In JavaScript, `NaN` is a special value of the `Number` type. It's used to repre
This rule is aimed at eliminating potential errors as the result of comparing against the special value `NaN`.
The following patterns are considered problems:
Examples of **incorrect** code for this rule:
```js
/*eslint use-isnan: 2*/
@@ -20,7 +20,7 @@ if (foo != NaN) {
}
```
The following patterns are not considered problems:
Examples of **correct** code for this rule:
```js
/*eslint use-isnan: 2*/
Oops, something went wrong.

0 comments on commit 5319b4a

Please sign in to comment.