Class: RuboCop::Cop::Style::ArgumentsForwarding
- Extended by:
- AutoCorrector, TargetRubyVersion
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/style/arguments_forwarding.rb
Overview
In Ruby 2.7, arguments forwarding has been added.
This cop identifies places where ‘do_something(*args, &block)` can be replaced by `do_something(…)`.
In Ruby 3.2, anonymous args/kwargs forwarding has been added.
This cop also identifies places where ‘use_args(*args)`/`use_kwargs(**kwargs)` can be replaced by `use_args(*)`/`use_kwargs(**)`; if desired, this functionality can be disabled by setting UseAnonymousForwarding: false.
Defined Under Namespace
Classes: SendNodeClassifier
Constant Summary collapse
- FORWARDING_LVAR_TYPES =
%i[splat kwsplat block_pass].freeze
- ADDITIONAL_ARG_TYPES =
%i[lvar arg].freeze
- FORWARDING_MSG =
'Use shorthand syntax `...` for arguments forwarding.'
- ARGS_MSG =
'Use anonymous positional arguments forwarding (`*`).'
- KWARGS_MSG =
'Use anonymous keyword arguments forwarding (`**`).'
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #on_def(node) ⇒ Object (also: #on_defs)
Methods included from AutoCorrector
Methods included from TargetRubyVersion
minimum_target_ruby_version, required_minimum_ruby_version, support_target_ruby_version?
Methods inherited from Base
#active_support_extensions_enabled?, #add_global_offense, #add_offense, autocorrect_incompatible_with, badge, #begin_investigation, callbacks_needed, #callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #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, #ready, #relevant_file?, 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_def(node) ⇒ Object Also known as: on_defs
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rubocop/cop/style/arguments_forwarding.rb', line 89 def on_def(node) return unless node.body forwardable_args = extract_forwardable_args(node.arguments) send_classifications = classify_send_nodes( node, node.each_descendant(:send).to_a, non_splat_or_block_pass_lvar_references(node.body), forwardable_args ) return if send_classifications.empty? if only_forwards_all?(send_classifications) add_forward_all_offenses(node, send_classifications, forwardable_args) elsif target_ruby_version >= 3.2 add_post_ruby_32_offenses(node, send_classifications, forwardable_args) end end |