-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
New Rule: continuation-linebreak #9510
Comments
Is this something that is, or could be, covered by |
@platinumazure |
|
As long as we can get both of these patterns checked and autofixed in the very near term, then that solves @airbnb's use cases - we don't have any strong preference whether it's a separate rule or enhancements to existing rules :-) |
A few thoughts after reading this again:
|
agreed.
const x = y =>
something; We find this less readable because it's not as apparent that it's a continuation; whereas in: const x = y => (
something
); the parens make it clear.
Certainly in the short term we'll implement it internally :-) however the goal is to include this in our public styleguide, so that won't suffice in the medium term. If |
yup @ljharb - const x = y => something;
// or
const x = y => (
something
); and warn on: const x = y =>
something; We added edit: missing |
@not-an-aardvark @platinumazure it seems like the two paths forward are either:
Are one of those palatable? |
In general I'm 👍 for the described scenarios (btw, thanks a lot for providing such clear rule request, it really helps). I'm just not sure about conflating arrows and equal operator into the same rule. I understand the goal, just not sure it makes sense when you are just looking through the list of rules. Would |
I think that does cover what we want; it'd be ideal to include handling of multiline + parens, but being able to autofix to one line, and manually fix to multiline + parens, is sufficient for |
…Fixes: eslint#9510) This update nonblock-statement-body-position to also warn on arrow functions. This is related to the issue: eslint#9510.
…le (Fixes: eslint#9510) This update nonblock-statement-body-position to also warn on arrow functions. This is related to the issue: eslint#9510.
…le (Refs: eslint#9510) This update nonblock-statement-body-position to also warn on arrow functions. This is related to the issue: eslint#9510.
…slint#9510) This update nonblock-statement-body-position to also warn on arrow functions. This is related to the issue: eslint#9510.
…#9510) This update nonblock-statement-body-position to also warn on arrow functions. This is related to the issue: eslint#9510.
…#9510) This update nonblock-statement-body-position to also warn on arrow functions. This is related to the issue: eslint#9510.
Adds a new rule that enforces consistency of arrow function bodies that contain an implicit return.
Adds a new rule that enforces consistency of arrow function bodies that contain an implicit return.
Adds a new rule that enforces consistency of arrow function bodies that contain an implicit return.
* New: Adds implicit-arrow-linebreak rule (refs #9510) Adds a new rule that enforces consistency of arrow function bodies that contain an implicit return. * Docs: Use "implicit-arrow-linebreak" consistently * Chore: Use name "implicit-arrow-linebreak"
Closing this since we can achieve the behavior we need by enabling Thanks for the help! |
Please describe what the rule should do:
This rule sets a strict style guideline for multiline arrow functions and expression statements; it can be customized to require or disallow a line break after
=>
or=
.Ending a line with
=>
or=
causes a readability issue by ambiguating what the assignment or function body contains. Moving the function body or second line of assignment inline beside=>
or=
should fix this issue.This rule can be auto-fixed by bumping the second line to be inline beside
=>
or=
. This can also be fixed by wrapping the multiline body in parentheses (see"multilineParens": true
option).Future Rule Extension: Add a guideline for object's that have keys and values multiple lines i.e. that end a line with a
:
.Potential Options:
Array options:
["always", { "multilineParens": false }]
- (default) require that a an assignment or arrow function must always have a line break i.e. always break on=
or=>
. This option takes an additional object parameter with the propertymultilineParens
. Setting"multilineParens": true
would require that multiline statements be wrapped in parentheses.["never", { "multilineParens": false }]
- requires that there should never be a linebreak in the middle of a continuation, i.e. never break on a=
or=>
. This takes an additional object parameter with the propertymultilineParens
. Setting"multilineParens": true
would require that multiline statements be wrapped in parentheses.["conditional", { "multilineParens": false, "maxLength": 80 }]
- requires that statements shorter than the maxLength should be inline and statements that are longer than themaxLength
need to be split up on multiple lines. This option takes an additional object parameter with the propertiesmultilineParens
andmaxLength
."multilineParens": true
would require wrapping rule violations in parentheses if they exceed themaxLength
and inline the continuation when the line length is below themaxLength
. ThemaxLength
property can have a default value of 80.What category of rule is this? (place an "X" next to just one item)
Provide 2-3 code examples that this rule will warn about:
Option:
"always", { "multilineParens": false }
Option:
"always", { "multilineParens": true }
Option:
"never", { "multilineParens": false }
Option:
"never", { "multilineParens": true }
Option:
"conditional", { "multilineParens": false, "maxLength": 20 }
Option:
"conditional", { "multilineParens": true, "maxLength": 20 }
Why should this rule be included in ESLint (instead of a plugin)?
This rule is very wide-reaching and can improve overall code style.
The text was updated successfully, but these errors were encountered: