Skip to content

Commit

Permalink
Merge pull request #9908 from koic/fix_incorrect_autocorrect_for_lint…
Browse files Browse the repository at this point in the history
…_useless_time

[Fix #9907] Fix an incorrect auto-correct for `Lint/UselessTimes`
  • Loading branch information
koic committed Jul 4, 2021
2 parents 79f6115 + 64d06c6 commit ae0deb3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
@@ -0,0 +1 @@
* [#9907](https://github.com/rubocop/rubocop/issues/9907): Fix an incorrect auto-correct for `Lint/UselessTimes` when using block argument for `1.times`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/useless_times.rb
Expand Up @@ -81,7 +81,7 @@ def autocorrect_block(corrector, node)
return if block_reassigns_arg?(node, block_arg)

source = node.body.source
source.gsub!(/\b#{block_arg}\b/, '1') if block_arg
source.gsub!(/\b#{block_arg}\b/, '0') if block_arg

corrector.replace(node, fix_indentation(source, node.loc.column...node.body.loc.column))
end
Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cop/lint/useless_times_spec.rb
Expand Up @@ -55,7 +55,7 @@
RUBY

expect_correction(<<~RUBY)
something(1)
something(0)
RUBY
end

Expand Down Expand Up @@ -163,8 +163,8 @@ def foo
RUBY

expect_correction(<<~RUBY)
do_something(1)
do_something_else(1)
do_something(0)
do_something_else(0)
RUBY
end

Expand Down Expand Up @@ -205,7 +205,7 @@ def foo
RUBY

expect_correction(<<~RUBY)
do_something(1)
do_something(0)
j = 1
do_something_else(j)
RUBY
Expand Down

0 comments on commit ae0deb3

Please sign in to comment.