-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
syntax: case clause formatting can add empty line when removing a newline #779
Comments
That sounds like a bug indeed :)
This feels like such a tiny detail to warrant adding a formatting flag. As you're aware from gofmt, the more flags the formatter gains, the less useful it becomes. But also, the more difficult it is for me to explain and document. Some instances like indentation have meet the bar for importance, but I don't think this case meets that bar. Note that we already have a flag for formatting switches,
I'm not sure. Part of the tool's design is to produce consistent output wherever possible. If we simply obeyed the user's choices everywhere, we wouldn't really format anything. For example, what if one switch mixes both styles? Should we enforce just one? What if one file has multiple switches that each use different styles? At least with the current logic, the output is consistently formatted. |
All valid points, thanks! Should I close the issue, or are you planning on fixing the empty line bug? |
We should fix the empty line bug, yup! |
Hi Daniel, keeping the leading parenthesis in |
I'm not sure I follow; "use syntax that works on pre-POSIX shells" is different from "keep the existing syntax as-is". |
Oh yes, you're right. |
I'm still fine with adding So, all in all, it doesn't seem worthwhile. I've tried options of the form "keep the user's syntax" before, such as #658, and it's not worth it. |
I did not mean to hit "close and comment" :) |
OK, no problem, I understand your point. I was essentially suggesting it because some other widely-used reformatters do not change the syntax but only improve readability (like |
The empty line is also wrongly kept in statements (not only after
is reformatted:
|
Another very similar case below minimized from #950; I think they are all the same bug:
|
If we remove any newlines when printing, don't insert others later on in the source. While here, improve how we keep track of p.line throughout the printer. Fixes #779.
If we remove any newlines when printing, don't insert others later on in the source. While here, improve how we keep track of p.line throughout the printer. Fixes #779.
Before:
After
shfmt -p -s
:POSIX allows
case
items to start with a parenthesis, and I prefer it, because it makescase
look more understandable, imo. I would like an option to either add them or at least not remove them.(Also, I've noticed that
shfmt
seems to add an empty line aftercase … in
, which looks like a bug.)The text was updated successfully, but these errors were encountered: