-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
format: don't group iterable when one has an empty file name #4260
format: don't group iterable when one has an empty file name #4260
Conversation
d642acb
to
e871815
Compare
☝️ We can discern it if we give the |
e871815
to
27f9337
Compare
As mentioned in the comment, empty file names happen when the format package's Ast() function does a sweep of its input, and adds a "default location" to everything that has a nil location. During PE, when generated the pairs to save in saveUnify, we'll return Var Terms without locations. Fixing that seemed like a bigger hurdle, so I went this route. The new check is such that if any term has the default file in its location, such as would happen if we're formatting code that was created programmatically (not parsed), we'll group the terms' elements, but print them in one line. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
27f9337
to
474f168
Compare
Updated. RFR. |
@@ -336,6 +336,52 @@ a[_x[y]]`, | |||
expected: `_x | |||
a[_x[y][[z, w]]]`, | |||
}, | |||
{ |
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.
Do we have an example of how this would look prior to this fix ? I would help to understand this fix (at least to me 😅 )
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.
[
_,
"foo",
] = split( ... )
🙈
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.
This fix seems reasonable to me... if the iterable contains elements that do not have locations, the iterable cannot be sorted into groups, so just leave the iterable as-is. LGTM
As mentioned in the comment, empty file names happen when the format
package's Ast() function does a sweep of its input, and adds a
"default location" to everything that has a nil location.
During PE, when generated the pairs to save in saveUnify, we'll
return Var Terms without locations. Fixing that seemed like a bigger
hurdle, so I went this route.
The new check is such that if any term has the default file in
its location, such as would happen if we're formatting code that
was created programmatically (not parsed), we'll group the terms'
elements, but print them in one line.