Skip to content

Commit

Permalink
Docs: Add linting for second half of rule docs (refs #2271)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian VanSchooten committed Sep 7, 2015
1 parent 2551594 commit 850f0cc
Show file tree
Hide file tree
Showing 117 changed files with 1,694 additions and 1,214 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Expand Up @@ -10,6 +10,9 @@ insert_final_newline = true
[docs/rules/linebreak-style.md]
end_of_line = disabled

[docs/rules/indent.md]
[{docs/rules/{indent.md,no-mixed-spaces-and-tabs.md}]
indent_style = disabled
indent_size = disabled

[docs/rules/no-trailing-spaces.md]
trim_trailing_whitespace = false
6 changes: 3 additions & 3 deletions docs/rules/brace-style.md
Expand Up @@ -87,7 +87,7 @@ else { /*error Closing curly brace does not appear on the same line
}
```

The following patterns adhere to one true brace style and do not cause warnings:
The following patterns adhere to one true brace style and are not considered warnings:

```js
/*eslint brace-style: 2*/
Expand Down Expand Up @@ -164,7 +164,7 @@ if (foo) {
}
```

The following patterns adhere to Stroustrup style and do not cause warnings:
The following patterns adhere to Stroustrup style and are not considered warnings:

```js
/*eslint brace-style: [2, "stroustrup"]*/
Expand Down Expand Up @@ -243,7 +243,7 @@ if (foo) { /*error Opening curly brace appears on the same line as con
}
```

The following patterns adhere to Allman style and do not cause warnings:
The following patterns adhere to Allman style and are not considered warnings:

```js
/*eslint brace-style: [2, "allman"]*/
Expand Down
10 changes: 7 additions & 3 deletions docs/rules/func-style.md
Expand Up @@ -53,7 +53,7 @@ The following patterns are considered warnings:

var foo = function() { /*error Expected a function declaration.*/
// ...
} ;
};
```

```js
Expand All @@ -69,16 +69,20 @@ The following patterns are not considered warnings:
```js
/*eslint func-style: [2, "declaration"]*/

function foo() {
// ...
}

// Methods (functions assigned to objects) are not checked by this rule
SomeObject.foo = function() {
// ...
};
```


```js
/*eslint func-style: [2, "expression"]*/

SomeObject.foo = function() {
var foo = function() {
// ...
};
```
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-div-regex.md
Expand Up @@ -18,7 +18,7 @@ The following patterns are considered warnings:
function bar() { return /=foo/; } /*error A regular expression literal can be confused with '/='.*/
```

The following patterns adhere to this rule:
The following patterns are not considered warnings:

```js
/*eslint no-div-regex: 2*/
Expand Down
12 changes: 6 additions & 6 deletions docs/rules/no-dupe-keys.md
Expand Up @@ -18,19 +18,19 @@ The following patterns are considered warnings:
```js
/*eslint no-dupe-keys: 2*/

var foo = { /*error Duplicate key 'bar'.*/
var foo = {
bar: "baz",
bar: "qux"
bar: "qux" /*error Duplicate key 'bar'.*/
};

var foo = { /*error Duplicate key 'bar'.*/
var foo = {
"bar": "baz",
bar: "qux"
bar: "qux" /*error Duplicate key 'bar'.*/
};

var foo = { /*error Duplicate key '1'.*/
var foo = {
0x1: "baz",
1: "qux"
1: "qux" /*error Duplicate key '1'.*/
};
```

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-empty-label.md
Expand Up @@ -12,7 +12,7 @@ The following patterns are considered warnings:
```js
/*eslint no-empty-label: 2*/

labeled: /*error Unexpected label labeled*/
labeled: /*error Unexpected label "labeled"*/
var x = 10;
```

Expand Down
20 changes: 13 additions & 7 deletions docs/rules/no-fallthrough.md
Expand Up @@ -65,8 +65,10 @@ This rule is aimed at eliminating unintentional fallthrough of one case to the o
The following patterns are considered warnings:

```js
/*eslint no-fallthrough: 2*/

switch(foo) {
case 1:
case 1: /*error Expected a "break" statement before "case".*/
doSomething();

case 2:
Expand All @@ -77,6 +79,8 @@ switch(foo) {
The following patterns are considered okay and do not cause warnings:

```js
/*eslint no-fallthrough: 2*/

switch(foo) {
case 1:
doSomething();
Expand All @@ -86,13 +90,15 @@ switch(foo) {
doSomething();
}

switch(foo) {
case 1:
doSomething();
return;
function bar(foo) {
switch(foo) {
case 1:
doSomething();
return;

case 2:
doSomething();
case 2:
doSomething();
}
}

switch(foo) {
Expand Down
10 changes: 7 additions & 3 deletions docs/rules/no-floating-decimal.md
Expand Up @@ -17,14 +17,18 @@ This rule is aimed at eliminating floating decimal points and will warn whenever
The following patterns are considered warnings:

```js
var num = .5;
var num = 2.;
var num = -.7;
/*eslint no-floating-decimal: 2*/

var num = .5; /*error A leading decimal point can be confused with a dot.*/
var num = 2.; /*error A trailing decimal point can be confused with a dot.*/
var num = -.7; /*error A leading decimal point can be confused with a dot.*/
```

The following patterns are not considered warnings:

```js
/*eslint no-floating-decimal: 2*/

var num = 0.5;
var num = 2.0;
```
Expand Down
12 changes: 9 additions & 3 deletions docs/rules/no-func-assign.md
Expand Up @@ -14,24 +14,30 @@ This rule is aimed at flagging probable mistakes and issues in the form of overw
The following patterns are considered warnings:

```js
/*eslint no-func-assign: 2*/

function foo() {}
foo = bar;
foo = bar; /*error 'foo' is a function.*/

function foo() {
foo = bar;
foo = bar; /*error 'foo' is a function.*/
}
```

Unlike the same rule in JSHint, the following pattern is also considered a warning:

```js
foo = bar;
/*eslint no-func-assign: 2*/

foo = bar; /*error 'foo' is a function.*/
function foo() {}
```

The following patterns are not considered warnings:

```js
/*eslint no-func-assign: 2*/

var foo = function () {}
foo = bar;

Expand Down
24 changes: 19 additions & 5 deletions docs/rules/no-implicit-coercion.md
Expand Up @@ -48,13 +48,19 @@ This rule has three options.
The following patterns are considered warnings:

```js
var b = !!foo;
var b = ~foo.indexOf("."); // only with `indexOf`/`lastIndexOf` method calling.
/*eslint no-implicit-coercion: 2*/

var b = !!foo; /*error use `Boolean(foo)` instead.*/
var b = ~foo.indexOf("."); /*error use `foo.indexOf(".") !== -1` instead.*/
// only with `indexOf`/`lastIndexOf` method calling.

```

The following patterns are not considered warnings:

```js
/*eslint no-implicit-coercion: 2*/

var b = Boolean(foo);
var b = foo.indexOf(".") !== -1;

Expand All @@ -66,13 +72,17 @@ var n = ~foo; // This is a just binary negating.
The following patterns are considered warnings:

```js
var n = +foo;
var n = 1 * foo;
/*eslint no-implicit-coercion: 2*/

var n = +foo; /*error use `Number(foo)` instead.*/
var n = 1 * foo; /*error use `Number(foo)` instead.*/
```

The following patterns are not considered warnings:

```js
/*eslint no-implicit-coercion: 2*/

var b = Number(foo);
var b = parseFloat(foo);
var b = parseInt(foo, 10);
Expand All @@ -83,12 +93,16 @@ var b = parseInt(foo, 10);
The following patterns are considered warnings:

```js
var n = "" + foo;
/*eslint no-implicit-coercion: 2*/

var n = "" + foo; /*error use `String(foo)` instead.*/
```

The following patterns are not considered warnings:

```js
/*eslint no-implicit-coercion: 2*/

var b = String(foo);
```

Expand Down
14 changes: 9 additions & 5 deletions docs/rules/no-implied-eval.md
Expand Up @@ -27,20 +27,24 @@ This rule aims to eliminate implied `eval()` through the use of `setTimeout()`,
The following patterns are considered warnings:

```js
setTimeout("alert('Hi!');", 100);
/*eslint no-implied-eval: 2*/

setTimeout("alert('Hi!');", 100); /*error Implied eval. Consider passing a function instead of a string.*/

setInterval("alert('Hi!');", 100);
setInterval("alert('Hi!');", 100); /*error Implied eval. Consider passing a function instead of a string.*/

execScript("alert('Hi!')");
execScript("alert('Hi!')"); /*error Implied eval. Consider passing a function instead of a string.*/

window.setTimeout("count = 5", 10);
window.setTimeout("count = 5", 10); /*error Implied eval. Consider passing a function instead of a string.*/

window.setInterval("foo = bar", 10);
window.setInterval("foo = bar", 10); /*error Implied eval. Consider passing a function instead of a string.*/
```

The following patterns are not warnings:

```js
/*eslint no-implied-eval: 2*/

setTimeout(function() {
alert("Hi!");
}, 100);
Expand Down
24 changes: 10 additions & 14 deletions docs/rules/no-inline-comments.md
Expand Up @@ -14,32 +14,28 @@ This rule takes no arguments.
The following patterns are considered warnings:

```js
var a = 1; // declaring a to 1
```
/*eslint no-inline-comments: 2*/

var a = 1; // declaring a to 1 /*error Unexpected comment inline with code.*/

```js
function getRandomNumber(){
return 4; // chosen by fair dice roll.
// guaranteed to be random.
return 4; // chosen by fair dice roll. /*error Unexpected comment inline with code.*/
// guaranteed to be random.
}
```

```js
/* A block comment before code */ var a = 2;
```
/* A block comment before code */ var b = 2; /*error Unexpected comment inline with code.*/

```js
var a = 3; /* A block comment after code */
var c = 3; /* A block comment after code */ /*error Unexpected comment inline with code.*/
```

The following patterns are not warnings:

```js
/*eslint no-inline-comments: 2*/

// This is a comment above a line of code
var foo = 5;
```

```js
var foo = 5;
var bar = 5;
//This is a comment below a line of code
```

0 comments on commit 850f0cc

Please sign in to comment.