From cd5009077155b6eccf5ca99a226e41771df997b8 Mon Sep 17 00:00:00 2001 From: Tejas Bubane Date: Thu, 13 May 2021 13:23:01 +0530 Subject: [PATCH] [Fix #9792] Fix false positive for `Lint/Void` cop Closes #9792 --- changelog/fix_lint_void_false_positive.md | 1 + lib/rubocop/cop/lint/void.rb | 2 +- spec/rubocop/cop/lint/void_spec.rb | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_lint_void_false_positive.md diff --git a/changelog/fix_lint_void_false_positive.md b/changelog/fix_lint_void_false_positive.md new file mode 100644 index 00000000000..a97edeaf96b --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/cop/lint/void.rb b/lib/rubocop/cop/lint/void.rb index a45cace085b..a94380e6cfe 100644 --- a/lib/rubocop/cop/lint/void.rb +++ b/lib/rubocop/cop/lint/void.rb @@ -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 diff --git a/spec/rubocop/cop/lint/void_spec.rb b/spec/rubocop/cop/lint/void_spec.rb index 919b63cf3cb..8d6ee93902a 100644 --- a/spec/rubocop/cop/lint/void_spec.rb +++ b/spec/rubocop/cop/lint/void_spec.rb @@ -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