ambiguous-block-association
What it does
Section titled “What it does”Reports a call without parentheses whose last argument is a call with a braces block (expect { x }.to change { y }); also a do block that binds to the outer call while a block method is an argument.
Why it matters
Section titled “Why it matters”A {} block binds to the nearest call and a do ... end block to the outermost one, so without parentheses it is easy to attach the block to a different method from the one that was meant, and the code runs without the block being used as intended.
To fix, add parentheses around the arguments.
Example
Section titled “Example”puts [1].map { |x| x }...raise StandardError...Configuration
Section titled “Configuration”ruby: lint: rules: ambiguous-block-association: warn # off (default), warn, errorEnabled by the presets: ruby/rubocop.
Suppress one line with sudsy-disable-next-line ambiguous-block-association 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/AmbiguousBlockAssociation |
full |