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 #9707] Fix false positive for Style/MethodCallWithArgsParentheses with omit_parentheses style on an endless defs node #9708

Merged
merged 1 commit into from Apr 18, 2021
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/fix_fix_false_positive_for.md
@@ -0,0 +1 @@
* [#9707](https://github.com/rubocop/rubocop/issues/9707): Fix false positive for `Style/MethodCallWithArgsParentheses` with `omit_parentheses` style on an endless `defs` node. ([@dvandersluis][])
Expand Up @@ -42,7 +42,7 @@ def offense_range(node)

def inside_endless_method_def?(node)
# parens are required around arguments inside an endless method
node.each_ancestor(:def).any?(&:endless?) && node.arguments.any?
node.each_ancestor(:def, :defs).any?(&:endless?) && node.arguments.any?
end

def syntax_like_method_call?(node)
Expand Down
29 changes: 29 additions & 0 deletions spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb
Expand Up @@ -23,19 +23,48 @@ def x() = foo()
def x() = foo#{trailing_whitespace}
RUBY
end

it 'registers an offense for `defs` when there are parens' do
expect_offense(<<~RUBY)
def self.x() = foo()
^^ Omit parentheses for method calls with arguments.
RUBY

expect_correction(<<~RUBY)
def self.x() = foo#{trailing_whitespace}
RUBY
end
else
it 'does not register an offense when there are parens' do
expect_no_offenses(<<~RUBY)
def x() = foo()
RUBY
end

it 'does not register an offense for `defs` when there are parens' do
expect_no_offenses(<<~RUBY)
def self.x() = foo()
RUBY
end
end

it 'does not register an offense when there are no parens' do
expect_no_offenses(<<~RUBY)
def x() = foo
RUBY
end

it 'does not register an offense when there are arguments' do
expect_no_offenses(<<~RUBY)
def x() = foo(y)
RUBY
end

it 'does not register an offense for `defs` when there are arguments' do
expect_no_offenses(<<~RUBY)
def self.x() = foo(y)
RUBY
end
end
end
end
Expand Down