Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Lint/RedundantSafeNavigation cop #8838

Merged
merged 1 commit into from Oct 4, 2020

Conversation

fatkodima
Copy link
Contributor

This cop checks for redundant safe navigation calls.

# bad
attrs&.respond_to?(:[])
foo&.dup&.inspect

# good
attrs.respond_to?(:[])
foo.dup.inspect

Closes #8668

@bbatsov bbatsov merged commit 0203a76 into rubocop:master Oct 4, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 4, 2020

Love it! Great work!

koic added a commit to rubocop/rubocop-minitest that referenced this pull request Oct 5, 2020
Follow rubocop/rubocop#8838.

This commit suppresses the following RuboCop's offense.

```console
% bundle exec rake
(snip)

Offenses:

test/assertion_helper.rb:79:12: W: Lint/RedundantSafeNavigation:
Redundant safe navigation detected.
    if file&.respond_to?(:write)
               ^^^^^^^^^^^^^^^^^^^^^

81 files inspected, 1 offense detected, 1 offense a
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a cop to detect safe navigation uses with respond_to?
2 participants