question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Leave one-line functions alone

See original GitHub issue

Prettier 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:closed
  • Created 6 years ago
  • Reactions:155
  • Comments:49 (15 by maintainers)

github_iconTop GitHub Comments

153reactions
merlinnotcommented, Mar 9, 2018

IMO the current output is much more clean, I wouldn’t like it to be changed. It seems as a step backwards to me.

38reactions
pvdlgcommented, Mar 13, 2018

Maybe that could be implemented similarly to Arrays and Objects:

  • If the user inline them and the line is shorter than printWidth => keep inlined
  • If the user write them on multiple lines => keep on multiple line
  • If the user inline them and the line is longer than printWidth => break into multiple line

This 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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found