Skip to content

Conversation

viralpraxis
Copy link
Contributor

ref: #1501

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.

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
ref: rubocop#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.
@koic koic merged commit 17c2831 into rubocop:master Aug 11, 2025
16 checks passed
@viralpraxis viralpraxis deleted the fix-rails-order-arguments-cop-false-positives branch August 11, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants