useless-times
What it does
Section titled “What it does”Reports 0.times and 1.times with a block.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...foo(1)...h.key?(x.id)1.times { f }2.times { f }...Configuration
Section titled “Configuration”ruby: lint: rules: useless-times: warn # off (default), warn, errorEnabled by the presets: ruby/rubocop.
Suppress one line with sudsy-disable-next-line useless-times in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| rubocop | Lint/UselessTimes |
full |