From b15ae494c387884c00ea14dc5757f1ec27d9d5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=A5=E0=A4=AE=E0=A5=87?= =?UTF-8?q?=E0=A4=B6=20Sonpatki?= Date: Tue, 30 Jul 2019 13:49:19 +0530 Subject: [PATCH] Mark ActiveRecord/Aliases as unsafe autocorrect We faced an issue where our custom `update_attributes` method call was changed to `update` but the method name remained same in the method definition. ```ruby def update_attributes end update_attributes ``` ```ruby def update_attributes end update ``` So the cop is not safe for auto correct. --- CHANGELOG.md | 2 ++ config/default.yml | 2 ++ manual/cops_rails.md | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04048e5e01..407e16ed0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### New features +* [#98](https://github.com/rubocop-hq/rubocop-rails/issues/98): Mark `Rails/ActiveRecordAliases` as `SafeAutoCorrect` false and disable autocorrect by default. ([@prathamesh-sonpatki][]) * [#78](https://github.com/rubocop-hq/rubocop-rails/issues/78): Add new `Rails/EnumHash` cop. ([@fedeagripa][], [@brunvez][], [@santib][]) ### Bug fixes @@ -54,3 +55,4 @@ [@fedeagripa]: https://github.com/fedeagripa [@brunvez]: https://github.com/brunvez [@santib]: https://github.com/santib +[@prathamesh-sonpatki]: https://github.com/prathamesh-sonpatki diff --git a/config/default.yml b/config/default.yml index e8ea60d302..6bbb43a763 100644 --- a/config/default.yml +++ b/config/default.yml @@ -31,6 +31,8 @@ Rails/ActiveRecordAliases: Use `update!` instead of `update_attributes!`. Enabled: true VersionAdded: '0.53' + SafeAutoCorrect: false + AutoCorrect: false Rails/ActiveRecordOverride: Description: >- diff --git a/manual/cops_rails.md b/manual/cops_rails.md index 017184d3c2..9b7a09d7c5 100644 --- a/manual/cops_rails.md +++ b/manual/cops_rails.md @@ -51,7 +51,7 @@ Include | `app/controllers/**/*.rb` | Array Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged --- | --- | --- | --- | --- -Enabled | Yes | Yes | 0.53 | - +Enabled | Yes | Yes (Unsafe) | 0.53 | - Checks that ActiveRecord aliases are not used. The direct method names are more clear and easier to read. @@ -66,6 +66,12 @@ Book.update_attributes!(author: 'Alice') Book.update!(author: 'Alice') ``` +### Configurable attributes + +Name | Default value | Configurable values +--- | --- | --- +AutoCorrect | `false` | Boolean + ## Rails/ActiveRecordOverride Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged