Sha256: acdcd8fc6131ae05c9b5bef79f96ada90f00e71e2ab61b9a965d02edf6211de3

Contents?: true

Size: 988 Bytes

Versions: 26

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Avoid empty metadata hash.
      #
      # @example EnforcedStyle: symbol (default)
      #   # bad
      #   describe 'Something', {}
      #
      #   # good
      #   describe 'Something'
      class EmptyMetadata < Base
        extend AutoCorrector

        include Metadata
        include RangeHelp

        MSG = 'Avoid empty metadata hash.'

        def on_metadata(_symbols, hash)
          return unless hash&.pairs&.empty?

          add_offense(hash) do |corrector|
            remove_empty_metadata(corrector, hash)
          end
        end

        private

        def remove_empty_metadata(corrector, node)
          corrector.remove(
            range_with_surrounding_comma(
              range_with_surrounding_space(
                node.source_range,
                side: :left
              ),
              :left
            )
          )
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 5 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_metadata.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/empty_metadata.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/empty_metadata.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/empty_metadata.rb
rubocop-rspec-2.27.0 lib/rubocop/cop/rspec/empty_metadata.rb