Module: RuboCop::Cop::HashTransformMethod

Extended by:
Macros
Included in:
Style::HashTransformKeys, Style::HashTransformValues
Defined in:
lib/rubocop/cop/mixin/hash_transform_method.rb

Overview

Common functionality for Style/HashTransformKeys and Style/HashTransformValues

Defined Under Namespace

Classes: Autocorrection, Captures

Constant Summary collapse

RESTRICT_ON_SEND =
i[[] to_h].freeze

Instance Method Summary collapse

Instance Method Details

#array_receiver?(node) ⇒ Object



87
88
89
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 87

def_node_matcher :array_receiver?, "{(array ...) (send _ :each_with_index) (send _ :with_index _ ?) (send _ :zip ...)}\n"

#on_block(node) ⇒ Object

rubocop:disable InternalAffairs/NumblockHandler



91
92
93
94
95
96
97
98
99
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 91

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
  on_bad_each_with_object(node) do |*match|
    handle_possible_offense(node, match, 'each_with_object')
  end

  return if target_ruby_version < 2.6

  on_bad_to_h(node) { |*match| handle_possible_offense(node, match, 'to_h {...}') }
end

#on_csend(node) ⇒ Object



108
109
110
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 108

def on_csend(node)
  on_bad_map_to_h(node) { |*match| handle_possible_offense(node, match, 'map {...}.to_h') }
end

#on_send(node) ⇒ Object



101
102
103
104
105
106
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 101

def on_send(node)
  on_bad_hash_brackets_map(node) do |*match|
    handle_possible_offense(node, match, 'Hash[_.map {...}]')
  end
  on_bad_map_to_h(node) { |*match| handle_possible_offense(node, match, 'map {...}.to_h') }
end
OSZAR »