Sha256: 271af248fabb0a96d8158f48f3544e262911964517c29dd2ab999f96ced25ee5

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

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?
          return if hash.children.any?(&:kwsplat_type?)

          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

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/empty_metadata.rb