Skip to content

Fix crash in Layout/EmptyLinesAroundMethodBody for endless methods #13796

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

Merged

Conversation

dvandersluis
Copy link
Member

Fixes crash in Layout/EmptyLinesAroundMethodBody when encountering an endless method on multiple lines.

# test.rb
def foo(bar,
  baz) = quux
$ rubocop -d test.rb

An error occurred while Layout/EmptyLinesAroundMethodBody cop was inspecting /Users/daniel/src/rubocop/test.rb:1:0.
  The range 27...28 is outside the bounds of the source
/Users/daniel/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/parser-3.3.6.0/lib/parser/source/tree_rewriter.rb:406:in 'Parser::Source::TreeRewriter#check_range_validity'
/Users/daniel/src/rubocop/lib/rubocop/cop/corrector.rb:120:in 'RuboCop::Cop::Corrector#check_range_validity'
/Users/daniel/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/parser-3.3.6.0/lib/parser/source/tree_rewriter.rb:398:in 'Parser::Source::TreeRewriter#combine'
/Users/daniel/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/parser-3.3.6.0/lib/parser/source/tree_rewriter.rb:194:in 'Parser::Source::TreeRewriter#replace'
/Users/daniel/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/parser-3.3.6.0/lib/parser/source/tree_rewriter.rb:218:in 'Parser::Source::TreeRewriter#remove'
/Users/daniel/src/rubocop/lib/rubocop/cop/correctors/empty_line_corrector.rb:13:in 'RuboCop::Cop::EmptyLineCorrector.correct'
/Users/daniel/src/rubocop/lib/rubocop/cop/mixin/empty_lines_around_body.rb:104:in 'block in RuboCop::Cop::Layout::EmptyLinesAroundBody#check_line'
/Users/daniel/src/rubocop/lib/rubocop/cop/base.rb:426:in 'RuboCop::Cop::Base#correct'
/Users/daniel/src/rubocop/lib/rubocop/cop/base.rb:210:in 'RuboCop::Cop::Base#add_offense'
/Users/daniel/src/rubocop/lib/rubocop/cop/mixin/empty_lines_around_body.rb:103:in 'RuboCop::Cop::Layout::EmptyLinesAroundBody#check_line'
/Users/daniel/src/rubocop/lib/rubocop/cop/mixin/empty_lines_around_body.rb:92:in 'RuboCop::Cop::Layout::EmptyLinesAroundBody#check_source'
/Users/daniel/src/rubocop/lib/rubocop/cop/mixin/empty_lines_around_body.rb:82:in 'RuboCop::Cop::Layout::EmptyLinesAroundBody#check_beginning'
/Users/daniel/src/rubocop/lib/rubocop/cop/mixin/empty_lines_around_body.rb:76:in 'RuboCop::Cop::Layout::EmptyLinesAroundBody#check_both'
/Users/daniel/src/rubocop/lib/rubocop/cop/mixin/empty_lines_around_body.rb:39:in 'RuboCop::Cop::Layout::EmptyLinesAroundBody#check'
/Users/daniel/src/rubocop/lib/rubocop/cop/layout/empty_lines_around_method_body.rb:32:in 'RuboCop::Cop::Layout::EmptyLinesAroundMethodBody#on_def'

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.

@koic koic merged commit b1b9415 into rubocop:master Feb 6, 2025
23 checks passed
@koic
Copy link
Member

koic commented Feb 6, 2025

This looks good. Thanks!

@dvandersluis dvandersluis deleted the fix/empty-lines-around-method-body-endless branch February 6, 2025 05:41
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