Skip to content

Commit 202d8c1

Browse files
authored
Merge pull request #1293 from fatkodima/where-range-unsafe
[Fix #1283] Mark `WhereRange` as unsafe autocorrect
2 parents eb89bdd + f262f71 commit 202d8c1

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1283](https://github.com/rubocop/rubocop-rails/issues/1283): Mark `WhereRange` as unsafe autocorrect. ([@fatkodima][])

config/default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ Rails/WhereRange:
12271227
Description: 'Use ranges in `where` instead of manually constructing SQL.'
12281228
StyleGuide: 'https://rails.rubystyle.guide/#where-ranges'
12291229
Enabled: pending
1230+
SafeAutoCorrect: false
12301231
VersionAdded: '2.25'
12311232

12321233
# Accept `redirect_to(...) and return` and similar cases.

lib/rubocop/cop/rails/where_range.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ module Rails
66
# Identifies places where manually constructed SQL
77
# in `where` can be replaced with ranges.
88
#
9+
# @safety
10+
# This cop's autocorrection is unsafe because it can change the query
11+
# by explicitly attaching the column to the wrong table.
12+
# For example, `Booking.joins(:events).where('end_at < ?', Time.current)` will correctly
13+
# implicitly attach the `end_at` column to the `events` table. But when autocorrected to
14+
# `Booking.joins(:events).where(end_at: ...Time.current)`, it will now be incorrectly
15+
# explicitly attached to the `bookings` table.
16+
#
917
# @example
1018
# # bad
1119
# User.where('age >= ?', 18)

0 commit comments

Comments
 (0)