New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule Proposal: newline-in-function-parens #6074
Comments
I think this is already covered by |
I don't think so, because it's about the function parenthesis and not the braces! |
Oh, I see! Sorry, got a bit confused. Yes, ignore my previous comment. |
At the risk of sounding like a broken record, what about parentheses not associated with function declarations/expressions? Does eslint have a general strategy for style-relevant characters that appear in distinct productions (of which parentheses are just the most obvious example)? |
Original JSCS rule seems to apply this rule to FunctionDeclaration, FunctionExpression, and ArrowFunctionExpression. I think, we can add {
"newline-in-function-parens": ["error", "always" or "never" or "multiline" or {"minItems": 2} or "any"]
// or
"newline-in-function-parens": ["error", {
"open": "always" or "never" or "multiline" or {"minItems": 2} or "any",
"close": "always" or "never" or "multiline" or {"minItems": 2} or "any",
"overrides": {
"declaration": null,
"expression": null,
"arrow": null
}
}]
}
|
Does this also cover newlines between arguments? If not, could we also add:
Valid /*eslint newline-in-function-parens: ["error", {"between": "multiline"}]*/
function foo(
) {}
function foo(
a
) {}
function foo(a) {}
function foo(
a,
b
) {}
function foo(
a = function() {
dosomething();
}
) {} Invalid /*eslint newline-in-function-parens: ["error", {"between": "multiline"}]*/
function foo(
a, b
) {} My use-case: We enforce someReallyCoolFunction(this.aLongPropertyName.subPropertyNamesToo,
this.anotherPropertyName.whySoManySubPropertyNames); Which we would like to enforce being written as: someReallyCoolFunction(
this.aLongPropertyName.subPropertyNamesToo,
this.anotherPropertyName.whySoManySubPropertyNames
); Ie; When there is a newline anywhere, everything should be newline. Otherwise, nothing should be newline. |
@jesstelford Very sorry we lost track of this. I like the idea of having a separate rule for newlines between function arguments (we have a similar approach for objects via If you can show that that was enforced by a JSCS rule, then we can flag that new proposal under the JSCS Compatibility milestone as well. If not, no worries, we will still evaluate the proposal 😄 |
@mysticatea I've 👍'd this issue. I'm wondering, what do you think of having the overrides be named by the JSTree node types (FunctionDeclaration, FunctionExpression, ArrowFunctionExpression)? That would be more consistent with some of our other rules. |
Looks like there are 3 👍s (@platinumazure, me, and @vitorbal on #6074 (comment)) so I'm marking this as accepted. |
I think we still need a champion for this one, though! |
I'm willing to champion it, but I wasn't sure whether @mysticatea is championing it. |
I'm working on this. |
Actually, looking at this again I have a question: The rule is called If not, I think we should modify the name of the rule to clarify that only params are checked, (and maybe have a separate rule to check argument parens). |
EDIT: I updated options in #6074 (comment)
From validateAlignedFunctionParameters.
This will require/disallow line breaks after open parentheses of function parameters and before close parentheses of function parameters.
"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:
Invalid:
The text was updated successfully, but these errors were encountered: