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 #10185] Fix a false positive for Lint/AmbiguousRange #10187

Merged
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/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