New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Use uniq before pluck #3148
Comments
I cannot replay it now, but as I see it is closed 👍 |
This is not fixed and should be reopened. See: #3122 (comment) |
I agree. It's not fixed. |
I don't think we can easily distinguish between I should either:
Let me know what is preferred in situations like this. |
Disable Rails/UniqBeforePluck rubocop cop Rails/UniqBeforePluck seems to have some bugs * rubocop/rubocop#3122 * rubocop/rubocop#3148 and we had some problems in EE with that https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/425#note_12245005 See merge request !4477
Maybe we can still "save" this cop by making it more conservative. I mean, we could start with some simple expressions that we believe will not generate many false positives. For example: MyModel.pluck(:col).uniq where the receiver looks like a class. We let the cop only report such expressions. But even so, removing (or disabling) auto-correct might be necessary. |
…cop#3231) Autocorrect is disabled by default for this cop since it can potentially generate false positives. Add offenses for `distinct` as well as `uniq`. By default only add offenses for calls to `pluck` directly on constants. Add an 'aggressive' mode that adds all offenses as the cop did originally.
In model i have
rubocop -a
returnsAnd in this case, it is wrong correction, because
uniq
ordistinct
methods return Array andpluck
need Activerecord::RelationThe text was updated successfully, but these errors were encountered: