Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
f62cff6
commit 7ebd9d6
Showing
4 changed files
with
1,216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
# enforce line breaks between array elements (array-element-newline) | ||
|
||
A number of style guides require or disallow line breaks between array elements. | ||
|
||
## Rule Details | ||
|
||
This rule enforces line breaks between array elements. | ||
|
||
## Options | ||
|
||
This rule has either a string option: | ||
|
||
* `"always"` (default) requires line breaks between array elements | ||
* `"never"` disallows line breaks between array elements | ||
|
||
Or an object option (Requires line breaks if any of properties is satisfied. Otherwise, disallows line breaks): | ||
|
||
* `"multiline": <boolean>` requires line breaks if there are line breaks inside elements. If this is false, this condition is disabled. | ||
* `"minItems": <number>` requires line breaks if the number of elements is at least the given integer. If this is 0, this condition will act the same as the option `"always"`. If this is `null` (the default), this condition is disabled. | ||
|
||
### always | ||
|
||
Examples of **incorrect** code for this rule with the default `"always"` option: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", "always"]*/ | ||
|
||
var c = [1, 2]; | ||
var d = [1, 2, 3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
Examples of **correct** code for this rule with the default `"always"` option: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", "always"]*/ | ||
|
||
var a = []; | ||
var b = [1]; | ||
var c = [1, | ||
2]; | ||
var d = [1, | ||
2, | ||
3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, | ||
function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
### never | ||
|
||
Examples of **incorrect** code for this rule with the default `"never"` option: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", "never"]*/ | ||
|
||
var c = [ | ||
1, | ||
2 | ||
]; | ||
var d = [ | ||
1, | ||
2, | ||
3 | ||
]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, | ||
function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
Examples of **correct** code for this rule with the `"never"` option: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", "never"]*/ | ||
|
||
var a = []; | ||
var b = [1]; | ||
var c = [1, 2]; | ||
var d = [1, 2, 3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
### multiline | ||
|
||
Examples of **incorrect** code for this rule with the `{ "multiline": true }` option: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", { "multiline": true }]*/ | ||
|
||
var d = [1, | ||
2, 3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
Examples of **correct** code for this rule with the `{ "multiline": true }` option: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", { "multiline": true }]*/ | ||
|
||
var a = []; | ||
var b = [1]; | ||
var c = [1, 2]; | ||
var d = [1, 2, 3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, | ||
function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
### minItems | ||
|
||
Examples of **incorrect** code for this rule with the `{ "minItems": 3 }` option: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", { "minItems": 3 }]*/ | ||
|
||
var c = [1, | ||
2]; | ||
var d = [1, 2, 3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, | ||
function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
Examples of **correct** code for this rule with the `{ "minItems": 3 }` option: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", { "minItems": 3 }]*/ | ||
|
||
var a = []; | ||
var b = [1]; | ||
var c = [1, 2]; | ||
var d = [1, | ||
2, | ||
3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
### multiline and minItems | ||
|
||
Examples of **incorrect** code for this rule with the `{ "multiline": true, "minItems": 3 }` options: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", { "multiline": true, "minItems": 3 }]*/ | ||
|
||
var c = [1, | ||
2]; | ||
var d = [1, 2, 3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
Examples of **correct** code for this rule with the `{ "multiline": true, "minItems": 3 }` options: | ||
|
||
```js | ||
/*eslint array-element-newline: ["error", { "multiline": true, "minItems": 3 }]*/ | ||
|
||
var a = []; | ||
var b = [1]; | ||
var c = [1, 2]; | ||
var d = [1, | ||
2, | ||
3]; | ||
var e = [ | ||
function foo() { | ||
dosomething(); | ||
}, | ||
function bar() { | ||
dosomething(); | ||
} | ||
]; | ||
``` | ||
|
||
|
||
## When Not To Use It | ||
|
||
If you don't want to enforce linebreaks between array elements, don't enable this rule. | ||
|
||
## Compatibility | ||
|
||
* **JSCS:** [validateNewlineAfterArrayElements](http://jscs.info/rule/validateNewlineAfterArrayElements) | ||
|
||
## Related Rules | ||
|
||
* [array-bracket-spacing](array-bracket-spacing.md) | ||
* [array-bracket-newline](array-bracket-newline.md) | ||
* [object-property-newline](object-property-newline.md) | ||
* [object-curly-spacing](object-curly-spacing.md) | ||
* [object-curly-newline](object-curly-newline.md) | ||
* [max-statements-per-line](max-statements-per-line.md) | ||
* [block-spacing](block-spacing.md) | ||
* [brace-style](brace-style.md) |
Oops, something went wrong.