lib/rubocop/cop/style/dig_chain.rb in rubocop-1.69.0 vs lib/rubocop/cop/style/dig_chain.rb in rubocop-1.69.1

- old
+ new

@@ -22,11 +22,10 @@ # # good - `dig`s cannot be combined # x.dig(:foo).bar.dig(:baz) # class DigChain < Base extend AutoCorrector - include RangeHelp include CommentsHelp include DigHelp MSG = 'Use `%<replacement>s` instead of chaining.' RESTRICT_ON_SEND = %i[dig].freeze @@ -47,20 +46,20 @@ private # Walk up the method chain while the receiver is `dig` with arguments. def inspect_chain(node) arguments = node.arguments.dup - end_pos = node.source_range.end_pos + end_range = node.source_range.end - while dig?((node = node.receiver)) - begin_pos = node.loc.dot ? node.loc.dot.begin_pos + 1 : 0 + while dig?(node = node.receiver) + begin_range = node.loc.selector arguments.unshift(*node.arguments) ignore_node(node) end - return unless begin_pos + return unless begin_range - [range_between(begin_pos, end_pos), arguments] + [begin_range.join(end_range), arguments] end def invalid_arguments?(arguments) # If any of the arguments are arguments forwarding (`...`), it can only be the # first argument, or else the resulting code will have a syntax error.