diff --git a/CHANGELOG.md b/CHANGELOG.md index d2ec7f58f60..f7f64c0b986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/config/default.yml b/config/default.yml index cb362fcd2e8..6c6e77c158f 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1799,6 +1799,7 @@ Lint/SafeNavigationChain: - presence - try - try! + - in? Lint/SafeNavigationConsistency: Description: >- diff --git a/docs/modules/ROOT/pages/cops_lint.adoc b/docs/modules/ROOT/pages/cops_lint.adoc index c1ac48c9589..04d9ea06a3b 100644 --- a/docs/modules/ROOT/pages/cops_lint.adoc +++ b/docs/modules/ROOT/pages/cops_lint.adoc @@ -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 |=== diff --git a/spec/rubocop/cop/lint/safe_navigation_chain_spec.rb b/spec/rubocop/cop/lint/safe_navigation_chain_spec.rb index 7c9e1f0d475..a777ddeb2bc 100644 --- a/spec/rubocop/cop/lint/safe_navigation_chain_spec.rb +++ b/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) @@ -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