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

Fix an infinite loop error for Style/EmptyMethod #8375

Merged
merged 1 commit into from Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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