lib/rubocop/cop/lint/safe_navigation_chain.rb in rubocop-1.36.0 vs lib/rubocop/cop/lint/safe_navigation_chain.rb in rubocop-1.37.0
- old
+ new
@@ -29,10 +29,11 @@
extend TargetRubyVersion
minimum_target_ruby_version 2.3
MSG = 'Do not chain ordinary method call after safe navigation operator.'
+ PLUS_MINUS_METHODS = %i[+@ -@].freeze
# @!method bad_method?(node)
def_node_matcher :bad_method?, <<~PATTERN
{
(send $(csend ...) $_ ...)
@@ -40,11 +41,11 @@
}
PATTERN
def on_send(node)
bad_method?(node) do |safe_nav, method|
- return if nil_methods.include?(method)
+ return if nil_methods.include?(method) || PLUS_MINUS_METHODS.include?(node.method_name)
method_chain = method_chain(node)
location =
Parser::Source::Range.new(node.source_range.source_buffer,
safe_nav.source_range.end_pos,
@@ -69,10 +70,10 @@
method_name: send_node.method_name
)
else
offense_range.source.dup
end
- source.prepend('.') unless send_node.dot?
+ source.prepend('.') unless source.start_with?('.')
source.prepend('&')
end
# @param [RuboCop::Cop::Corrector] corrector
# @param [Parser::Source::Range] offense_range