Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Long sequence expressions #2413

Closed
Tracked by #2403
MichaReiser opened this issue Apr 13, 2022 · 2 comments · Fixed by #2541
Closed
Tracked by #2403

Long sequence expressions #2413

MichaReiser opened this issue Apr 13, 2022 · 2 comments · Fixed by #2541
Assignees
Labels
A-Formatter Area: formatter I-Normal Implementation: normal understanding of the tool and awareness

Comments

@MichaReiser
Copy link
Contributor

MichaReiser commented Apr 13, 2022

Rome's formatter doesn't break long sequence expressions whereas Prettier does.

Playground

Input

abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsfddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd;

abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf;

Prettier

abcdefghijklkmnopqrstufwkdsf,
	abcdefghijklkmnopqrstufwkdsfddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd;

abcdefghijklkmnopqrstufwkdsf,
	abcdefghijklkmnopqrstufwkdsf,
	abcdefghijklkmnopqrstufwkdsf,
	abcdefghijklkmnopqrstufwkdsf,
	abcdefghijklkmnopqrstufwkdsf,
	abcdefghijklkmnopqrstufwkdsf,
	abcdefghijklkmnopqrstufwkdsf,
	abcdefghijklkmnopqrstufwkdsf;

Rome

abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsfddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd;

abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf, abcdefghijklkmnopqrstufwkdsf;

Expected

Rome emits the same formatting for long sequence expression as Prettier.

@MichaReiser MichaReiser added good first issue Good for newcomers A-Formatter Area: formatter and removed good first issue Good for newcomers labels Apr 13, 2022
@ematipico
Copy link
Contributor

In this case we don't have anything fancy, the new logic will have to be created from scratch.

This is not a good first issue because it would require to make the AST "flat" and then correctly format. Usually we use recursion to handle these cases but we recently moved away because it's expensive.

If we aim to tackle this, I think we should use the Post-Order solution. (same for chain of call expressions)

@MichaReiser
Copy link
Contributor Author

In this case we don't have anything fancy, the new logic will have to be created from scratch.

This is not a good first issue because it would require to make the AST "flat" and then correctly format. Usually we use recursion to handle these cases but we recently moved away because it's expensive.

If we aim to tackle this, I think we should use the Post-Order solution. (same for chain of call expressions)

I'm not sure if we need a post order solution here because the formatting only affects the right hand side (and not left hand side of the expression). So it should be possible to use a regular while loop here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter I-Normal Implementation: normal understanding of the tool and awareness
Projects
Status: Done
2 participants