Skip to content

Commit

Permalink
Merge pull request #320 from kunitoo/uniq_before_pluck_to_unsafe
Browse files Browse the repository at this point in the history
Mark `Rails/UniqBeforePluck` cops as unsafe
  • Loading branch information
koic authored Aug 7, 2020
2 parents ee5c3e0 + e69b8ea commit dc888a3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -262,3 +263,4 @@
[@taylorthurlow]: https://github.com/taylorthurlow
[@krim]: https://github.com/krim
[@philcoggins]: https://github.com/philcoggins
[@kunitoo]: https://github.com/kunitoo
3 changes: 2 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions docs/modules/ROOT/pages/cops_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rails/uniq_before_pluck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down

0 comments on commit dc888a3

Please sign in to comment.