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

#on_block(node) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 16

def on_block(node)
  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) do |*match|
    handle_possible_offense(node, match, 'to_h {...}')
  end
end

#on_csend(node) ⇒ Object



37
38
39
40
41
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 37

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

#on_send(node) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 28

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) do |*match|
    handle_possible_offense(node, match, 'map {...}.to_h')
  end
end