-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
opa fmt ... displaces comments #1549
Comments
Thanks for filing this @mikol. I think it should be possible to at least make the formatting around
If the fix requires the position of the closing brace characters it might be more problematic since we don't have end positions. |
This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. |
Closing in favor of #4508, where we'll try to compile all ideas for the next iteration of |
Expected Behavior
How exactly the comments are preserved is more art than science at this point. That said, the following seem like good guidelines:
A. Comments within a block should remain within the block (not appear outside of the block)
B. Block-starting comments (e.g.,
{ # Begin
) should be preserved as-isC. Block-ending comments (e.g.,
} # End
) should be preserved as-isThere will inevitably be cases that can’t feasibly be accommodated because we’re talking about re-commenting code after it has been formatted, which may leave the formatted code in such a state that the original comments cannot be placed in any way that match the author’s original intent.
Given the following input, I expect formatted code to preserve comments more-or-less as suggested above.
Actual Behavior
Consider:
I would have expected
# End rule
to remain at the end of the closing curly brace as} # End rule
.Then:
The first rule body is formatted as I would expect. Each
else
isn’t as expected. For example. I would expect# Else 1
to appear after theelse
block’s opening curly braces (same as# Else 0
and# Else 2
). There’s some ambiguity, however, since I (personally) would have expected theelse
rule heads to appear on the same line as the previous closing curly (i.e.,} else = 2 { # Else 1
), but that might be a subjective style consideration.#F
and#I
should appear within the open and closing curly braces of theelse
bodies.As for:
It’s unclear what to expect in this case since the formatting rule for the array/set rewrites the original to be 100% inline.
Steps to Reproduce the Problem
Run
opa fmt ...
on the input.The text was updated successfully, but these errors were encountered: