From 048bdb2e9ef5ad22bd9937f47ad01823a44f09f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 31 Oct 2025 13:02:09 +0100 Subject: [PATCH] Add and apply Rails/OrderArguments rubocop rule This rule was introduced in rubocop-rails 2.33. We were following it most of the time. --- .rubocop.yml | 3 +++ .../admin/budget_investments/search_form_component.rb | 4 ++-- app/controllers/admin/homepage_controller.rb | 2 +- app/controllers/admin/site_customization/pages_controller.rb | 2 +- app/models/budget/investment.rb | 4 ++-- app/models/budget/stats.rb | 2 +- app/models/concerns/statisticable.rb | 2 +- app/models/legislation/draft_version.rb | 2 +- app/models/legislation/question.rb | 2 +- app/models/poll/question.rb | 2 +- app/models/site_customization/page.rb | 4 ++-- app/models/widget/feed.rb | 2 +- 12 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9544ed300..e6c5dc937 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -469,6 +469,9 @@ Rails/NotNullColumn: Exclude: - "db/migrate/201[5-7]*" +Rails/OrderArguments: + Enabled: true + Rails/OutputSafety: Enabled: true Severity: warning diff --git a/app/components/admin/budget_investments/search_form_component.rb b/app/components/admin/budget_investments/search_form_component.rb index daa5c222e..ebfa3e55e 100644 --- a/app/components/admin/budget_investments/search_form_component.rb +++ b/app/components/admin/budget_investments/search_form_component.rb @@ -35,11 +35,11 @@ class Admin::BudgetInvestments::SearchFormComponent < ApplicationComponent end def valuator_group_select_options - ValuatorGroup.order("name ASC").map { |g| [g.name, "group_#{g.id}"] } + ValuatorGroup.order(:name).map { |g| [g.name, "group_#{g.id}"] } end def valuator_select_options - budget.valuators.order("description ASC").order("users.email ASC").includes(:user) + budget.valuators.order(:description).order("users.email ASC").includes(:user) .map { |v| [v.description_or_email, "valuator_#{v.id}"] } end diff --git a/app/controllers/admin/homepage_controller.rb b/app/controllers/admin/homepage_controller.rb index 30ded0a75..4333dca34 100644 --- a/app/controllers/admin/homepage_controller.rb +++ b/app/controllers/admin/homepage_controller.rb @@ -21,6 +21,6 @@ class Admin::HomepageController < Admin::BaseController end def load_feeds - @feeds = Widget::Feed.order("created_at") + @feeds = Widget::Feed.order(:created_at) end end diff --git a/app/controllers/admin/site_customization/pages_controller.rb b/app/controllers/admin/site_customization/pages_controller.rb index 11a69b9d9..85a476dde 100644 --- a/app/controllers/admin/site_customization/pages_controller.rb +++ b/app/controllers/admin/site_customization/pages_controller.rb @@ -3,7 +3,7 @@ class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::Base load_and_authorize_resource :page, class: "SiteCustomization::Page" def index - @pages = SiteCustomization::Page.order("slug").page(params[:page]) + @pages = SiteCustomization::Page.order(:slug).page(params[:page]) end def create diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 871b3bc1f..5f6ea7257 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -69,8 +69,8 @@ class Budget scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc, id: :desc) } scope :sort_by_ballots, -> { reorder(ballot_lines_count: :desc, id: :desc) } scope :sort_by_price, -> { reorder(price: :desc, confidence_score: :desc, id: :desc) } - scope :sort_by_id, -> { order("id DESC") } - scope :sort_by_supports, -> { order("cached_votes_up DESC") } + scope :sort_by_id, -> { order(id: :desc) } + scope :sort_by_supports, -> { order(cached_votes_up: :desc) } scope :valuation_open, -> { where(valuation_finished: false) } scope :with_admin, -> { where.not(administrator_id: nil) } diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 33e45b211..673c1727d 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -75,7 +75,7 @@ class Budget::Stats def headings groups = Hash.new(0) - budget.headings.order("id ASC").each do |heading| + budget.headings.order(:id).each do |heading| groups[heading.id] = Hash.new(0).merge(calculate_heading_totals(heading)) end diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb index f8b13766a..a36e889a7 100644 --- a/app/models/concerns/statisticable.rb +++ b/app/models/concerns/statisticable.rb @@ -216,7 +216,7 @@ module Statisticable end def geozones - Geozone.order("name") + Geozone.order(:name) end def range_description(start, finish) diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 9b21ae923..2a23d48b8 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -19,7 +19,7 @@ class Legislation::DraftVersion < ApplicationRecord validates_translation :body, presence: true validates :status, presence: true, inclusion: { in: ->(*) { VALID_STATUSES }} - scope :published, -> { where(status: "published").order("id DESC") } + scope :published, -> { where(status: "published").order(id: :desc) } def body_html MarkdownConverter.new(body, with_toc_data: true).render diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 569544b6d..7895a54a9 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -27,7 +27,7 @@ class Legislation::Question < ApplicationRecord validates :process, presence: true validates_translation :title, presence: true - scope :sorted, -> { order("id ASC") } + scope :sorted, -> { order(:id) } def next_question_id @next_question_id ||= process.questions.where("id > ?", id).sorted.limit(1).ids.first diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index ce719493a..669babc8b 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -12,7 +12,7 @@ class Poll::Question < ApplicationRecord has_many :comments, as: :commentable, inverse_of: :commentable has_many :answers, class_name: "Poll::Answer" - has_many :question_options, -> { order "given_order asc" }, + has_many :question_options, -> { order :given_order }, class_name: "Poll::Question::Option", inverse_of: :question, dependent: :destroy diff --git a/app/models/site_customization/page.rb b/app/models/site_customization/page.rb index a5a1105d1..a57123d5e 100644 --- a/app/models/site_customization/page.rb +++ b/app/models/site_customization/page.rb @@ -13,8 +13,8 @@ class SiteCustomization::Page < ApplicationRecord validates :status, presence: true, inclusion: { in: ->(*) { VALID_STATUSES }} scope :published, -> { where(status: "published").sort_desc } - scope :sort_asc, -> { order("id ASC") } - scope :sort_desc, -> { order("id DESC") } + scope :sort_asc, -> { order(:id) } + scope :sort_desc, -> { order(id: :desc) } scope :with_more_info_flag, -> { where(status: "published", more_info_flag: true).sort_asc } scope :with_same_locale, -> { joins(:translations).locale } scope :locale, -> { where("site_customization_page_translations.locale": I18n.locale) } diff --git a/app/models/widget/feed.rb b/app/models/widget/feed.rb index cce6c69bc..793d8843c 100644 --- a/app/models/widget/feed.rb +++ b/app/models/widget/feed.rb @@ -29,6 +29,6 @@ class Widget::Feed < ApplicationRecord end def processes - Legislation::Process.open.published.order("created_at DESC").limit(limit) + Legislation::Process.open.published.order(created_at: :desc).limit(limit) end end