rubocop icon indicating copy to clipboard operation
rubocop copied to clipboard

Lint/RedundantSafeNavigation false claim

Open morgoth opened this issue 2 months ago • 0 comments

Having code something if context[:controller]&.respond_to?(:class)

It wrongly reports offense Lint/RedundantSafeNavigation: Redundant safe navigation detected, use . instead

Behavior differs:

> nil.respond_to? :class
=> true
> nil&.respond_to? :class
=> nil

RuboCop version

be rubocop -V
1.81.7 (using Parser 3.3.10.0, Prism 1.6.0, rubocop-ast 1.47.1, analyzing as Ruby 3.4, running on ruby 3.4.6) [x86_64-linux]
  - rubocop-performance 1.26.1
  - rubocop-rails 2.33.4
  - rubocop-minitest 0.38.2
  - rubocop-capybara 2.22.1

morgoth avatar Nov 04 '25 14:11 morgoth