From 83a32e1fa79c2cf51cee7bb89c8f0e651f510cdc Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 29 Mar 2020 17:01:43 +0900 Subject: [PATCH] [Fix #210] Change enforced style to conditionals for `Style/AndOr` Resolves #210. The following idioms exist for `return` and` raise` in Ruby. - `do_something and return` - `do_something || raise` And Rails will also show users the error message using this idiom. > `"redirect_to(...) and return\"` https://github.com/rails/rails/blob/v6.0.2.2/actionpack/lib/abstract_controller/rendering.rb#L10 This is the same for `render :action and return` and others. `Style/AndOr` cop default rule (`EnforcedStyle: always`) does seem to unmatch for these cases. I think these cases need to be accepted. So, this PR changes it to `EnforcedStyle: conditionals` at least in Rails. The enforced style cannot catch all cases, but probably the closest to solving the issue. --- CHANGELOG.md | 1 + config/default.yml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15790ccdf9..af6c7f24e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * [#233](https://github.com/rubocop-hq/rubocop-rails/pull/233): **(BREAKING)** Drop support for Ruby 2.3. ([@koic][]) * [#236](https://github.com/rubocop-hq/rubocop-rails/pull/236): **(BREAKING)** Drop support for Rails 4.1 or lower. ([@koic][]) +* [#210](https://github.com/rubocop-hq/rubocop-rails/issues/210): Accept `redirecto_to(...) and return` and similar cases. ([@koic][]) ## 2.5.2 (2020-04-09) diff --git a/config/default.yml b/config/default.yml index 32e13eb94b..95629e442b 100644 --- a/config/default.yml +++ b/config/default.yml @@ -549,3 +549,7 @@ Rails/Validation: VersionChanged: '0.41' Include: - app/models/**/*.rb + +# Accept `redirecto_to(...) and return` and similar cases. +Style/AndOr: + EnforcedStyle: conditionals