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
Don't force arrow function body on same line #760
Comments
Oh, those are related? I really need to look at those ;) |
One thing I want to do at some point is to disallow last argument expansion if the params don't fit in a single line. /* ... */ fn((
err,
result
) => {
// ...
}); should be formatted as /* ... */ fn(
(err, result) => {
// ...
}
); |
#847 makes it look: const promiseFromCallback = fn =>
new Promise((resolve, reject) => fn((err, result) => {
if (err) return reject(err);
return resolve(result);
})); instead. It's not the original one but looks way less broken than what is currently in prettier. |
That new style looks much better. 👌🏻 The original function is formatted according to my personal preference but anything non-broken looking is good with prettier. |
In practice, trying to allow calls to be inlined is causing a lot of code to look very weird and unstable as seen by the four issues this is fixing. It also requires us to add a conditional group and do hackery around it. Fixes prettier#959 Fixes prettier#760 Fixes prettier#615 Fixes prettier#625
In practice, trying to allow calls to be inlined is causing a lot of code to look very weird and unstable as seen by the four issues this is fixing. It also requires us to add a conditional group and do hackery around it. Fixes prettier#959 Fixes prettier#760 Fixes prettier#615 Fixes prettier#625
@vjeux as @Hilzu had in his original, I too think it is more readable to to see function bodies nested more or less regardless of how small they are. For example I think this more readable: const imageParams = src =>
src.replace("__IMAGE_PARAMS__", "b_white") than: const imageParams = src => src.replace("__IMAGE_PARAMS__", "b_white") I realize not everyone may agree so maybe this feature would be best as an opt-in flag. Is there an issue already tracking this described refinement or should I create a new one? Thanks! |
I'd like to add a +1 to @jasonkuhrt as well. I much prefer the body in a separate line. This option exist anywhere and maybe I'm just missing it? |
I would like to also second @jasonkuhrt and then on top of that third @spencerfdavis second of @jasonkuhrt comment. |
I created a function like this:
This seems pretty clear to me with all the arrow function bodies moved to a new line. Prettier formats that function to this:
At least to me that is a lot less readable than the first one. This formatting seems to be related to always moving the body of an arrow function to the same line as the arrow. I'm not sure this creates well formatted code.
I also added that code to prettier.github.io
The text was updated successfully, but these errors were encountered: