-
-
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
Add support for endless methods to Style/SingleLineMethods
.
#9276
Conversation
|
@@ -32,6 +35,7 @@ class SingleLineMethods < Base | |||
|
|||
def on_def(node) | |||
return unless node.single_line? | |||
return if node.endless? |
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.
Shouldn't #single_line?
return true on this case as well?
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.
My bad. I just realized the cop treats specially empty definitions and now endless definition. I guess we need to improve its description a bit.
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.
@bbatsov just realized my PR description was a bit wonky so I've fixed that.
single_line?
likely returns true for an endless method (since they generally should be on a single line I believe), however, a single line method as far as this cop is concerned is one that is of the form def x; something end
, and the correction code was failing because node.loc.end
doesn't exist for an endless method.
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.
Yeah, I figured this out with a bit of a delay. 😆
I'll merge this, even though it seems something's wrong with the |
Style/SingleLineMethods
would raise an error when encountering a Ruby 3.0 endless method. I updated it to ignore endless methods (Style/EndlessMethods
in #9281 handles them instead).Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.