diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aec27826f..49a52d4ff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ ### Changes * [#98](https://github.com/rubocop-hq/rubocop-rails/pull/98): Mark `Rails/ActiveRecordAliases` as `SafeAutoCorrect` false and disable autocorrect by default. ([@prathamesh-sonpatki][]) +* [#101](https://github.com/rubocop-hq/rubocop-rails/pull/101): Mark `Rails/SaveBang` as `SafeAutoCorrect` false and disable autocorrect by default. ([@prathamesh-sonpatki][]) +* [#102](https://github.com/rubocop-hq/rubocop-rails/pull/102): Include `create_or_find_by` in `Rails/SaveBang` cop. ([@MaximeLaurenty][]) ## 2.2.1 (2019-07-13) @@ -59,3 +61,4 @@ [@brunvez]: https://github.com/brunvez [@santib]: https://github.com/santib [@prathamesh-sonpatki]: https://github.com/prathamesh-sonpatki +[@MaximeLaurenty]: https://github.com/MaximeLaurenty diff --git a/config/default.yml b/config/default.yml index 4a51a98092..bf9e24d8e0 100644 --- a/config/default.yml +++ b/config/default.yml @@ -404,6 +404,7 @@ Rails/SaveBang: VersionChanged: '0.59' AllowImplicitReturn: true AllowedReceivers: [] + SafeAutoCorrect: false Rails/ScopeArgs: Description: 'Checks the arguments of ActiveRecord scopes.' diff --git a/lib/rubocop/cop/rails/save_bang.rb b/lib/rubocop/cop/rails/save_bang.rb index 38a1e4140b..e301023469 100644 --- a/lib/rubocop/cop/rails/save_bang.rb +++ b/lib/rubocop/cop/rails/save_bang.rb @@ -108,7 +108,7 @@ class SaveBang < Cop CREATE_CONDITIONAL_MSG = '`%s` returns a model which is ' \ 'always truthy.' - CREATE_PERSIST_METHODS = %i[create + CREATE_PERSIST_METHODS = %i[create create_or_find_by first_or_create find_or_create_by].freeze MODIFY_PERSIST_METHODS = %i[save update update_attributes destroy].freeze diff --git a/manual/cops_rails.md b/manual/cops_rails.md index b5603e000f..2915800d1d 100644 --- a/manual/cops_rails.md +++ b/manual/cops_rails.md @@ -2064,7 +2064,7 @@ ConvertTry | `false` | Boolean Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged --- | --- | --- | --- | --- -Disabled | Yes | Yes | 0.42 | 0.59 +Disabled | Yes | Yes (Unsafe) | 0.42 | 0.59 This cop identifies possible cases where Active Record save! or related should be used instead of save because the model might have failed to