Skip to content

Commit

Permalink
Make Lint/Debugger aware of debug.rb
Browse files Browse the repository at this point in the history
This PR makes `Lint/Debugger` aware of debug.rb.
https://github.com/ruby/debug

debug.rb has `binding.break` and `binding.b` commands (`b` for short).
  • Loading branch information
koic committed Aug 25, 2021
1 parent 7b0358f commit d94451e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/new_make_lint_debugger_aware_of_debug_rb.md
@@ -0,0 +1 @@
* [#10040](https://github.com/rubocop/rubocop/pull/10040): Make `Lint/Debugger` aware of debug.rb. ([@koic][])
5 changes: 5 additions & 0 deletions config/default.yml
Expand Up @@ -1519,6 +1519,11 @@ Lint/Debugger:
Capybara:
- save_and_open_page
- save_and_open_screenshot
debug.rb:
- binding.b
- binding.break
- Kernel.binding.b
- Kernel.binding.break
Pry:
- binding.pry
- binding.remote_pry
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/lint/debugger.rb
Expand Up @@ -7,8 +7,8 @@ module Lint
# not be kept for production code.
#
# The cop can be configured using `DebuggerMethods`. By default, a number of gems
# debug entrypoints are configured (`Kernel`, `Byebug`, `Capybara`, `Pry`, `Rails`,
# `RubyJard` and `WebConsole`). Additional methods can be added.
# debug entrypoints are configured (`Kernel`, `Byebug`, `Capybara`, `debug.rb`,
# `Pry`, `Rails`, `RubyJard`, and `WebConsole`). Additional methods can be added.
#
# Specific default groups can be disabled if necessary:
#
Expand Down
30 changes: 30 additions & 0 deletions spec/rubocop/cop/lint/debugger_spec.rb
Expand Up @@ -114,6 +114,36 @@
end
end

context 'debug.rb' do
it 'registers an offense for a `b` binding call' do
expect_offense(<<~RUBY)
binding.b
^^^^^^^^^ Remove debugger entry point `binding.b`.
RUBY
end

it 'registers an offense for a `break` binding call' do
expect_offense(<<~RUBY)
binding.break
^^^^^^^^^^^^^ Remove debugger entry point `binding.break`.
RUBY
end

it 'registers an offense for a `binding.b` with `Kernel` call' do
expect_offense(<<~RUBY)
Kernel.binding.b
^^^^^^^^^^^^^^^^ Remove debugger entry point `Kernel.binding.b`.
RUBY
end

it 'registers an offense for a `binding.break` with `Kernel` call' do
expect_offense(<<~RUBY)
Kernel.binding.break
^^^^^^^^^^^^^^^^^^^^ Remove debugger entry point `Kernel.binding.break`.
RUBY
end
end

context 'pry' do
it 'registers an offense for a pry binding call' do
expect_offense(<<~RUBY)
Expand Down

0 comments on commit d94451e

Please sign in to comment.