Rule Proposal: newline-in-function-parens
See original GitHub issueEDIT: I updated options in https://github.com/eslint/eslint/issues/6074#issuecomment-217124523
From validateAlignedFunctionParameters.
This will require/disallow line breaks after open parentheses of function parameters and before close parentheses of function parameters.
{
"newline-in-function-parens": ["error", "always" or "never" or "multiline" or {"minItems": 2}]
}
"always"
(default) - Requires line breaks always."never"
- Disallows line breaks always."multiline"
- Requires line breaks when the content is multiline. Otherwise, disallows line breaks.{"minItems": <integer>}
- Requires line breaks when the number of items is more than the specific integer. Otherwise, disallows line breaks.
Valid:
/*eslint newline-in-function-parens: ["error", "always"]*/
function foo(
) {}
function foo(
a
) {}
function foo(
a, b
) {}
function foo(
a,
b
) {}
function foo(
a = function() {
dosomething();
}
) {}
/*eslint newline-in-function-parens: ["error", "never"]*/
function foo() {}
function foo(a) {}
function foo(a, b) {}
function foo(a,
b) {}
function foo(a = function() {
dosomething();
}) {}
/*eslint newline-in-function-parens: ["error", "multiline"]*/
function foo() {}
function foo(a) {}
function foo(a, b) {}
function foo(
a,
b
) {}
function foo(
a = function() {
dosomething();
}
) {}
/*eslint newline-in-function-parens: ["error", {"minItems": 2}]*/
function foo() {}
function foo(a) {}
function foo(
a, b
) {}
function foo(
a,
b
) {}
function foo(a = function() {
dosomething();
}) {}
Invalid:
/*eslint newline-in-function-parens: ["error", "always"]*/
function foo() {}
function foo(a) {}
function foo(a, b) {}
function foo(a,
b) {}
function foo(a = function() {
dosomething();
}) {}
/*eslint newline-in-function-parens: ["error", "never"]*/
function foo(
) {}
function foo(
a
) {}
function foo(
a, b
) {}
function foo(
a,
b
) {}
function foo(
a = function() {
dosomething();
}
) {}
/*eslint newline-in-function-parens: ["error", "multiline"]*/
function foo(
) {}
function foo(
a
) {}
function foo(
a, b
) {}
function foo(a,
b) {}
function foo(a = function() {
dosomething();
}) {}
/*eslint newline-in-function-parens: ["error", {"minItems": 2}]*/
function foo(
) {}
function foo(
a
) {}
function foo(a, b) {}
function foo(a,
b) {}
function foo(
a = function() {
dosomething();
}
) {}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:13
- Comments:13 (12 by maintainers)
Top Results From Across the Web
function-paren-newline - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >function-parentheses-newline-inside - Stylelint
Require a newline or disallow whitespace on the inside of the parentheses of functions. The fix option can automatically fix all of the...
Read more >2. Lexical analysis — Python 3.11.1 documentation
A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer. This...
Read more >Optional Braces - Scala 3 - EPFL
In a brace-delimited region, no statement is allowed to start to the left of the first statement after the opening brace that starts...
Read more >UAX #14: Unicode Line Breaking Algorithm
Newline Functions are defined in the Unicode Standard as providing additional mandatory breaks. They are not individual characters, but are encoded as sequences ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Does this also cover newlines between arguments? If not, could we also add:
between
(default is “any”) - Setting for the line break between arguments.Valid
Invalid
My use-case: We enforce
max-len
to100
, and for longer lines we can meet that rule by doing:Which we would like to enforce being written as:
Ie; When there is a newline anywhere, everything should be newline. Otherwise, nothing should be newline.
Original JSCS rule seems to apply this rule to FunctionDeclaration, FunctionExpression, and ArrowFunctionExpression.
I think, we can add
overrides
option to apply for each kind. (also, original rule can configure each paren of open/close)“always” (default) - Requires line breaks always.
“never” - Disallows line breaks always.
“multiline” - Requires line breaks when the content is multiline. Otherwise, disallows line breaks.
{“minItems”: <integer>} - Requires line breaks when the number of items is more than the specific integer. Otherwise, disallows line breaks.
"any"
- Does not warn.open
(default is"always"
) - Setting for the line break after the open parenthesis.close
(default is"always"
) - Setting for the line break before the close parenthesis.overrides
- We can override setting for each kind of functions. For example: