Skip to content

Commit

Permalink
[Fix #9792] Fix false positive for Lint/Void cop
Browse files Browse the repository at this point in the history
Closes #9792
  • Loading branch information
tejasbubane authored and bbatsov committed May 17, 2021
1 parent 4f13546 commit 40d0970
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_lint_void_false_positive.md
@@ -0,0 +1 @@
* [#9792](https://github.com/rubocop/rubocop/issues/9792): Fix false positive for `Lint/Void` cop with ranges. ([@tejasbubane][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/void.rb
Expand Up @@ -104,7 +104,7 @@ def check_var(node)
end

def check_literal(node)
return if !node.literal? || node.xstr_type?
return if !node.literal? || node.xstr_type? || node.range_type?

add_offense(node, message: format(LIT_MSG, lit: node.source))
end
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/lint/void_spec.rb
Expand Up @@ -254,4 +254,22 @@ def foo=(rhs)
nil
RUBY
end

it 'accepts method with irange block' do
expect_no_offenses(<<~RUBY)
def foo
1..100.times.each { puts 1 }
do_something
end
RUBY
end

it 'accepts method with erange block' do
expect_no_offenses(<<~RUBY)
def foo
1...100.times.each { puts 1 }
do_something
end
RUBY
end
end

0 comments on commit 40d0970

Please sign in to comment.