Skip to content

Commit

Permalink
Merge pull request #3866 from eslint/issue2271
Browse files Browse the repository at this point in the history
Docs: Prepare for rule doc linting (refs #2271)
  • Loading branch information
ilyavolodin committed Sep 25, 2015
2 parents 3837c75 + c7a5d19 commit 6762f71
Show file tree
Hide file tree
Showing 57 changed files with 256 additions and 60 deletions.
6 changes: 6 additions & 0 deletions docs/rules/array-bracket-spacing.md
Expand Up @@ -4,6 +4,8 @@ A number of style guides require or disallow spaces between array brackets. This
applies to both array literals and destructuring assignment (EcmaScript 6) using arrays.

```js
/*eslint-env es6*/

var arr = [ 'foo', 'bar' ];
var [ x, y ] = z;

Expand Down Expand Up @@ -39,6 +41,7 @@ When `"never"` is set, the following patterns are considered problems:

```js
/*eslint array-bracket-spacing: [2, "never"]*/
/*eslint-env es6*/

var arr = [ 'foo', 'bar' ]; /*error There should be no space after '['*/ /*error There should be no space before ']'*/
var arr = ['foo', 'bar' ]; /*error There should be no space before ']'*/
Expand All @@ -57,6 +60,7 @@ The following patterns are not considered problems:

```js
/*eslint array-bracket-spacing: [2, "never"]*/
/*eslint-env es6*/

var arr = [];
var arr = ['foo', 'bar', 'baz'];
Expand All @@ -82,6 +86,7 @@ When `"always"` is used, the following patterns are considered problems:

```js
/*eslint array-bracket-spacing: [2, "always"]*/
/*eslint-env es6*/

var arr = ['foo', 'bar']; /*error A space is required after '['*/ /*error A space is required before ']'*/
var arr = ['foo', 'bar' ]; /*error A space is required after '['*/
Expand All @@ -103,6 +108,7 @@ The following patterns are not considered problems:

```js
/*eslint array-bracket-spacing: [2, "always"]*/
/*eslint-env es6*/

var arr = [];
var arr = [ 'foo', 'bar', 'baz' ];
Expand Down
18 changes: 18 additions & 0 deletions docs/rules/arrow-parens.md
Expand Up @@ -8,6 +8,8 @@ be wrapped in parentheses. This rule enforces the consistent use of parentheses
This rule enforces parentheses around arrow function parameters regardless of arity. For example:

```js
/*eslint-env es6*/

// Bad
a => {}

Expand All @@ -20,6 +22,8 @@ when a comparison such as `>=` was the intent.


```js
/*eslint-env es6*/

// Bad
if (a => 2) {
}
Expand All @@ -32,6 +36,8 @@ if (a >= 2) {
The rule can also be configured to discourage the use of parens when they are not required:

```js
/*eslint-env es6*/

// Bad
(a) => {}

Expand All @@ -53,6 +59,7 @@ When the rule is set to `"always"` the following patterns are considered problem

```js
/*eslint arrow-parens: [2, "always"]*/
/*eslint-env es6*/

a => {}; /*error Expected parentheses around arrow function argument.*/
a => a; /*error Expected parentheses around arrow function argument.*/
Expand All @@ -66,6 +73,7 @@ The following patterns are not considered problems:

```js
/*eslint arrow-parens: [2, "always"]*/
/*eslint-env es6*/

() => {};
(a) => {};
Expand All @@ -80,6 +88,8 @@ a.then((foo) => { if (true) {}; });
One benefits of this option is that it prevents the incorrect use of arrow functions in conditionals:

```js
/*eslint-env es6*/

var a = 1;
var b = 2;
// ...
Expand All @@ -95,6 +105,8 @@ The contents of the `if` statement is an arrow function, not a comparison.
If the arrow function is intentional, it should be wrapped in parens to remove ambiguity.

```js
/*eslint-env es6*/

var a = 1;
var b = 0;
// ...
Expand All @@ -109,6 +121,8 @@ if ((a) => b) {
The following is another example of this behavior:

```js
/*eslint-env es6*/

var a = 1, b = 2, c = 3, d = 4;
var f = a => b ? c: d;
// f = ?
Expand All @@ -119,6 +133,8 @@ var f = a => b ? c: d;
This should be rewritten like so:

```js
/*eslint-env es6*/

var a = 1, b = 2, c = 3, d = 4;
var f = (a) => b ? c: d;
```
Expand All @@ -130,6 +146,7 @@ When the rule is set to `"as-needed"` the following patterns are considered prob

```js
/*eslint arrow-parens: [2, "as-needed"]*/
/*eslint-env es6*/

(a) => {}; /*error Unexpected parentheses around single function argument*/
(a) => a; /*error Unexpected parentheses around single function argument*/
Expand All @@ -143,6 +160,7 @@ The following patterns are not considered problems:

```js
/*eslint arrow-parens: [2, "as-needed"]*/
/*eslint-env es6*/

() => {};
a => {};
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/arrow-spacing.md
Expand Up @@ -3,6 +3,8 @@
This rule normalize style of spacing before/after an arrow function's arrow(`=>`).

```js
/*eslint-env es6*/

// { "before": true, "after": true }
(a) => {}

Expand All @@ -24,6 +26,7 @@ The following patterns are considered problems if `{ "before": true, "after": tr

```js
/*eslint arrow-spacing: 2*/
/*eslint-env es6*/

()=> {}; /*error Missing space before =>*/
() =>{}; /*error Missing space after =>*/
Expand All @@ -39,6 +42,7 @@ The following patterns are not considered problems if `{ "before": true, "after"

```js
/*eslint arrow-spacing: 2*/
/*eslint-env es6*/

() => {};
(a) => {};
Expand All @@ -50,6 +54,7 @@ The following patterns are not considered problems if `{ "before": false, "after

```js
/*eslint arrow-spacing: [2, { "before": false, "after": false }]*/
/*eslint-env es6*/

()=>{};
(a)=>{};
Expand All @@ -61,6 +66,7 @@ The following patterns are not considered problems if `{ "before": true, "after"

```js
/*eslint arrow-spacing: [2, { "before": true, "after": false }]*/
/*eslint-env es6*/

() =>{};
(a) =>{};
Expand All @@ -72,6 +78,7 @@ The following patterns are not considered problems if `{ "before": false, "after

```js
/*eslint arrow-spacing: [2, { "before": false, "after": true }]*/
/*eslint-env es6*/

()=> {};
(a)=> {};
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/block-scoped-var.md
Expand Up @@ -35,7 +35,7 @@ function doSomething() {

function doSomething() {
if (true) {
var build = true;
var build = true; /*error "build" used outside of binding context.*/
} else {
var build = false; /*error "build" used outside of binding context.*/
}
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/computed-property-spacing.md
Expand Up @@ -4,6 +4,8 @@ While formatting preferences are very personal, a number of style guides require
or disallow spaces between computed properties in the following situations:

```js
/*eslint-env es6*/

// computed properties
var obj = { prop: "value" };
var a = "prop";
Expand Down Expand Up @@ -40,6 +42,8 @@ When `"never"` is set, the following patterns will give a warning:

```js
/*eslint computed-property-spacing: [2, "never"]*/
/*eslint-env es6*/

obj[foo ] /*error There should be no space before ']'*/
obj[ 'foo'] /*error There should be no space after '['*/
var x = {[ b ]: a} /*error There should be no space after '['*/ /*error There should be no space before ']'*/
Expand All @@ -50,6 +54,7 @@ The following patterns are considered correct:

```js
/*eslint computed-property-spacing: [2, "never"]*/
/*eslint-env es6*/

obj[foo]
obj['foo']
Expand All @@ -63,6 +68,7 @@ When `"always"` is used, the following patterns will give a warning:

```js
/*eslint computed-property-spacing: [2, "always"]*/
/*eslint-env es6*/

obj[foo] /*error A space is required after '['*/ /*error A space is required before ']'*/
var x = {[b]: a} /*error A space is required after '['*/ /*error A space is required before ']'*/
Expand All @@ -77,6 +83,7 @@ The following patterns are considered correct:

```js
/*eslint computed-property-spacing: [2, "always"]*/
/*eslint-env es6*/

obj[ foo ]
obj[ 'foo' ]
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/constructor-super.md
Expand Up @@ -14,6 +14,7 @@ The following patterns are considered problems:

```js
/*eslint constructor-super: 2*/
/*eslint-env es6*/

class A {
constructor() {
Expand All @@ -36,6 +37,7 @@ The following patterns are not considered problems:

```js
/*eslint constructor-super: 2*/
/*eslint-env es6*/

class A {
constructor() { }
Expand Down
10 changes: 10 additions & 0 deletions docs/rules/generator-star-spacing.md
Expand Up @@ -6,6 +6,8 @@ These special functions are indicated by placing an `*` after the `function` key
Here is an example of a generator function:

```js
/*eslint-env es6*/

function* generator() {
yield "44";
yield "55";
Expand All @@ -15,6 +17,8 @@ function* generator() {
This is also valid:

```js
/*eslint-env es6*/

function *generator() {
yield "44";
yield "55";
Expand All @@ -24,6 +28,8 @@ function *generator() {
This is valid as well:

```js
/*eslint-env es6*/

function * generator() {
yield "44";
yield "55";
Expand Down Expand Up @@ -71,6 +77,7 @@ When using `{"before": true, "after": false}` this placement will be enforced:

```js
/*eslint generator-star-spacing: [2, {"before": true, "after": false}]*/
/*eslint-env es6*/

function *generator() {}

Expand All @@ -83,6 +90,7 @@ When using `{"before": false, "after": true}` this placement will be enforced:

```js
/*eslint generator-star-spacing: [2, {"before": false, "after": true}]*/
/*eslint-env es6*/

function* generator() {}

Expand All @@ -95,6 +103,7 @@ When using `{"before": true, "after": true}` this placement will be enforced:

```js
/*eslint generator-star-spacing: [2, {"before": true, "after": true}]*/
/*eslint-env es6*/

function * generator() {}

Expand All @@ -107,6 +116,7 @@ When using `{"before": false, "after": false}` this placement will be enforced:

```js
/*eslint generator-star-spacing: [2, {"before": false, "after": false}]*/
/*eslint-env es6*/

function*generator() {}

Expand Down

0 comments on commit 6762f71

Please sign in to comment.