Skip to content

Commit

Permalink
Merge pull request #9708 from dvandersluis/issue/9707
Browse files Browse the repository at this point in the history
[Fix #9707] Fix false positive for `Style/MethodCallWithArgsParentheses` with `omit_parentheses` style on an endless `defs` node
  • Loading branch information
koic committed Apr 18, 2021
2 parents 7d12a8d + f75aea9 commit 00dc817
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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

0 comments on commit 00dc817

Please sign in to comment.