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
- #on_block(node) ⇒ Object (also: #on_numblock)
- #on_csend(node) ⇒ Object
- #on_send(node) ⇒ Object
Instance Method Details
#on_block(node) ⇒ Object Also known as: on_numblock
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) 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
33 34 35 36 37 |
# File 'lib/rubocop/cop/mixin/index_method.rb', line 33 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
23 24 25 26 27 28 29 30 31 |
# File 'lib/rubocop/cop/mixin/index_method.rb', line 23 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 |