Skip to content

Commit

Permalink
[Fix rubocop#210] Change enforced style to conditionals for `Style/An…
Browse files Browse the repository at this point in the history
…dOr`

Resolves rubocop#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.
  • Loading branch information
koic committed Apr 1, 2020
1 parent 32791a6 commit 6dbae58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Changes

* [#223](https://github.com/rubocop-hq/rubocop-rails/pull/223): Mark `Rails/ApplicationController`, `Rails/ApplicationJob`, `Rails/ApplicationMailer`, and `Rails/ApplicationRecord` as unsafe autocorrect. ([@hoshinotsuyoshi][])
* [#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)

Expand Down
4 changes: 4 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,7 @@ Rails/Validation:
VersionChanged: '0.41'
Include:
- app/models/**/*.rb

# Accept `redirecto_to(...) and return` and similar cases.
Style/AndOr:
EnforcedStyle: conditionals

0 comments on commit 6dbae58

Please sign in to comment.