Skip to content

Commit

Permalink
[Fix #8704] Fix an error for Lint/AmbiguousOperator
Browse files Browse the repository at this point in the history
Fixes #8704.

This PR fixes an error for `Lint/AmbiguousOperator`
when using safe navigation operator with a unary operator.
  • Loading branch information
koic authored and bbatsov committed Sep 12, 2020
1 parent 3686984 commit 134068f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -30,6 +30,7 @@
* [#8683](https://github.com/rubocop-hq/rubocop/issues/8683): Make naming cops work with non-ascii characters. ([@tejasbubane][])
* [#8626](https://github.com/rubocop-hq/rubocop/issues/8626): Fix false negatives for `Lint/UselessMethodDefinition`. ([@marcandre][])
* [#8698](https://github.com/rubocop-hq/rubocop/pull/8698): Fix cache to avoid encoding exception. ([@marcandre][])
* [#8704](https://github.com/rubocop-hq/rubocop/issues/8704): Fix an error for `Lint/AmbiguousOperator` when using safe navigation operator with a unary operator. ([@koic][])

### Changes

Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/lint/ambiguous_operator.rb
Expand Up @@ -43,6 +43,8 @@ def on_new_investigation
next unless diagnostic.reason == :ambiguous_prefix

offense_node = find_offense_node_by(diagnostic)
next unless offense_node

message = message(diagnostic)

add_offense(
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/lint/ambiguous_operator_spec.rb
Expand Up @@ -194,4 +194,12 @@
end
end
end

context 'when using safe navigation operator with a unary operator' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
do_something&.* -1
RUBY
end
end
end

0 comments on commit 134068f

Please sign in to comment.