From 25cbf309cb0d15e31272f42645f42d48028259e3 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 | 4 ++++ config/default.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad28ccef09..137df4618f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ * [#215](https://github.com/rubocop-hq/rubocop-rails/issues/215): Fix a false positive for `Rails/UniqueValidationWithoutIndex` when using Expression Indexes. ([@koic][]) * [#214](https://github.com/rubocop-hq/rubocop-rails/issues/214): Fix an error for `Rails/UniqueValidationWithoutIndex`when a table has no column definition. ([@koic][]) +### Changes + +* [#210](https://github.com/rubocop-hq/rubocop-rails/issues/210): Accept `redirecto_to(...) and return` and similar cases. ([@koic][]) + ## 2.5.0 (2020-03-24) ### New features diff --git a/config/default.yml b/config/default.yml index f6817e69b9..e7f2efb20f 100644 --- a/config/default.yml +++ b/config/default.yml @@ -535,3 +535,7 @@ Rails/Validation: VersionChanged: '0.41' Include: - app/models/**/*.rb + +# Accept `redirecto_to(...) and return` and similar cases. +Style/AndOr: + EnforcedStyle: conditionals