Module: RuboCop::Cop::IndexMethod

Included in:
Rails::IndexBy, Rails::IndexWith
Defined in:
lib/rubocop/cop/mixin/index_method.rb

Overview

Common functionality for Rails/IndexBy and Rails/IndexWith

Defined Under Namespace

Classes: Autocorrection, Captures

Constant Summary collapse

RESTRICT_ON_SEND =

rubocop:disable Metrics/ModuleLength

%i[each_with_object to_h map collect []].freeze

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object

rubocop:todo InternalAffairs/NumblockHandler



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/cop/mixin/index_method.rb', line 9

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

#on_csend(node) ⇒ Object



31
32
33
34
35
# File 'lib/rubocop/cop/mixin/index_method.rb', line 31

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



21
22
23
24
25
26
27
28
29
# File 'lib/rubocop/cop/mixin/index_method.rb', line 21

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

  on_bad_hash_brackets_map(node) do |*match|
    handle_possible_offense(node, match, 'Hash[map { ... }]')
  end
end