Skip to content

Commit 0699f73

Browse files
koicbbatsov
authored andcommitted
[Fix rubocop#11556] Fix a false positive for Lint/Debugger
Fixes rubocop#11556. This PR fixes a false positive for `Lint/Debugger` when `p` is an argument of method call. Basically, debugger methods are not used as a method argument without arguments.
1 parent 1cbf186 commit 0699f73

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#11556](https://github.com/rubocop/rubocop/issues/11556): Fix a false positive for `Lint/Debugger` when `p` is an argument of method call. ([@koic][])

lib/rubocop/cop/lint/debugger.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class Debugger < Base
7070
def on_send(node)
7171
return unless debugger_method?(node)
7272

73+
# Basically, debugger methods are not used as a method argument without arguments.
74+
return if node.arguments.empty? && node.each_ancestor(:send, :csend).any?
75+
7376
add_offense(node)
7477
end
7578

spec/rubocop/cop/lint/debugger_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,30 @@
110110
Foo.p
111111
RUBY
112112
end
113+
114+
it 'does not register an offense when `p` is an argument of method call' do
115+
expect_no_offenses(<<~RUBY)
116+
let(:p) { foo }
117+
118+
it { expect(do_something(p)).to eq bar }
119+
RUBY
120+
end
121+
122+
it 'does not register an offense when `p` is an argument of safe navigation method call' do
123+
expect_no_offenses(<<~RUBY)
124+
let(:p) { foo }
125+
126+
it { expect(obj&.do_something(p)).to eq bar }
127+
RUBY
128+
end
129+
130+
it 'does not register an offense when `p` is a keyword argument of method call' do
131+
expect_no_offenses(<<~RUBY)
132+
let(:p) { foo }
133+
134+
it { expect(do_something(k: p)).to eq bar }
135+
RUBY
136+
end
113137
end
114138

115139
context 'byebug' do

0 commit comments

Comments
 (0)