Skip to content
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

Merged
merged 2 commits into from
Dec 23, 2020

Conversation

dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented Dec 22, 2020

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:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@dvandersluis
Copy link
Member Author

documentation_syntax_check was failing on the ruby 3.0 syntax in examples, so I've updated the base parser it uses to be Parser::Ruby30 instead of Parser::Ruby27.

@@ -32,6 +35,7 @@ class SingleLineMethods < Base

def on_def(node)
return unless node.single_line?
return if node.endless?
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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. 😆

@bbatsov bbatsov merged commit 4184846 into rubocop:master Dec 23, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 23, 2020

I'll merge this, even though it seems something's wrong with the single_line? method.

@dvandersluis dvandersluis deleted the fix/single-line-methods branch January 18, 2021 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants