Don't force arrow function body on same line
See original GitHub issueI created a function like this:
const promiseFromCallback = fn =>
new Promise((resolve, reject) =>
fn((err, result) => {
if (err) return reject(err);
return resolve(result);
})
);
This seems pretty clear to me with all the arrow function bodies moved to a new line. Prettier formats that function to this:
const promiseFromCallback = fn => new Promise((resolve, reject) => fn((
err,
result
) => {
if (err) return reject(err);
return resolve(result);
}));
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
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How does arrow functions behave when the body is a single ...
I wanted to know when arrow functions have a single line, the curly braces and the return keyword can be omitted, it implicitly...
Read more >arrow-body-style - ESLint - Pluggable JavaScript Linter
"never" enforces no braces around the function body (constrains arrow functions to the role of returning an expression). The second one is an...
Read more >ES6 Arrow Functions | What Not To Do | by Jacob Worrel
Arrow functions do not bind their own 'this' or 'arguments'. One of the great things about arrow functions is that they do not...
Read more >Arrow Function JavaScript Tutorial – How to Declare a JS ...
If you have a one-line arrow function (like the example above), then the value is implicitly returned. So you can omit the return...
Read more >Arrow function expressions - JavaScript - MDN Web Docs
Arrow functions don't have their own bindings to this , arguments , or ... If the body has additional lines of processing, the...
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 Free
Top 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
#847 makes it look:
instead. It’s not the original one but looks way less broken than what is currently in prettier.
Thanks for the report! This is not intended to be printed like this. #674 and #680 are attempts at fixing the problem but we’re not 100% sure what the root cause is.