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
Layout/DotPosition
seems to get confused by heredocs
#10110
Comments
Seems to also have a problem with comments: original: my_method.
something.
# comment
somethingelse expected:
actual:
ruby version:
note that I did test actual behavior, and all of the above produce the same behavior. is it something with older rubies that leading dot position wouldn't work with comments between the method calls? |
The cop actually purposely does not register an offense on dots when there is a blank line or comment line between methods in the chain in order to not break things (added in #2354): rubocop/lib/rubocop/cop/layout/dot_position.rb Lines 79 to 83 in a20493d
This is causing the bug with heredocs as well (because the heredoc adds extra lines between the dot and the receiver); however, I think that's a bug that I'm looking at fixing now. |
[Fix #10110] Update `Layout/DotPosition` to be able to handle heredocs
Comments between fluent method calls is allowed in Ruby 2.7: https://blog.saeloun.com/2020/01/20/ruby-2-7-allows-placing-of-comment-lines-between-fluent-dots.html. I'd think the cop's behavior should be dependent on the TargetRubyVersion parameter. Thanks for the quick response though! |
Yes that is indeed true, and thanks for the reference because I was looking for it myself but misremembered that it was done in ruby 3.0 rather than 2.7. |
I have some chained method calls that the arguments are heredocs. Layout/DotPosition doesn't seem to know that it needs to move the dot.
Given:
and running
rubocop -a -- test.rb
Expected behavior
Actual behavior
RuboCop version
The text was updated successfully, but these errors were encountered: