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

[Fix #8500] Add in? to AllowedMethods for Lint/SafeNavigationChain cop #8662

Merged
merged 1 commit into from Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,7 @@
* [#8470](https://github.com/rubocop-hq/rubocop/issues/8470): Do not autocorrect `Style/StringConcatenation` when parts of the expression are too complex. ([@dvandersluis][])
* [#8561](https://github.com/rubocop-hq/rubocop/issues/8561): Fix `Lint/UselessMethodDefinition` to not register an offense when method definition includes optional arguments. ([@fatkodima][])
* [#8617](https://github.com/rubocop-hq/rubocop/issues/8617): Fix `Style/HashAsLastArrayItem` to not register an offense when all items in an array are hashes. ([@dvandersluis][])
* [#8500](https://github.com/rubocop-hq/rubocop/issues/8500): Add `in?` to AllowedMethods for `Lint/SafeNavigationChain` cop. ([@tejasbubane][])

## 0.90.0 (2020-09-01)

Expand Down
1 change: 1 addition & 0 deletions config/default.yml
Expand Up @@ -1799,6 +1799,7 @@ Lint/SafeNavigationChain:
- presence
- try
- try!
- in?

Lint/SafeNavigationConsistency:
Description: >-
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/cops_lint.adoc
Expand Up @@ -3193,7 +3193,7 @@ x&.foo || bar
| Name | Default value | Configurable values

| AllowedMethods
| `present?`, `blank?`, `presence`, `try`, `try!`
| `present?`, `blank?`, `presence`, `try`, `try!`, `in?`
| Array
|===

Expand Down
7 changes: 2 additions & 5 deletions spec/rubocop/cop/lint/safe_navigation_chain_spec.rb
@@ -1,10 +1,6 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Lint::SafeNavigationChain, :config do
let(:cop_config) do
{ 'AcceptedMethods' => %w[present? blank? try presence] }
end

shared_examples 'accepts' do |name, code|
it "accepts usages of #{name}" do
expect_no_offenses(code)
Expand All @@ -31,7 +27,8 @@
['safe navigation with `try` method', 'a&.b.try(:c)'],
['safe navigation with assignment method', 'x&.foo = bar'],
['safe navigation with self assignment method', 'x&.foo += bar'],
['safe navigation with `to_d` method', 'x&.foo.to_d']
['safe navigation with `to_d` method', 'x&.foo.to_d'],
['safe navigation with `in?` method', 'x&.foo.in?([:baz, :qux])']
].each do |name, code|
include_examples 'accepts', name, code
end
Expand Down