Skip to content
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

Rails/FindBy should ignore take with arguments #512

Closed
bquorning opened this issue Jun 30, 2021 · 0 comments · Fixed by #513
Closed

Rails/FindBy should ignore take with arguments #512

bquorning opened this issue Jun 30, 2021 · 0 comments · Fixed by #513
Labels
bug Something isn't working

Comments

@bquorning
Copy link
Contributor

Failing test case (for

it 'does not registers an offense when using `#take` with arguments' do
  expect_no_offenses(<<~RUBY)
    User.where(id: x).take(5)
  RUBY
end

In the current implementation you’d get

User.where(id: x).take(5)
     ^^^^^^^^^^^^^^^^^ Use `find_by` instead of `where.take`.

and the line would be autocorrected to

User.where(id: x)(5)

RuboCop version

❯ bundle exec rubocop -V
1.18.1 (using Parser 3.0.1.1, rubocop-ast 1.7.0, running on ruby 2.6.6 x86_64-darwin19)
  - rubocop-performance 1.11.3
  - rubocop-rails 2.11.1
  - rubocop-rspec 1.29.1
@bquorning bquorning added the bug Something isn't working label Jun 30, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Jun 30, 2021
Fix rubocop#512

This PR fixes a false positive for `Rails/FindBy`
when using `take` with arguments.
koic added a commit to koic/rubocop-rails that referenced this issue Jul 1, 2021
Fix rubocop#512

This PR fixes a false positive for `Rails/FindBy`
when using `take` with arguments.
koic added a commit to koic/rubocop-rails that referenced this issue Jul 1, 2021
Fix rubocop#512

This PR fixes a false positive for `Rails/FindBy`
when using `take` with arguments.
@koic koic closed this as completed in #513 Jul 1, 2021
koic added a commit that referenced this issue Jul 1, 2021
[Fix #512] Fix a false positive for `Rails/FindBy`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant