Leave one-line functions alone
See original GitHub issuePrettier 1.10.2 Playground link
--arrow-parens always
Input:
const sha256 = (data) => crypto.createHash("sha256").update(data).digest("hex");
Output:
const sha256 = (data) =>
crypto
.createHash("sha256")
.update(data)
.digest("hex");
Expected behavior:
The input was perfectly fine as it stood; it was a nice one-liner, exactly 80 characters long. Breaking it into multiple lines just makes it less clear. Is there a specific reason prettier behaves this way?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:155
- Comments:49 (15 by maintainers)
Top Results From Across the Web
Leave one-line functions alone · Issue #4125 · prettier/prettier
Expected behavior: The input was perfectly fine as it stood; it was a nice one-liner, exactly 80 characters long. Breaking it into multiple ......
Read more >Is there a way with .clang-format to break before one line ...
To have a short function body on a separate line add this to the .clang-format file: AllowShortFunctionsOnASingleLine: Empty.
Read more >My boss asks me to stop writing small functions and do ...
One way to shorten a function is to extract various helper functions. That can be a good idea when it extracts a self-contained...
Read more >ES5 functions vs. ES6 'fat arrow' functions | by Jason Arnold
They leave it alone so that it stays the same as the context in which the function was created. Honestly, I still have...
Read more >Write more one-line functions - JavaScript Code Readability
Write more one-line functions · Showing meaning through function names. You've probably seen code like this: · Preparing for future changes. Look ...
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
IMO the current output is much more clean, I wouldn’t like it to be changed. It seems as a step backwards to me.
Maybe that could be implemented similarly to
Array
s andObject
s:printWidth
=> keep inlinedprintWidth
=> break into multiple lineThis way users can choose for each specific case if it make much sense to write a one-liner or not.
See playground example with objects (to clarify what I mean).