Skip to content

Commit

Permalink
[Fix rubocop#12372] Fix a false negative for Lint/Debugger
Browse files Browse the repository at this point in the history
Fixes rubocop#12372.

This PR fixes a false negative for `Lint/Debugger`
when used within method arguments a `begin`...`end` block.
  • Loading branch information
koic committed Nov 9, 2023
1 parent f53f5a0 commit 9764366
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_a_false_negative_for_lint_debugger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12372](https://github.com/rubocop/rubocop/issues/12372): Fix a false negative for `Lint/Debugger` when used within method arguments a `begin`...`end` block. ([@koic][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/lint/debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module Lint
# end
class Debugger < Base
MSG = 'Remove debugger entry point `%<source>s`.'
BLOCK_TYPES = %i[block numblock kwbegin].freeze

def on_send(node)
return if !debugger_method?(node) || assumed_usage_context?(node)
Expand Down Expand Up @@ -98,7 +99,7 @@ def assumed_usage_context?(node)
return true if assumed_argument?(node)

node.each_ancestor.none? do |ancestor|
ancestor.block_type? || ancestor.numblock_type? || ancestor.lambda_or_proc?
BLOCK_TYPES.include?(ancestor.type) || ancestor.lambda_or_proc?
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/lint/debugger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@
RUBY
end

it 'registers an offense for a `custom_debugger` call when used within method arguments a `begin`...`end` block' do
expect_offense(<<~RUBY)
do_something(
begin
custom_debugger
^^^^^^^^^^^^^^^ Remove debugger entry point `custom_debugger`.
end
)
RUBY
end

context 'nested custom configurations' do
let(:cop_config) { { 'DebuggerMethods' => { 'Custom' => %w[custom_debugger] } } }

Expand Down

0 comments on commit 9764366

Please sign in to comment.