KEMBAR78
Style/SafeNavigation cop gives incorrect results after #14424 · Issue #14441 · rubocop/rubocop · GitHub
Skip to content

Style/SafeNavigation cop gives incorrect results after #14424 #14441

@tmtm

Description

@tmtm

Expected behavior

This code should not be detected by the Style/SafeNavigation cop:

foo.rb:

true if hash[:foo] && hash[:bar].blank?

Actual behavior

Afer #14424

/tmp/foo.rb:1:9: C: [Correctable] Style/SafeNavigation: Use safe navigation (&.) instead of checking if an object exists before calling the method.
true if hash[:foo] && hash[:bar].blank?
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

% cat /tmp/foo.rb
true if hash[:foo] && hash[:bar].blank?

% git checkout 5535cd33a07683eb145ab9a0f6b98ec0c83a9e8e
% ./exe/rubocop /tmp/foo.rb
Inspecting 1 file
C

Offenses:

/tmp/foo.rb:1:9: C: [Correctable] Style/SafeNavigation: Use safe navigation (&.) instead of checking if an object exists before calling the method.
true if hash[:foo] && hash[:bar].blank?
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

% git checkout 5535cd33a07683eb145ab9a0f6b98ec0c83a9e8e^
% ./exe/rubocop /tmp/foo.rb                             
Inspecting 1 file
.

1 file inspected, no offenses detected

RuboCop version

% ./exe/rubocop -V
1.79.2 (using Parser 3.3.9.0, rubocop-ast 1.46.0, analyzing as Ruby 2.7, running on ruby 3.4.4) [arm64-darwin23]
  - rubocop-performance 1.25.0
  - rubocop-rake 0.7.1
  - rubocop-rspec 3.6.0

However, as shown above, I'm using commit 5535cd3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions