Skip to content

Commit

Permalink
Merge pull request rubocop#9705 from koic/fix_an_error_for_style_sing…
Browse files Browse the repository at this point in the history
…le_line_method

Fix an error for `Style/SingleLineMethods`
  • Loading branch information
koic committed Apr 17, 2021
2 parents f504a4e + 42e9d89 commit 7d12a8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/single_line_methods.rb
Expand Up @@ -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(', ')
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/style/single_line_methods_spec.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 7d12a8d

Please sign in to comment.