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 an error for Lint/UselessTimes when no block is present #12775

Merged
merged 1 commit into from
Mar 11, 2024
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_an_error_for_lint_useless_times.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12775](https://github.com/rubocop/rubocop/pull/12775): Fix an error for `Lint/UselessTimes` when no block is present. ([@earlopain][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/useless_times.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def autocorrect(corrector, count, node, proc_name)
remove_node(corrector, node)
elsif !proc_name.empty?
autocorrect_block_pass(corrector, node, proc_name)
else
elsif node.block_type?
autocorrect_block(corrector, node)
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/lint/useless_times_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ def my_method

expect_no_corrections
end

it 'registers no offense for 1.times without block' do
Copy link
Contributor

Choose a reason for hiding this comment

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

It does register an offense, though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, right. Initially my intention was to not register something but I switched it up without updating this as well.

I'll try my hand at maybe making/extending some internal affair for this, there are already things that check for correct spec titles.

expect_offense(<<~RUBY)
1.times
^^^^^^^ Useless call to `1.times` detected.
RUBY

expect_no_corrections
end
end
end
end