Class: RuboCop::Cop::Style::HashTransformValues
- Extended by:
- AutoCorrector, TargetRubyVersion
- Includes:
- HashTransformMethod
- Defined in:
- lib/rubocop/cop/style/hash_transform_values.rb
Overview
Looks for uses of ‘_.each_with_object({}) …`, `_.map ….to_h`, and `Hash[_.map …]` that are actually just transforming the values of a hash, and tries to use a simpler & faster call to `transform_values` instead.
Constant Summary
Constants included from HashTransformMethod
HashTransformMethod::RESTRICT_ON_SEND
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #on_bad_each_with_object(node) ⇒ Object
- #on_bad_hash_brackets_map(node) ⇒ Object
- #on_bad_map_to_h(node) ⇒ Object
- #on_bad_to_h(node) ⇒ Object
Methods included from AutoCorrector
Methods included from TargetRubyVersion
maximum_target_ruby_version, minimum_target_ruby_version, required_maximum_ruby_version, required_minimum_ruby_version, support_target_ruby_version?
Methods included from HashTransformMethod
#array_receiver?, #on_block, #on_csend, #on_send
Methods inherited from Base
#active_support_extensions_enabled?, #add_global_offense, #add_offense, #always_autocorrect?, autocorrect_incompatible_with, badge, #begin_investigation, #callbacks_needed, callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #contextual_autocorrect?, #cop_config, cop_name, #cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, #inspect, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_new_investigation, #on_other_file, #parse, #parser_engine, #ready, #relevant_file?, requires_gem, #string_literals_frozen_by_default?, support_autocorrect?, support_multiple_source?, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
This class inherits a constructor from RuboCop::Cop::Base
Instance Method Details
#on_bad_each_with_object(node) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubocop/cop/style/hash_transform_values.rb', line 34 def_node_matcher :on_bad_each_with_object, <<~PATTERN (block (call !#array_receiver? :each_with_object (hash)) (args (mlhs (arg _key) (arg $_)) (arg _memo)) (call (lvar _memo) :[]= $(lvar _key) $!`_memo)) PATTERN |
#on_bad_hash_brackets_map(node) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/style/hash_transform_values.rb', line 46 def_node_matcher :on_bad_hash_brackets_map, <<~PATTERN (send (const _ :Hash) :[] (block (call !#array_receiver? {:map :collect}) (args (arg _key) (arg $_)) (array $(lvar _key) $_))) PATTERN |
#on_bad_map_to_h(node) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubocop/cop/style/hash_transform_values.rb', line 59 def_node_matcher :on_bad_map_to_h, <<~PATTERN (call (block (call !#array_receiver? {:map :collect}) (args (arg _key) (arg $_)) (array $(lvar _key) $_)) :to_h) PATTERN |
#on_bad_to_h(node) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/rubocop/cop/style/hash_transform_values.rb', line 71 def_node_matcher :on_bad_to_h, <<~PATTERN (block (call !#array_receiver? :to_h) (args (arg _key) (arg $_)) (array $(lvar _key) $_)) PATTERN |