Class: RuboCop::Cop::Twirp::DeprecatedArguments
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Twirp::DeprecatedArguments
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/twirp/deprecated_arguments.rb
Overview
Checks that Twirp::ClientResp uses keyword arguments instead of positional arguments.
Constant Summary collapse
- RESTRICT_ON_SEND =
[:new].freeze
- POSITIONAL_ARGS =
[:data, :error].freeze
- MSG =
"Positional args are deprecated, use keyword args: " \ "`%<class_name>s.%<method_name>s(%<kwargs>s)`"
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubocop/cop/twirp/deprecated_arguments.rb', line 29 def on_send(node) return unless pos_args?(node) kwargs = POSITIONAL_ARGS.map.with_index do |arg, index| "#{arg}: #{node.arguments[index].source}" end.join(", ") = format( MSG, class_name: node.receiver.source, kwargs: kwargs, method_name: node.method_name, ) offense_range = range_between( node.arguments.first.source_range.begin_pos, node.arguments.last.source_range.end_pos ) add_offense( offense_range, message: , ) do |corrector| corrector.replace(offense_range, kwargs) end end |