on-internet
← Community

Is there a way to enforce explicit returns in Rubocop?

Stack Overflow ·

I'm looking for a way to make Rubocop linter for Ruby enforce explicit returns from function calls. This is a house rule I want to implement since it is easier for people coming from other languages. I saw that someone had the same question earlier on the Rubocop GitHub but there was no solution provided https://github.com/rubocop/rubocop/issues/4149 Examples: # good def cond_explicit(cond) if cond return 'yes' else return 'no' end end # bad def cond_implicit(cond) if cond 'yes' else 'no' end end # good def str_explicit return 'str' end # bad def str_implicit 'str' end

Comments

Sign in or sign up to comment and upvote.

No comments yet.