Sha256: 68ece9fb47d96c345e2f349711bd9c36cfe9967f2d288740d8e7aa7d8f40a712

Contents?: true

Size: 1.77 KB

Versions: 15

Compression:

Stored size: 1.77 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} ...)
           (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)
          target_ruby_version >= 2.4 && binding_irb_call?(node)
        end
      end
    end
  end
end

Version data entries

15 entries across 9 versions & 2 rubygems

Version Path
rubocop-0.78.0 lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/debugger.rb
rubocop-0.77.0 lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/debugger.rb
rubocop-0.76.0 lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/debugger.rb
rubocop-0.75.1 lib/rubocop/cop/lint/debugger.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/debugger.rb
rubocop-0.75.0 lib/rubocop/cop/lint/debugger.rb