-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Format: correctly indent block of indented method chain #5195
Format: correctly indent block of indented method chain #5195
Conversation
I'm not sure what you mean by "correctly". I think this is entirely invalid and looks atrocious.
Disallowing such chaining would probably be best for readability. Also here's a more widely accepted perception of "correct": |
I think this is much more readable. Just look at the reformatted code in Obviously such pieces should be formatted differently to be really good, but this is one step in the right direction. This would be much cleaner: expansion
.expanded_sources
.zip(expansion.expanded_macros)
.each_with_index do |(expanded_source, expanded_macro), j|
expanded_macro.each do |a_macro|
name = a_macro[:name]
# ...
end
io << "~> "
end I'm not sure what you mean with such chaining exactly, but I'm pretty confident that it shouldn't be generally disallowed. |
I actually think it's less readable. Before everything fit in 80 columns, now you have to scroll right to see what's going on. The current formatting is just fine. I know, it's a personal opinion, and that's why we will never agree on this. |
I also think this is worse. And I'm also glad crystals code base only changes formatting in one file, it means we don't have much code that's messy in this way. |
@asterite let me ask you a question then - which version would you prefer to write/see? expansion.expanded_sources.zip(expansion.expanded_macros)
.each_with_index do |(expanded_source, expanded_macro), j|
expanded_macro.each do |a_macro|
# ...
end
end or expansion.expanded_sources
.zip(expansion.expanded_macros)
.each_with_index do |(expanded_source, expanded_macro), j|
expanded_macro.each do |a_macro|
# ...
end
end What I'm heading at is placement of |
@@ -21,16 +21,16 @@ module Crystal | |||
io.puts | |||
expansion.expanded_sources.zip(expansion.expanded_macros) | |||
.each_with_index do |(expanded_source, expanded_macro), j| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should refactor this code in the future, but formatter is not wrong. I believe this indentation is correct and old indent is bad, as @straight-shoota and @Sija said.
Thinking about it again, I think @Sija's right. I think that expansion.expanded_sources.zip(expansion.expanded_macros)
.each_with_index do |(expanded_source, expanded_macro), j|
expanded_macro.each do |a_macro|
# ...
end
end should format to expansion.expanded_sources.zip(expansion.expanded_macros)
.each_with_index do |(expanded_source, expanded_macro), j|
expanded_macro.each do |a_macro|
# ...
end
end personally (4 spaces to indent a method chain broken onto multiple lines). I'd then be encouraged to do this, which I believe to be my favourite formatting: expansion.expanded_sources
.zip(expansion.expanded_macros)
.each_with_index do |(expanded_source, expanded_macro), j|
expanded_macro.each do |a_macro|
# ...
end
end |
I totally agree with @RX14's idea. Dot based alignment is painful. (and why align to last dot on previous line?) |
@RX14 I'm totally fine with 4 spaces indentation for method chained dot-lines. Though I'm not sure if this needs to be enforced by the formatter. |
@asterite Why does the formatter align method chain with the last dot on previous line? So, why the formatter keeps this: foo.bar.baz
.quz This behavior makes too deep indentation and I think it is wrong. If the formatter aligns method chain with first dot, this PR fix does not lose readability in many case. |
By now I think the formatter should always use 2 spaces to indent. |
@asterite I agree normally, but I think that's wrong in the case of multi-line statements. Adding more indent makes it clear that it's a continuation of the previous statement, not just a normal control-flow indent. |
I implemented @RX14's idea at What do you think? |
Opened a new pull request #5234. |
Fixed #5193