Add and apply Style/CollectionQuerying rubocop rule

This rule was added in rubocop 1.77. We were following it most of the
time. It makes the code more readable in my humble opinion.
This commit is contained in:
Javi Martín
2025-10-31 14:31:35 +01:00
parent 1fa3cf8ce7
commit 7f749bb9bb
9 changed files with 14 additions and 11 deletions

View File

@@ -747,6 +747,9 @@ Style/ClassVars:
Style/CollectionMethods:
Enabled: true
Style/CollectionQuerying:
Enabled: true
Style/ComparableBetween:
Enabled: true

View File

@@ -16,7 +16,7 @@ class Layout::NotificationItemComponent < ApplicationComponent
end
def notifications_class
if unread_notifications.count > 0
if unread_notifications.any?
"unread-notifications"
else
"no-notifications"

View File

@@ -1,6 +1,6 @@
module DebatesHelper
def has_featured?
Debate.all.featured.count > 0
Debate.all.featured.any?
end
def empty_recommended_debates_message_text(user)

View File

@@ -6,11 +6,11 @@ class PollOptionFinder
end
def manageable_choices
choices_map.select { |choice, ids| ids.count == 1 }
choices_map.select { |choice, ids| ids.one? }
end
def unmanageable_choices
choices_map.reject { |choice, ids| ids.count == 1 }
choices_map.reject { |choice, ids| ids.one? }
end
private

View File

@@ -37,7 +37,7 @@ class Budget
end
def has_lines_with_no_heading?
investments.no_heading.count > 0
investments.no_heading.any?
end
def has_lines_with_heading?

View File

@@ -84,7 +84,7 @@ module Globalizable
length: options[:length],
if: lambda { |translation| translation.locale == Setting.default_locale }
end
if options.count > 1
if options.many?
translation_class.instance_eval do
validates method, options.reject { |key| key == :length }
end

View File

@@ -42,7 +42,7 @@ class Verification::Management::Email
private
def validate_user
return if errors.count > 0
return if errors.any?
if !user?
errors.add(:email, I18n.t("errors.messages.user_not_found"))
@@ -52,7 +52,7 @@ class Verification::Management::Email
end
def validate_document_number
return if errors.count > 0
return if errors.any?
if document_number_mismatch?
errors.add(

View File

@@ -1,5 +1,5 @@
# Default admin user (change password after first deploy to a server!)
if Administrator.count == 0 && (!Rails.env.test? || !Tenant.default?)
if Administrator.none? && (!Rails.env.test? || !Tenant.default?)
admin = User.create!(username: "admin", email: "admin@consul.dev", password: "12345678",
password_confirmation: "12345678", confirmed_at: Time.current,
terms_of_service: "1")

View File

@@ -94,7 +94,7 @@ namespace :polls do
option_finder.unmanageable_choices.each do |choice, ids|
tenant_info = " on tenant #{Tenant.current_schema}" unless Tenant.default?
if ids.count == 0
if ids.none?
logger.warn "Skipping poll_answers with the text \"#{choice}\" for the poll_question " \
"with ID #{question.id}. This question has no poll_question_answers " \
"containing the text \"#{choice}\"" + tenant_info.to_s
@@ -185,7 +185,7 @@ namespace :polls do
option_finder.unmanageable_choices.each do |choice, ids|
tenant_info = " on tenant #{Tenant.current_schema}" unless Tenant.default?
if ids.count == 0
if ids.none?
logger.warn "Skipping poll_partial_results with the text \"#{choice}\" for the poll_question " \
"with ID #{question.id}. This question has no poll_question_answers " \
"containing the text \"#{choice}\"" + tenant_info.to_s