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 #9792] Fix false positive for Lint/Void cop #9796

Merged
merged 1 commit into from May 17, 2021
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_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?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why literal? doesn't cover them. I think they weren't immutable or something like this, but my memory on the subject is fuzzy.


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 }
tejasbubane marked this conversation as resolved.
Show resolved Hide resolved
do_something
end
RUBY
end
tejasbubane marked this conversation as resolved.
Show resolved Hide resolved
end