Given the following:
class Foo
def foo
return 1, 2
end
end
RuboCop reports:
foo.rb:3:5: C: Redundant return detected.
return 1, 2
^^^^^^
In this case, the return isn't redundant, it's required. I'm not a huge fan of multiple return values, but given that I'm trying to validate two method parameters in relation to one another, it seems like writing a validate method that returns both is the cleanest thing to do without getting RuboCop complaining about the cyclomatic complexity of my initializer. :)
Implicit return of [1, 2] solves the problem.
Good point.
Just ran into this myself. I understand that an implicit return solves the problem and this is a minor problem, but that workaround enforces a certain style. Rubocop's job as a linter should be to catch a true redundancy in return and it's throwing a false error in this case.
Can the check be modified to not throw an error when it sees multiple values return (e.g. values separated by a comma?)
The option already exists, but it's not on by default: https://github.com/rubocop-hq/rubocop/blob/v0.58.2/config/default.yml#L1323-L1324
@jonas054 - Thanks, that's perfect!
Most helpful comment
The option already exists, but it's not on by default: https://github.com/rubocop-hq/rubocop/blob/v0.58.2/config/default.yml#L1323-L1324