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

Wrap long lines based on line length #26

Open
bentsherman opened this issue Sep 9, 2024 · 2 comments
Open

Wrap long lines based on line length #26

bentsherman opened this issue Sep 9, 2024 · 2 comments
Labels
formatting Related to automatic code formatting

Comments

@bentsherman
Copy link
Member

Primarily for list and map expressions, but could also apply to function calls and property chains. The best heuristic for deciding whether to wrap a statement seems to be if the statement is "too long" e.g. greater than 80 characters. But the visitor + string builder approach makes this difficult, because you don't know the line length until you already appended the line.

A simple approach would be to (1) produce the line with no wrapping (2) check the length of the line (3) re-do the line with wrapping if the unwrapped line was too long.

Ideally we would reuse the pieces instead of computing them twice, and also be able to handle nested expressions intelligently. Not yet sure what all that entails.

Until then, a simpler heuristic is the number of elements (e.g. wrap if more than 3 elements), but I suspect it might be just wrong enough to be annoying.

@bentsherman
Copy link
Member Author

Or we could simply preserve the user's choice, i.e. if an expression was wrapped (spanned multiple lines) then wrap it, otherwise don't. It will still wrap or not wrap in a consistent way without getting in the user's way.

@bentsherman
Copy link
Member Author

Actually this should be stupid easy to implement... I already have the source range of every ast node 😅

@ewels ewels added the formatting Related to automatic code formatting label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting Related to automatic code formatting
Projects
None yet
Development

No branches or pull requests

2 participants