Skip to content

Commit

Permalink
Merge pull request #8733 from koic/fix_error_for_lint_useless_times
Browse files Browse the repository at this point in the history
[Fix #8730] Fix an error for `Lint/UselessTimes`
  • Loading branch information
koic committed Sep 16, 2020
2 parents a6c89f9 + fe478d7 commit 5e2acf3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* [#8720](https://github.com/rubocop-hq/rubocop/issues/8720): Fix an error for `Lint/IdentityComparison` when calling `object_id` method without receiver in LHS or RHS. ([@koic][])
* [#8710](https://github.com/rubocop-hq/rubocop/issues/8710): Fix a false positive for `Layout/RescueEnsureAlignment` when `Layout/BeginEndAlignment` cop is not enabled status. ([@koic][])
* [#8726](https://github.com/rubocop-hq/rubocop/issues/8726): Fix a false positive for `Naming/VariableNumber` when naming multibyte character variable name. ([@koic][])
* [#8730](https://github.com/rubocop-hq/rubocop/issues/8730): Fix an error for `Lint/UselessTimes` when there is a blank line in the method definition. ([@koic][])

### Changes

Expand Down
7 changes: 6 additions & 1 deletion lib/rubocop/cop/lint/useless_times.rb
Expand Up @@ -82,7 +82,12 @@ def autocorrect_block(corrector, node)
def fix_indentation(source, range)
# Cleanup indentation in a multiline block
source_lines = source.split("\n")
source_lines[1..-1].each { |line| line[range] = '' }

source_lines[1..-1].each do |line|
next if line.empty?

line[range] = ''
end
source_lines.join("\n")
end

Expand Down
21 changes: 21 additions & 0 deletions spec/rubocop/cop/lint/useless_times_spec.rb
Expand Up @@ -61,6 +61,27 @@
RUBY
end

it 'registers an offense and corrects when there is a blank line in the method definition' do
expect_offense(<<~RUBY)
def foo
1.times do
^^^^^^^^^^ Useless call to `1.times` detected.
bar
baz
end
end
RUBY

expect_correction(<<~RUBY)
def foo
bar
baz
end
RUBY
end

it 'does not register an offense for an integer > 1' do
expect_no_offenses(<<~RUBY)
2.times { |i| puts i }
Expand Down

0 comments on commit 5e2acf3

Please sign in to comment.