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 #8704] Fix an error for Lint/AmbiguousOperator #8706

Merged
merged 1 commit into from Sep 12, 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 @@ -29,6 +29,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