diff --git a/CHANGELOG.md b/CHANGELOG.md index be369485fe..3545855977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * [#312](https://github.com/rubocop-hq/rubocop-rails/pull/312): Mark `Rails/MailerName` as unsafe for auto-correct. ([@eugeneius][]) * [#294](https://github.com/rubocop-hq/rubocop-rails/pull/294): Update `Rails/ReversibleMigration` to register offenses for `remove_columns` and `remove_index`. ([@philcoggins][]) * [#310](https://github.com/rubocop-hq/rubocop-rails/issues/310): Add `EnforcedStyle` to `Rails/PluckInWhere`. By default, it does not register an offense if `pluck` method's receiver is a variable. ([@koic][]) +* [#320](https://github.com/rubocop-hq/rubocop-rails/pull/320): Mark `Rails/UniqBeforePluck` as unsafe. ([@kunitoo][]) ## 2.7.1 (2020-07-26) @@ -262,3 +263,4 @@ [@taylorthurlow]: https://github.com/taylorthurlow [@krim]: https://github.com/krim [@philcoggins]: https://github.com/philcoggins +[@kunitoo]: https://github.com/kunitoo diff --git a/config/default.yml b/config/default.yml index 2da68ebc49..3795e63a0f 100644 --- a/config/default.yml +++ b/config/default.yml @@ -657,11 +657,12 @@ Rails/UniqBeforePluck: Description: 'Prefer the use of uniq or distinct before pluck.' Enabled: true VersionAdded: '0.40' - VersionChanged: '2.6' + VersionChanged: '2.8' EnforcedStyle: conservative SupportedStyles: - conservative - aggressive + Safe: false AutoCorrect: false Rails/UniqueValidationWithoutIndex: diff --git a/docs/modules/ROOT/pages/cops_rails.adoc b/docs/modules/ROOT/pages/cops_rails.adoc index 5ef235d780..dc2c540cf8 100644 --- a/docs/modules/ROOT/pages/cops_rails.adoc +++ b/docs/modules/ROOT/pages/cops_rails.adoc @@ -3977,10 +3977,10 @@ Time.at(timestamp).in_time_zone | Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Enabled -| Yes -| Yes +| No +| Yes (Unsafe) | 0.40 -| 2.6 +| 2.8 |=== Prefer the use of distinct, before pluck instead of after. @@ -3998,6 +3998,8 @@ as the cop cannot distinguish between calls to pluck on an ActiveRecord::Relation vs a call to pluck on an ActiveRecord::Associations::CollectionProxy. +This cop is unsafe because the behavior may change depending on the +database collation. Autocorrect is disabled by default for this cop since it may generate false positives. diff --git a/lib/rubocop/cop/rails/uniq_before_pluck.rb b/lib/rubocop/cop/rails/uniq_before_pluck.rb index a650605842..c74d3f6d2d 100644 --- a/lib/rubocop/cop/rails/uniq_before_pluck.rb +++ b/lib/rubocop/cop/rails/uniq_before_pluck.rb @@ -18,6 +18,8 @@ module Rails # ActiveRecord::Relation vs a call to pluck on an # ActiveRecord::Associations::CollectionProxy. # + # This cop is unsafe because the behavior may change depending on the + # database collation. # Autocorrect is disabled by default for this cop since it may generate # false positives. #