Sha256: 70bbdb832588f4204214dd41e4c7ca59607db17709399f31a8ee4a8c7f52c8d5

Contents?: true

Size: 1.13 KB

Versions: 14

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      #  Checks for empty before and after hooks.
      #
      # @example
      #   # bad
      #   before {}
      #   after do; end
      #   before(:all) do
      #   end
      #   after(:all) { }
      #
      #   # good
      #   before { create_users }
      #   after do
      #     cleanup_users
      #   end
      #   before(:all) do
      #     create_feed
      #   end
      #   after(:all) { cleanup_feed }
      #
      class EmptyHook < Base
        extend AutoCorrector
        include RuboCop::Cop::RangeHelp

        MSG = 'Empty hook detected.'

        # @!method empty_hook?(node)
        def_node_matcher :empty_hook?, <<~PATTERN
          (block $#{send_pattern('#Hooks.all')} _ nil?)
        PATTERN

        def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
          empty_hook?(node) do |hook|
            add_offense(hook) do |corrector|
              corrector.remove(
                range_with_surrounding_space(node.loc.expression, side: :left)
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/empty_hook.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.18.1 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.18.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.17.1 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.17.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.16.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.15.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.14.2 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.14.1 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.14.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.13.2 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.13.1 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.13.0 lib/rubocop/cop/rspec/empty_hook.rb