Commit 3971a35
committed
Fix
ref: #1501
```shell
echo 'User.order("1")' | bundle exec rubocop --stdin bug.rb -A --only Rails/OrderArguments
Inspecting 1 file
F
Offenses:
bug.rb:1:12: C: [Corrected] Rails/OrderArguments: Prefer :1 instead. (https://rails.rubystyle.guide/#order-arguments)
User.order("1")
^^^
bug.rb:1:13: F: Lint/Syntax: invalid symbol
(Using Ruby 3.4 parser; configure using TargetRubyVersion parameter, under AllCops)
User.order(:1)
bug.rb:1:13: F: Lint/Syntax: unexpected integer; expected a ) to close the arguments
(Using Ruby 3.4 parser; configure using TargetRubyVersion parameter, under AllCops)
User.order(:1)
^
bug.rb:1:14: F: Lint/Syntax: unexpected ')', expecting end-of-input
(Using Ruby 3.4 parser; configure using TargetRubyVersion parameter, under AllCops)
User.order(:1)
^
1 file inspected, 4 offenses detected, 1 offense corrected
====================
User.order(:1)
```
The same happens for these cases:
```
order("1 ASC") # => User.order(:1)
order("1 DESC") # => User.order(1: :desc)
order("id ASC, 2 DESC") # => User.order(:id, 2: :desc)
```
`order("1")` can be autocorrected to `order(1)`, but this can be done
separately.Rails/OrderArguments cop false positives1 parent 812251d commit 3971a35
3 files changed
Lines changed: 32 additions & 0 deletions
File tree
- changelog
- lib/rubocop/cop/rails
- spec/rubocop/cop/rails
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
131 | 157 | | |
0 commit comments