lib/rubocop/cop/ezcater/style_dig.rb in ezcater_rubocop-0.49.2 vs lib/rubocop/cop/ezcater/style_dig.rb in ezcater_rubocop-0.49.3
- old
+ new
@@ -22,11 +22,11 @@
minimum_target_ruby_version 2.3
MSG = "Use `dig` for nested access.".freeze
def_node_matcher :nested_access_match, <<-PATTERN
- (send (send (send _receiver !:[]) :[] _) :[] _)
+ (send (send (send _receiver !:[]) :[] !{irange erange}) :[] !{irange erange})
PATTERN
def on_send(node)
return unless nested_access_match(node) && !assignment?(node)
match_node = node
@@ -57,10 +57,14 @@
def assignment?(node)
node.parent&.assignment? && (node.parent.children.first == node)
end
def access_node?(node)
- node && node.send_type? && node.method_name == :[]
+ node && node.send_type? && node.method_name == :[] && !range?(node.method_args.first)
+ end
+
+ def range?(node)
+ node.irange_type? || node.erange_type?
end
end
end
end
end