Skip to content

return-in-void-context

Rubysuspiciousno fixdefault: warnruby/rubocop

Reports return value in initialize or a setter method, whose result is ignored.

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.

Reported
...
super(msg)
end
def foo=(_v)
return 1
end
def bar(a, b = 1)
super
...
ruby:
lint:
rules:
return-in-void-context: warn # off, warn (default), error

Enabled 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.

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

Tool Rule Match
rubocop Lint/ReturnInVoidContext full