Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: function-paren-newline rule (fixes #6074)
- Loading branch information
1 parent
ff8c4bb
commit 855af35
Showing
3 changed files
with
993 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
# enforce consistent line breaks inside function parentheses (function-paren-newline) | ||
|
||
(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixes problems reported by this rule. | ||
|
||
Many styleguides require or disallow newlines inside of function parentheses. | ||
|
||
## Rule Details | ||
|
||
This rule enforces consistent line breaks inside parentheses of function parameters or arguments. | ||
|
||
### Options | ||
|
||
This rule has a single option, which can either be a string or an object. | ||
|
||
* `"always"` requires line breaks inside all function parentheses. | ||
* `"never"` disallows line breaks inside all function parentheses. | ||
* `"multiline"` (default) requires linebreaks inside function parentheses if any of the parameters/arguments have a line break between them. Otherwise, it disallows linebreaks. | ||
* `{ "minItems": value }` requires linebreaks inside function parentheses if the number of parameters/arguments is at least `value`. Otherwise, it disallows linebreaks. | ||
|
||
Example configurations: | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"function-paren-newline": ["error", "never"] | ||
} | ||
} | ||
``` | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"function-paren-newline": ["error", { "minItems": 3 }] | ||
} | ||
} | ||
``` | ||
|
||
Examples of **incorrect** code for this rule with the `"always"` option: | ||
|
||
```js | ||
/* eslint function-paren-newline: ["error", "always"] */ | ||
|
||
function foo(bar, baz) {} | ||
|
||
var foo = function(bar, baz) {}; | ||
|
||
var foo = (bar, baz) => {}; | ||
|
||
foo(bar, baz); | ||
``` | ||
|
||
Examples of **correct** code for this rule with the `"always"` option: | ||
|
||
```js | ||
/* eslint function-paren-newline: ["error", "always"] */ | ||
|
||
function foo( | ||
bar, | ||
baz | ||
) {} | ||
|
||
var foo = function( | ||
bar, baz | ||
) {}; | ||
|
||
var foo = ( | ||
bar, | ||
baz | ||
) => {}; | ||
|
||
foo( | ||
bar, | ||
baz | ||
); | ||
``` | ||
|
||
Examples of **incorrect** code for this rule with the `"never"` option: | ||
|
||
```js | ||
/* eslint function-paren-newline: ["error", "never"] */ | ||
|
||
function foo( | ||
bar, | ||
baz | ||
) {} | ||
|
||
var foo = function( | ||
bar, baz | ||
) {}; | ||
|
||
var foo = ( | ||
bar, | ||
baz | ||
) => {}; | ||
|
||
foo( | ||
bar, | ||
baz | ||
); | ||
``` | ||
|
||
Examples of **correct** code for this rule with the `"never"` option: | ||
|
||
```js | ||
/* eslint function-paren-newline: ["error", "never"] */ | ||
|
||
function foo(bar, baz) {} | ||
|
||
function foo(bar, | ||
baz) {} | ||
|
||
var foo = function(bar, baz) {}; | ||
|
||
var foo = (bar, baz) => {}; | ||
|
||
foo(bar, baz); | ||
|
||
foo(bar, | ||
baz); | ||
``` | ||
|
||
Examples of **incorrect** code for this rule with the default `"multiline"` option: | ||
|
||
```js | ||
/* eslint function-paren-newline: ["error", "multiline"] */ | ||
|
||
function foo(bar, | ||
baz | ||
) {} | ||
|
||
var foo = function( | ||
bar, baz | ||
) {}; | ||
|
||
var foo = ( | ||
bar, | ||
baz) => {}; | ||
|
||
foo(bar, | ||
baz); | ||
|
||
foo( | ||
function() { | ||
return baz; | ||
} | ||
); | ||
``` | ||
|
||
Examples of **correct** code for this rule with the default `"multiline"` option: | ||
|
||
```js | ||
/* eslint function-paren-newline: ["error", "multiline"] */ | ||
|
||
function foo(bar, baz) {} | ||
|
||
var foo = function( | ||
bar, | ||
baz | ||
) {}; | ||
|
||
var foo = (bar, baz) => {}; | ||
|
||
foo(bar, baz, qux); | ||
|
||
foo( | ||
bar, | ||
baz, | ||
qux | ||
); | ||
|
||
foo(function() { | ||
return baz; | ||
}); | ||
``` | ||
|
||
Examples of **incorrect** code for this rule with the `{ "minItems": 3 }` option: | ||
|
||
```js | ||
/* eslint function-paren-newline: ["error", { "minItems": 3 }] */ | ||
|
||
function foo( | ||
bar, | ||
baz | ||
) {} | ||
|
||
function foo(bar, baz, qux) {} | ||
|
||
var foo = function( | ||
bar, baz | ||
) {}; | ||
|
||
var foo = (bar, | ||
baz) => {}; | ||
|
||
foo(bar, | ||
baz); | ||
``` | ||
|
||
Examples of **correct** code for this rule with the `{ "minItems": 3 }` option: | ||
|
||
```js | ||
/* eslint function-paren-newline: ["error", { "minItems": 3 }] */ | ||
|
||
function foo(bar, baz) {} | ||
|
||
var foo = function( | ||
bar, | ||
baz, | ||
qux | ||
) {}; | ||
|
||
var foo = ( | ||
bar, baz, qux | ||
) => {}; | ||
|
||
foo(bar, baz); | ||
|
||
foo( | ||
bar, baz, qux | ||
); | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If don't want to enforce consistent linebreaks inside function parentheses, do not turn on this rule. |
Oops, something went wrong.