Skip to content

Commit

Permalink
[Fix #8500] Add in? to AllowedMethods for `Lint/SafeNavigationChain…
Browse files Browse the repository at this point in the history
…` cop

Closes #8500
  • Loading branch information
tejasbubane authored and bbatsov committed Sep 8, 2020
1 parent 0d5d52b commit 636d26a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
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

0 comments on commit 636d26a

Please sign in to comment.