Skip to content
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

📝 Multi-line formatting issue #1218

Closed
1 task done
AlexBlokh opened this issue Dec 16, 2023 · 1 comment · Fixed by #1696
Closed
1 task done

📝 Multi-line formatting issue #1218

AlexBlokh opened this issue Dec 16, 2023 · 1 comment · Fixed by #1696
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@Conaclos Conaclos changed the title Multi-line formatting issue 📝 Multi-line formatting issue Dec 16, 2023
@Conaclos Conaclos added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Dec 16, 2023
@faultyserver
Copy link
Contributor

faultyserver commented Dec 17, 2023

I took a look at this thinking it would be a relatively simple solve, but it turns out this is going to be pretty complicated to solve properly.

For anyone that wants to pick this up, the relevant content is in crates/biome_js_formatter/src/utils/member_chain/chain_member.rs. Right now, the member chain splits the groups of expressions at each Call expression (plus some extra logic), and then when formatting the whole chain it looks behind the current group to see if there are empty lines that need to be preserved. This gets close to Prettier, but doesn't account for a few other things that Prettier lets collapse. Prettier also looks ahead so that only Call expressions can have empty lines after them, but Biome lets any expression have empty lines, leading to this specific behavior in this issue.

I think to solve this particular issue, there will need to be some changes to the hierarchy of formatting in the chain so that the current group can know if it's following a call expression, and also potentially some changes to the grouping logic, though so far in my exploration that seems to match Prettier decently well.

Here's Playground Link with a variety of test cases to check for completeness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants