-
-
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
ExtraSpacing reform #2035
Comments
I think 1, 3 and 4 look good. Number 2 I don't understand – would you mind explaining in a bit more detail, or perhaps give a second example? |
2 is based on code I found in
|
Seems to me things might spiral of control if we head down this path. But if there's strong demand for something like this to be supported, I can live with it. Frankly, I think most of the alignment techniques serve more to obscure the code, rather than make it more clear, but everyone has their own opinion regarding this. 1 & 2 look pretty absurd to me. |
I misunderstood 1 (hadn’t noticed that |
@bquorning My basic idea was that in order to bring the For example, in our own case rhs.type
when :if then on_if(rhs, base)
when :while, :until then on_while(rhs, base)
else return
end into case rhs.type
when :if then on_if(rhs, base)
when :while, :until then on_while(rhs, base)
else return
end We have a few of these kinds of constructs. So in my view, we either try to make the cop focus entirely on apparent mistakes and let it be enabled by default, or we leave things as they are. |
I like the idea of enabling this by default. Some of the supported spacings seem weird to be, but I can see why people would chose that alignment. My biggest annoyance with custom alignment is its inconsistencies. Most of the time that I come across it, it seems to inconsistent throughout the file or section of code. 1 seems odd to me because it feels only partially aligned. I would prefer it without the extra space. If someone wants the extra space though, I think it should be a = 1 if b == 2
aa = 10 unless bb == 20 |
@rrosenblum I agree. That does look better. But the point I'm trying to make is that @bbatsov I think that by having those broad rules right from the start (e.g., rule 1 talks about any token being aligned), we avoid the risk of spiralling out of control (having to add more and more logic down the road). |
I cannot think of a use case that falls outside of your 4 examples. That should make this cop safe enough to enable by default. |
That one way to look into it - the other is that it becomes harder to enforce a particular style. I might accidentally do something that looks like an alignment and the check won't report it. This would solve one issue, but introduce others. |
That's an important aspect. People who feel that enforcing a consistent style is important, more important than allowing custom alignment, should be able to configure the cop to maintain the current behavior of reporting all extra spacing. I don't think it's possible to implement a perfect check that finds all mistakes and still allows all kinds of reasonable alignment. What we can achieve is to give a choice between super strict and lenient. I think that's an improvement over today's implementation that's super strict and disabled by default. It's disabled in our own project, which means that the obvious mistakes (there are 16 of them that I've found) are still not fixed. That should motivate us to do something. |
Fair enough. You have my blessing for the reform. :-) |
Thanks! I'm off to Denmark for some summer holiday activities now, and will be back in a week. I'll cook up a PR at that time. |
No worries. Enjoy your vacation! |
@jonas054 Awesome, thanks. |
@jonas054 I could kiss you for this. 😘 😀 Now if we could just get a cop to enforce and autocorrect alignment of tokens on consecutive lines, I would be in heaven. foo ||= 'bar'
another_foo = 'another_bar' Enforce alignment of foo ||= 'bar'
another_foo = 'another_bar' I appreciate all the hard work you and @bbatsov do. |
@jfelchner Thanks for the kind words. I think it's doable, but it would have to be implemented in a separate cop. We would have to solve the problem of the new cop and Please open a new issue for the enforced alignment functionality. |
Based on @jacob-carlborg's question about detecting alignment in #1888, I have a suggestion for how we can change
Style/ExtraSpacing
so it can be enabled by default without generating a lot of false positives for common alignment idioms.We allow a token preceded by multiple spaces if either of these is true:
+=
and the=
is aligned with an=
on an adjacent lineAs is hinted in example 1, an enabled
ExtraSpacing
would also check space before modifier keywords, rendering #2027 unnecessary.The text was updated successfully, but these errors were encountered: