Sha256: c6148c7f0316de4c05a93df5fa264c343deac1e67a11c82266f73d1feff5f0f7

Contents?: true

Size: 1.75 KB

Versions: 14

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for calls to debugger or pry.
      #
      # @example
      #
      #   # bad (ok during development)
      #
      #   # using pry
      #   def some_method
      #     binding.pry
      #     do_something
      #   end
      #
      # @example
      #
      #   # bad (ok during development)
      #
      #   # using byebug
      #   def some_method
      #     byebug
      #     do_something
      #   end
      #
      # @example
      #
      #   # good
      #
      #   def some_method
      #     do_something
      #   end
      class Debugger < Cop
        MSG = 'Remove debugger entry point `%<source>s`.'

        def_node_matcher :kernel?, <<~PATTERN
          {
            (const nil? :Kernel)
            (const (cbase) :Kernel)
          }
        PATTERN

        def_node_matcher :debugger_call?, <<~PATTERN
          {(send {nil? #kernel?} {:debugger :byebug :remote_byebug} ...)
           (send (send {#kernel? nil?} :binding)
             {:pry :remote_pry :pry_remote :console} ...)
           (send (const {nil? (cbase)} :Pry) :rescue ...)
           (send nil? {:save_and_open_page
                      :save_and_open_screenshot
                      :save_screenshot} ...)}
        PATTERN

        def_node_matcher :binding_irb_call?, <<~PATTERN
          (send (send {#kernel? nil?} :binding) :irb ...)
        PATTERN

        def on_send(node)
          return unless debugger_call?(node) || binding_irb?(node)

          add_offense(node)
        end

        private

        def message(node)
          format(MSG, source: node.source)
        end

        def binding_irb?(node)
          binding_irb_call?(node)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
rubocop-0.88.0 lib/rubocop/cop/lint/debugger.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/lint/debugger.rb
rubocop-0.87.1 lib/rubocop/cop/lint/debugger.rb
rubocop-0.87.0 lib/rubocop/cop/lint/debugger.rb
rubocop-0.86.0 lib/rubocop/cop/lint/debugger.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/lint/debugger.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/lint/debugger.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/lint/debugger.rb
rubocop-0.85.1 lib/rubocop/cop/lint/debugger.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/lint/debugger.rb
rubocop-0.85.0 lib/rubocop/cop/lint/debugger.rb
rubocop-0.84.0 lib/rubocop/cop/lint/debugger.rb
rubocop-0.83.0 lib/rubocop/cop/lint/debugger.rb
rubocop-0.82.0 lib/rubocop/cop/lint/debugger.rb