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

Autocorrect with Rails/WhereRange does not work correctly if a space is after the placeholder #1282

Closed
atolix opened this issue May 20, 2024 · 1 comment · Fixed by #1291
Closed
Labels
bug Something isn't working

Comments

@atolix
Copy link

atolix commented May 20, 2024

As the title suggests, Rails/WhereRange offense detection will not work if the placeholder in the where clause contains a space after it.

Expected behavior

User.where('created_at >= ? ', 10.days.ago)

This code expected to be automatically corrected like below.

User.where(created_at: 10.days.ago..)

Actual behavior

Offenses are not detected and are not automatically corrected.

Steps to reproduce the problem

It can be reproduced by adding a space after the placeholder.

ex)

User.where('created_at >= ? ', 10.days.ago)

RuboCop version

$ [bundle exec] rubocop -V
1.63.5 (using Parser 3.3.1.0, rubocop-ast 1.31.3, running on ruby 3.2.4) 
[aarch64-linux-musl] 
- rubocop-capybara 2.20.0 
- rubocop-factory_bot 2.25.1 
- rubocop-performance 1.21.0
- rubocop-rails 2.25.0 
- rubocop-rspec 2.29.2 
- rubocop-rspec_rails 2.28.3
@koic koic added the bug Something isn't working label May 27, 2024
fatkodima added a commit to fatkodima/rubocop-rails that referenced this issue Jun 7, 2024
@mikdiet
Copy link

mikdiet commented Jun 7, 2024

I just faced with similar, but with space before statement, i.e.

User.where(' created_at >= ?', 10.days.ago)

rubocop-rails v2.25.0

@koic koic closed this as completed in #1291 Jun 7, 2024
koic added a commit that referenced this issue Jun 7, 2024
[Fix #1282] Fix `WhereRange` to correctly handle template strings with extra spaces
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.

3 participants