Skip to content

Commit

Permalink
Merge pull request #8375 from koic/fix_infinite_loop_error_for_empty_…
Browse files Browse the repository at this point in the history
…method

Fix an infinite loop error for `Style/EmptyMethod`
  • Loading branch information
koic committed Jul 20, 2020
2 parents 8d051da + 9cf9ceb commit 3874a10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@
* [#8299](https://github.com/rubocop-hq/rubocop/issues/8299): Fix an incorrect auto-correct for `Style/RedundantCondition` when using `raise`, `rescue`, or `and` without argument parentheses in `else`. ([@koic][])
* [#8335](https://github.com/rubocop-hq/rubocop/issues/8335): Fix incorrect character class detection for nested or POSIX bracket character classes in `Style/RedundantRegexpEscape`. ([@owst][])
* [#8347](https://github.com/rubocop-hq/rubocop/issues/8347): Fix an incorrect auto-correct for `EnforcedStyle: hash_rockets` of `Style/HashSyntax` with `Layout/HashAlignment`. ([@koic][])
* [#8375](https://github.com/rubocop-hq/rubocop/pull/8375): Fix an infinite loop error for `Style/EmptyMethod`. ([@koic][])

### Changes

Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/style/empty_method.rb
Expand Up @@ -73,13 +73,13 @@ def correct_style?(node)
end

def corrected(node)
if node.arguments?
arguments = node.arguments.source
extra_space = ' ' unless parentheses?(node.arguments)
end
scope = node.receiver ? "#{node.receiver.source}." : ''
arguments = if node.arguments?
args = node.arguments.map(&:source).join(', ')

signature = [scope, node.method_name, extra_space, arguments].join
parentheses?(node.arguments) ? "(#{args})" : " #{args}"
end
signature = [scope, node.method_name, arguments].join

["def #{signature}", 'end'].join(joint(node))
end
Expand Down
5 changes: 5 additions & 0 deletions spec/rubocop/cop/style/empty_method_spec.rb
Expand Up @@ -61,6 +61,11 @@
'end'].join("\n"),
'def foo; end'

it_behaves_like 'code with offense',
['def foo(arg',
'); end'].join("\n"),
'def foo(arg); end'

it_behaves_like 'code without offense',
'def foo; end'
end
Expand Down

0 comments on commit 3874a10

Please sign in to comment.