rubocop / rails-style-guide

A community-driven Ruby on Rails style guide
http://rails.rubystyle.guide
6.47k stars 1.06k forks source link

Suggestion: Avoid `render ... and return` #327

Open andyw8 opened 1 year ago

andyw8 commented 1 year ago

Previously this pattern was used in the Rails docs examples but is now discouraged:

https://github.com/rails/rails/pull/45927/files

pirj commented 1 year ago

It's a controversial topic. https://github.com/rubocop/ruby-style-guide/pull/730 has been recently merged. Also related https://github.com/rubocop/ruby-style-guide/pull/785

mvz commented 8 months ago

While .. and .. is now permitted by the default RuboCop settings, the main problem I see with the render ... and return pattern is that it incorrectly suggests we should not return if the render part somehow fails.

pirj commented 8 months ago

Should we recommend return render …?

andyw8 commented 8 months ago

I think it's better for the return to be a separate statement. Returning a value would suggest that it's used for something.