Skip to content

Commit

Permalink
Merge pull request #10187 from koic/fix_false_positive_for_lint_ambig…
Browse files Browse the repository at this point in the history
…uous_range

[Fix #10185] Fix a false positive for `Lint/AmbiguousRange`
  • Loading branch information
koic committed Oct 14, 2021
2 parents e9c339b + 96457ee commit 41f2632
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_false_positive_for_lint_ambiguous_range.md
@@ -0,0 +1 @@
* [#10185](https://github.com/rubocop/rubocop/issues/10185): Fix a false positive for `Lint/AmbiguousRange` when using `self` in a range literal. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/ambiguous_range.rb
Expand Up @@ -82,7 +82,7 @@ def each_boundary(range)
def acceptable?(node)
node.begin_type? ||
node.basic_literal? ||
node.variable? || node.const_type? ||
node.variable? || node.const_type? || node.self_type? ||
(node.call_type? && acceptable_call?(node))
end

Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/lint/ambiguous_range_spec.rb
Expand Up @@ -74,6 +74,13 @@
RUBY
end

it 'does not register an offense for `self`' do
expect_no_offenses(<<~RUBY)
self#{operator}42
42#{operator}self
RUBY
end

it 'can handle an endless range', :ruby26 do
expect_offense(<<~RUBY)
x || 1#{operator}
Expand Down

0 comments on commit 41f2632

Please sign in to comment.