Sha256: a037118fe7e550817576bea1b3b83f3a110296f77851b095c2a5acf4ffcca17d

Contents?: true

Size: 1.14 KB

Versions: 36

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for redundant uses of double splat hash braces.
      #
      # @example
      #
      #   # bad
      #   do_something(**{foo: bar, baz: qux})
      #
      #   # good
      #   do_something(foo: bar, baz: qux)
      #
      class RedundantDoubleSplatHashBraces < Base
        extend AutoCorrector

        MSG = 'Remove the redundant double splat and braces, use keyword arguments directly.'

        def on_hash(node)
          return if node.pairs.empty? || node.pairs.any?(&:hash_rocket?)
          return unless (parent = node.parent)
          return unless parent.kwsplat_type?

          add_offense(parent) do |corrector|
            corrector.remove(parent.loc.operator)
            corrector.remove(opening_brace(node))
            corrector.remove(closing_brace(node))
          end
        end

        private

        def opening_brace(node)
          node.loc.begin.join(node.children.first.source_range.begin)
        end

        def closing_brace(node)
          node.children.last.source_range.end.join(node.loc.end)
        end
      end
    end
  end
end

Version data entries

36 entries across 35 versions & 9 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.52.1/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.56.4 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.56.3 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.56.2 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
synctera_ruby_sdk-1.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
synctera_ruby_sdk-1.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
synctera_ruby_sdk-1.1.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
sampero-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.1/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.56.1 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
tursodb-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
synctera_ruby_sdk-1.0.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.56.0 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.55.1 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.55.0 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.54.2 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.54.1/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.52.1/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.54.1/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.54.1 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
rubocop-1.54.0 lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb