lib/rubocop/cop/salsify/style_dig.rb in salsify_rubocop-0.48.1 vs lib/rubocop/cop/salsify/style_dig.rb in salsify_rubocop-0.52.1
- old
+ new
@@ -1,6 +1,6 @@
-# encoding: utf-8
+# This may be added in the near future to rubocop, see https://github.com/bbatsov/rubocop/issues/5332
module RuboCop
module Cop
module Salsify
# Use `dig` for deeply nested access.
@@ -30,19 +30,19 @@
def on_send(node)
if nested_access_match(node) && !conditional_assignment?(node)
match_node = node
# walk to outermost access node
match_node = match_node.parent while access_node?(match_node.parent)
- add_offense(match_node, :expression, MSG)
+ add_offense(match_node)
end
end
def autocorrect(node)
access_node = node
- source_args = [access_node.method_args.first.source]
+ source_args = [access_node.first_argument.source]
while access_node?(access_node.children.first)
access_node = access_node.children.first
- source_args << access_node.method_args.first.source
+ source_args << access_node.first_argument.source
end
root_node = access_node.children.first
lambda do |corrector|
range = Parser::Source::Range.new(node.source_range.source_buffer,