return-in-void-context
What it does
Section titled “What it does”Reports return value in initialize or a setter method, whose result is ignored.
Why it matters
Section titled “Why it matters”new always returns the new object, and an assignment a.x = 1 evaluates to 1 whatever the setter returns. The value cannot be used by anyone, so it is a sign of a misunderstanding.
To fix, return nothing: return alone is fine.
Example
Section titled “Example”... super(msg) end def foo=(_v) return 1 end def bar(a, b = 1) super...Configuration
Section titled “Configuration”ruby: lint: rules: return-in-void-context: warn # off, warn (default), errorEnabled by the presets: ruby/rubocop.
Suppress one line with sudsy-disable-next-line return-in-void-context 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/ReturnInVoidContext |
full |