Sha256: 624f51092839e5123efa47af539b753f794260944b5d7d4ffef5846ed36a9e8a

Contents?: true

Size: 1.13 KB

Versions: 18

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 nil? #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.source_range, side: :left)
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/empty_hook.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/empty_hook.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/empty_hook.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/empty_hook.rb