Sha256: e34e092fc9c0667c0f1470eec0824a27c8499d178e78b21e7e8047cf7a286248

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 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.'

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

        def on_block(node)
          empty_hook?(node) do |hook|
            add_offense(hook) do |corrector|
              range = range_with_surrounding_space(range: node.loc.expression)
              corrector.remove(range)
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-2.2.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.1.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.0.1 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.0.0 lib/rubocop/cop/rspec/empty_hook.rb