-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
End alignment with chained assignments #338
Comments
Yep, that's a bug - I guess @edzhelyov will take a look at it soon. |
@edzhelyov If you're busy with the AST traversal changes I can take a look at this. Just let me know. |
@jonas054 I discussed with @bbatsov some time ago, that the block strategy used by most editors is to just align the I'd like if you check and tell me your opinion about this. |
Expecting the No edge case where that does not make sense came to my mind, yet. So I think that's probably the best solution for the cop. |
@edzhelyov Since our solution must cover the case where there is a line break after There are, by the way, other edge cases that we don't cover at the moment, for example a(b do
end) at least if you go by how emacs indents it.
And this is also an exception to the rule about alignment with the first position of the line where |
That case: a(b do
end) in my Vim the @jonas054 Feel free to fix this issue any way you find appropriate. I will experiment with the idea of indenting based on the start of the line later this week. |
@edzhelyov Okay, I'll do my solution, then we can compare it to yours. Just out of curiosity, how does your vim (settings) indent a parameter list without blocks? Is it: a_function(b,
c) |
@jonas054's alignment suggestion seems more reasonable to me. I guess vim's indentation logic is flawed in that particular scenario. |
@jonas054 Vim indents in the same way as you've suggested. It's the block alignment that is always with the beginning on the line where |
Do we get information from the parser about the line that a statement (rather than expression) begins on? It seems we want to put the Also, shall we collect the various cases we want to cover and the "correct" way to indent them? So far, I've seen: foo do
end
a = foo do
end
a = b = foo do
end
a =
foo do
end
bar(foo do
end) |
@lee-dohm I'm with you except for the last one. If we add another parameter to that example, I think it looks a bit weird: bar(foo do
end,
baz) so I say (again) that bar(foo do
end,
baz) is the way to go. And to answer your question, yes we can get all the position information we need from Parser, but it's not as simple as just asking for the statement. |
@jonas054 in my opinion
is the way to go. If you add another parameter on a separate line, the first one should be separated from the function call as well. The compact version would be:
Anyway, I think if there's a controversy about an edge case like this, rubocop should allow more than one way. It does not make sense to enforce a style only a fraction of people (and editors) agree on. The result would be the other fractions switching off the respective cop losing the benefits of the undisputed styles as well, which would make this great gem a little less useful overall. |
@cschramm We cannot support every possible scenario - the alignment code is pretty complex even now :-) Anyways, this particular issue is now fixed. |
Thanks! 😃 |
With
the EndAlignment cop expects end to be aligned with b, while in my opinion it should be a.
The text was updated successfully, but these errors were encountered: