Skip to content

useless-times

Rubysuspiciousno fixdefault: offruby/rubocop

Reports 0.times and 1.times with a block.

The block runs at most once, so the loop is a way to write if. It is usually left from a value that was a variable.

To fix, delete the loop, or call the code directly.

Reported
...
foo(1)
...
h.key?(x.id)
1.times { f }
2.times { f }
...
ruby:
lint:
rules:
useless-times: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line useless-times in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/UselessTimes full