-
Notifications
You must be signed in to change notification settings - Fork 59
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
Comments: Field comment moved outside declaration #134
Comments
I understand this is not expected in here, but the behaviour is consistent with moving the trailing comment to the line before. There are places, I've seen in the wild, where this is the desired behaviour. For example: apply(Module, Fun, % dynamic call
build_arguments(State)). Formatting this as: % dynamic call
apply(
Module,
Fun,
build_arguments(State)
). seems more correct than apply(
Module,
% dynamic call
Fun,
build_arguments(State)
). even if we did floating comments, the issue wouldn't be solved since: apply(
Module,
Fun, % dynamic call
build_arguments(State)
). would be equally incorrect. It seems it's impossible to differentiate. |
It's certainly impossible to know (for a machine) whether the comment pertains to the nearest item or to the item at the start of the line (or any inbetween). Personally, I'd prefer to punish people who use the latter style (so erl_prettypr always attaches to the nearest item). |
You can always punish nobody Sorry, @michalmuskala … I couldn't resist. 🙄 Jokes aside, that's exactly why we wrote |
It's not about preference, though. In both cases one format is correct and the other is incorrect, the choice only changes which case is correct. Additionally the formatting roundtrip though a different formatter wouldn't result in getting the same code back, e.g. original -> erlfmt -> rebar3_format default would produce something like: % callback module
-record(state, {callback,
pass = 0,
fail = 0,
skip = 0,
cancel = 0,
% substate
state
}). I'm not sure how the choice of formatter helps here. |
Oh, right! Sorry, I jumped over too quickly. |
Given the line is expanded while formatting anyway, would it not make sense to turn it into -record(state, {
% callback module
callback,
pass = 0,
fail = 0,
skip = 0,
cancel = 0,
% substate
state
}). |
It would make sense in this case, yes. It would unfortunately be worse than current formatting for other cases that I shown in #134 (comment) |
Just adding a data point. I was looking at @rvirding 's luerl and found that the style that richard referenced in this issue is quite popular there https://github.com/rvirding/luerl/pull/133/files?file-filters%5B%5D=.hrl#diff-526cd0f79036f27ed96d792ce69e68f8L24 |
Some more examples from other issues I've closed in favour of the discussion happening here: From #160 f(1,
2). % comment formatted today as: f(
1,
% comment
2
). Where the issue author would prefer % comment
f(
1,
2
). or f(
1,
2
). % comment From #165 [x % x
, y % y
]. formatted today as: % x
[
x,
% y
y
]. Where the issue author would prefer [
% x
x,
% y
y
]. |
After doing more analyses on comments, we have decided that adding support for trailing comments is a good idea #219 Doing it will require a lot of work, so no promises on when this will be delivered, but I believe we can consider this issue a duplicate, because if we support trailing comments, then this wouldn't have been an issue. I hope that makes sense. |
Original:
Formatted:
The text was updated successfully, but these errors were encountered: