diff --git a/lib/rubocop/cop/style/single_line_methods.rb b/lib/rubocop/cop/style/single_line_methods.rb index 4764db44cde..41bde1fbe92 100644 --- a/lib/rubocop/cop/style/single_line_methods.rb +++ b/lib/rubocop/cop/style/single_line_methods.rb @@ -115,7 +115,7 @@ def move_comment(node, corrector) end def method_body_source(method_body) - if method_body.arguments.empty? || method_body.parenthesized? + if !method_body.send_type? || method_body.arguments.empty? || method_body.parenthesized? method_body.source else arguments_source = method_body.arguments.map(&:source).join(', ') diff --git a/spec/rubocop/cop/style/single_line_methods_spec.rb b/spec/rubocop/cop/style/single_line_methods_spec.rb index 0ad0502cdf4..2802bb8f6d8 100644 --- a/spec/rubocop/cop/style/single_line_methods_spec.rb +++ b/spec/rubocop/cop/style/single_line_methods_spec.rb @@ -187,6 +187,12 @@ def some_method(a, b, c) = body RUBY end + it 'corrects to an endless method definition when method body is a literal' do + expect_correction(<<~RUBY.strip, source: 'def some_method; 42 end') + def some_method() = 42 + RUBY + end + it 'corrects to an endless method definition when single line method call with parentheses' do expect_correction(<<~RUBY.strip, source: 'def index() head(:ok) end') def index() = head(:ok)