Prettier formats a sensible one-liner into seven lines
See original GitHub issuePrettier 1.15.3 Playground link
--parser babylon
Input:
eventStore.update(id, _.flow(updater, incrementVersion))
Output:
eventStore.update(
id,
_.flow(
updater,
incrementVersion
)
);
Expected behavior: Unchanged:
eventStore.update(id, _.flow(updater, incrementVersion))
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Options - Prettier
Prettier's printWidth option does not work the same way. It is not the hard upper allowed line length limit. It is a way...
Read more >Prettier — The Formatting Big Brother of ESLint - In Plain English
Prettier is the formatting big brother to ESLint. Where ESLint focuses mainly on code quality with some code formatting, Prettier focuses ...
Read more >Is there a config in prettier to keep line breaks? - Stack Overflow
Not true. This only stops formatting because lack of config file. – oxk4r. Dec 1, 2021 at 17:18.
Read more >How to write a plugin for Prettier | by Franco Victorio | Medium
Prettier's philosophy is to keep them (although if there are two or more blank lines together, they are replaced by a single blank...
Read more >Google JavaScript Style Guide
7 JSDoc: 7.1 General form: 7.2 Markdown: 7.3 JSDoc tags: 7.4 Line wrapping ... A JavaScript source file is described as being in...
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
I think we maybe should revisit this heuristic.
Could such a function call default to being one-line (as long as it’s within the character limit), but in the same way that an object can always be made to be on multiple lines if a newline is added after
{
, this could this be made to adapt the following behaviour:OR
This would also have the benefit of not affecting existing prettier code that has already been split over multiple lines by the existing heuristic.
It also brings it much more in-line with the way that prettier handles objects over multiple lines.
It also doesn’t rely on special function name detection, and as it is specific enough to only apply to function calls within function calls, it can handle many of these edge-cases without either being too constrictive or too open.
Just the one-liner as is
Input:
Output:
A newline after the first opening parentheses of the first function call
Input:
Output:
Multiple lines, but no newline between first opening parentheses of first function call and first parameter
Input:
Output:
A one-liner with a parameter function call that exceeds the character limit
Input:
Output: