Sha256: 61f0fb91a4ce058ee09c74c5088f01f1bb345a8363121a2aab08e4b2d57f9c7f

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Lint
      # This cop checks for calls to debugger or pry.
      class Debugger < Cop
        MSG = 'Remove debugger entry point `%s`.'

        # debugger call node
        #
        # (send nil :debugger)
        DEBUGGER_NODE = s(:send, nil, :debugger)

        # byebug call node
        #
        # (send nil :byebug)
        BYEBUG_NODE = s(:send, nil, :byebug)

        # binding.pry node
        #
        # (send
        #   (send nil :binding) :pry)
        PRY_NODE = s(:send, s(:send, nil, :binding), :pry)

        # binding.remote_pry node
        #
        # (send
        #   (send nil :binding) :remote_pry)
        REMOTE_PRY_NODE = s(:send, s(:send, nil, :binding), :remote_pry)

        # binding.pry_remote node
        #
        # (send
        #   (send nil :binding) :pry_remote)
        PRY_REMOTE_NODE = s(:send, s(:send, nil, :binding), :pry_remote)

        # save_and_open_page
        #
        # (send nil :save_and_open_page)
        CAPYBARA_SAVE_PAGE = s(:send, nil, :save_and_open_page)

        # save_and_open_screenshot
        #
        # (send nil :save_and_open_screenshot)
        CAPYBARA_SAVE_OPEN_SCREENSHOT = s(:send, nil, :save_and_open_screenshot)

        # save_screenshot
        #
        # (send nil :save_screenshot)
        CAPYBARA_SAVE_SCREENSHOT = s(:send, nil, :save_screenshot)

        DEBUGGER_NODES = [
          DEBUGGER_NODE,
          BYEBUG_NODE,
          PRY_NODE,
          REMOTE_PRY_NODE,
          PRY_REMOTE_NODE,
          CAPYBARA_SAVE_PAGE,
          CAPYBARA_SAVE_OPEN_SCREENSHOT,
          CAPYBARA_SAVE_SCREENSHOT
        ]

        def on_send(node)
          receiver, method_name, *_args = *node
          node_without_args = self.class.s(:send, receiver, method_name)
          return unless DEBUGGER_NODES.include? node_without_args
          add_offense(node,
                      :expression,
                      format(MSG, node.loc.expression.source))
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.34.2 lib/rubocop/cop/lint/debugger.rb
rubocop-0.34.1 lib/rubocop/cop/lint/debugger.rb
rubocop-0.34.0 lib/rubocop/cop/lint/debugger.rb
rubocop-0.33.0 lib/rubocop/cop/lint/debugger.rb
rubocop-0.32.1 lib/rubocop/cop/lint/debugger.rb