-
Notifications
You must be signed in to change notification settings - Fork 17
feat: format list-like objects with comments #154
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
feat: format list-like objects with comments #154
Conversation
a206163
to
cdc2564
Compare
A big challenge is func-call and chain-access. It can be divided into two cases, not considering comments: #{
// If we can put everything except the arguments of the last one in one line and the last one is *heavy enough*.
a.b().c().d(
e(..)
)
// Otherwise, chain them.
a
.b(..)
.c(..)
.d(e(..))
} We don't want to see an item in the middle split into multiple lines while there exists |
Some insights about comment handling. We can abstract a line as
If the items are in a single line, we put the attached block comment before the comma. Otherwise after the comma. So the comma positions may change. |
BTW, is dot chain formatting still a problem? I haven't examine snapshots yet. I can help take a look if the problem still present. |
I haven't touched it yet, so the chain formatting is expected to remain unchanged. |
e462cb3
to
3ed358a
Compare
3ed358a
to
57978ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just go through all snapshot updates
fdfec24
to
5f49003
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
BTW please consider editing the PR description to reflect latest changes. thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This PR rewrites the pretty conversion of list-like objects, including arrays, dicts, destructions, and parameters (and closure definitions).
It supports comments within these objects. Each item can be attached with comments at the front or back.
It also fixes:
Except that, the styles remain unchanged (if formattable before).
Some examples:
may be formatted to
and
to
It also fixes a bug with destruction. Previously,
will be formatted to
Now the pattern is handled correctly.