Add and apply rules for multi-line hashes

For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
This commit is contained in:
Javi Martín
2023-07-01 16:17:33 +02:00
parent 97aca0cf95
commit 8b13daad95
130 changed files with 676 additions and 592 deletions

View File

@@ -33,9 +33,9 @@ class Budget
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
validates :population, numericality: { greater_than: 0 }, allow_nil: true
validates :latitude, length: { maximum: 22 }, allow_blank: true, \
format: /\A(-|\+)?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)\z/
format: /\A(-|\+)?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)\z/
validates :longitude, length: { maximum: 22 }, allow_blank: true, \
format: /\A(-|\+)?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)\z/
format: /\A(-|\+)?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)\z/
validates :max_ballot_lines, numericality: { greater_than_or_equal_to: 1 }
delegate :budget, :budget_id, to: :group, allow_nil: true

View File

@@ -51,7 +51,7 @@ class Budget
has_many :comments, -> { where(valuation: false) }, as: :commentable, inverse_of: :commentable
has_one :summary_comment, as: :commentable, class_name: "MlSummaryComment", dependent: :destroy
has_many :valuations, -> { where(valuation: true) },
as: :commentable,
as: :commentable,
inverse_of: :commentable,
class_name: "Comment"
@@ -203,8 +203,9 @@ class Budget
end
def searchable_values
{ author.username => "B",
heading.name => "B",
{
author.username => "B",
heading.name => "B",
tag_list.join(" ") => "B"
}.merge(searchable_globalized_values)
end
@@ -394,7 +395,7 @@ class Budget
end
def searchable_translations_definitions
{ title => "A",
{ title => "A",
description => "D" }
end
end

View File

@@ -57,10 +57,10 @@ class Comment < ApplicationRecord
def self.build(commentable, user, body, p_id = nil, valuation = false)
new(commentable: commentable,
user_id: user.id,
body: body,
parent_id: p_id,
valuation: valuation)
user_id: user.id,
body: body,
parent_id: p_id,
valuation: valuation)
end
def self.find_commentable(c_type, c_id)
@@ -134,7 +134,7 @@ class Comment < ApplicationRecord
def searchable_values
{
body => "A",
body => "A",
commentable&.title => "B"
}
end

View File

@@ -3,9 +3,9 @@ module Relationable
included do
has_many :related_contents,
as: :parent_relationable,
as: :parent_relationable,
inverse_of: :parent_relationable,
dependent: :destroy
dependent: :destroy
end
def find_related_content(relationable)

View File

@@ -57,15 +57,15 @@ class Debate < ApplicationRecord
end
def searchable_translations_definitions
{ title => "A",
{ title => "A",
description => "D" }
end
def searchable_values
{
author.username => "B",
author.username => "B",
tag_list.join(" ") => "B",
geozone&.name => "B"
geozone&.name => "B"
}.merge!(searchable_globalized_values)
end

View File

@@ -12,8 +12,8 @@ class Legislation::DraftVersion < ApplicationRecord
belongs_to :process, foreign_key: "legislation_process_id", inverse_of: :draft_versions
has_many :annotations,
foreign_key: "legislation_draft_version_id",
inverse_of: :draft_version,
dependent: :destroy
inverse_of: :draft_version,
dependent: :destroy
validates_translation :title, presence: true
validates_translation :body, presence: true

View File

@@ -28,20 +28,20 @@ class Legislation::Process < ApplicationRecord
has_many :draft_versions, -> { order(:id) },
foreign_key: "legislation_process_id",
inverse_of: :process,
dependent: :destroy
inverse_of: :process,
dependent: :destroy
has_one :final_draft_version, -> { where final_version: true, status: "published" },
class_name: "Legislation::DraftVersion",
class_name: "Legislation::DraftVersion",
foreign_key: "legislation_process_id",
inverse_of: :process
inverse_of: :process
has_many :questions, -> { order(:id) },
foreign_key: "legislation_process_id",
inverse_of: :process,
dependent: :destroy
inverse_of: :process,
dependent: :destroy
has_many :proposals, -> { order(:id) },
foreign_key: "legislation_process_id",
inverse_of: :process,
dependent: :destroy
inverse_of: :process,
dependent: :destroy
validates_translation :title, presence: true
validates :start_date, presence: true
@@ -127,8 +127,8 @@ class Legislation::Process < ApplicationRecord
def searchable_translations_definitions
{
title => "A",
summary => "C",
title => "A",
summary => "C",
description => "D"
}
end

View File

@@ -57,12 +57,12 @@ class Legislation::Proposal < ApplicationRecord
end
def searchable_values
{ title => "A",
author.username => "B",
{ title => "A",
author.username => "B",
tag_list.join(" ") => "B",
geozone&.name => "B",
summary => "C",
description => "D" }
geozone&.name => "B",
summary => "C",
description => "D" }
end
def self.search(terms)

View File

@@ -32,17 +32,17 @@ class Officing::Residence
user.update!(verified_at: Time.current)
else
user_params = {
document_number: document_number,
document_type: document_type,
geozone: geozone,
date_of_birth: response_date_of_birth.in_time_zone.to_datetime,
gender: gender,
document_number: document_number,
document_type: document_type,
geozone: geozone,
date_of_birth: response_date_of_birth.in_time_zone.to_datetime,
gender: gender,
residence_verified_at: Time.current,
verified_at: Time.current,
erased_at: Time.current,
password: random_password,
terms_of_service: "1",
email: nil
verified_at: Time.current,
erased_at: Time.current,
password: random_password,
terms_of_service: "1",
email: nil
}
self.user = User.create!(user_params)
end

View File

@@ -205,8 +205,8 @@ class Poll < ApplicationRecord
def searchable_translations_definitions
{
name => "A",
summary => "C",
name => "A",
summary => "C",
description => "D"
}
end

View File

@@ -36,8 +36,8 @@ class Poll::BallotSheet < ApplicationRecord
def create_ballot(poll_ballot)
Budget::Ballot.where(physical: true,
user: nil,
poll_ballot: poll_ballot,
budget: poll.budget).first_or_create!
user: nil,
poll_ballot: poll_ballot,
budget: poll.budget).first_or_create!
end
end

View File

@@ -17,7 +17,7 @@ class Poll::Question < ApplicationRecord
has_many :question_answers, -> { order "given_order asc" },
class_name: "Poll::Question::Answer",
inverse_of: :question,
dependent: :destroy
dependent: :destroy
has_many :partial_results
belongs_to :proposal
@@ -40,9 +40,9 @@ class Poll::Question < ApplicationRecord
end
def searchable_values
{ title => "A",
proposal&.title => "A",
author.username => "C",
{ title => "A",
proposal&.title => "A",
author.username => "C",
author_visible_name => "C" }
end

View File

@@ -28,10 +28,10 @@ class Poll
def create_officer_assignments
booth.booth_assignments.order(:id).each do |booth_assignment|
attrs = {
officer_id: officer_id,
date: date,
officer_id: officer_id,
date: date,
booth_assignment_id: booth_assignment.id,
final: recount_scrutiny?
final: recount_scrutiny?
}
Poll::OfficerAssignment.create!(attrs)
end

View File

@@ -12,10 +12,10 @@ class ProgressBar < ApplicationRecord
validates :progressable, presence: true
validates :kind, presence: true,
uniqueness: {
scope: [:progressable_type, :progressable_id],
conditions: -> { primary }
}
uniqueness: {
scope: [:progressable_type, :progressable_id],
conditions: -> { primary }
}
validates :percentage, presence: true, inclusion: { in: ->(*) { RANGE }}, numericality: { only_integer: true }
validates_translation :title, presence: true, unless: :primary?

View File

@@ -118,16 +118,16 @@ class Proposal < ApplicationRecord
end
def searchable_translations_definitions
{ title => "A",
summary => "C",
{ title => "A",
summary => "C",
description => "D" }
end
def searchable_values
{
author.username => "B",
tag_list.join(" ") => "B",
geozone&.name => "B"
author.username => "B",
tag_list.join(" ") => "B",
geozone&.name => "B"
}.merge!(searchable_globalized_values)
end

View File

@@ -59,7 +59,7 @@ class ProposalNotification < ApplicationRecord
def searchable_values
{
title => "A",
body => "B"
body => "B"
}
end

View File

@@ -9,7 +9,7 @@ class SDG::LocalTarget < ApplicationRecord
validates_translation :description, presence: true
validates :code, presence: true, uniqueness: true,
format: ->(local_target) { /\A#{local_target.target&.code}\.\d+/ }
format: ->(local_target) { /\A#{local_target.target&.code}\.\d+/ }
validates :target, presence: true
validates :goal, presence: true

View File

@@ -61,18 +61,18 @@ class Setting < ApplicationRecord
def mime_types
{
"images" => {
"jpg" => "image/jpeg",
"png" => "image/png",
"gif" => "image/gif"
"jpg" => "image/jpeg",
"png" => "image/png",
"gif" => "image/gif"
},
"documents" => {
"pdf" => "application/pdf",
"doc" => "application/msword",
"pdf" => "application/pdf",
"doc" => "application/msword",
"docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"xls" => "application/x-ole-storage",
"xls" => "application/x-ole-storage",
"xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"csv" => "text/plain",
"zip" => "application/zip"
"csv" => "text/plain",
"zip" => "application/zip"
}
}
end

View File

@@ -26,55 +26,55 @@ class User < ApplicationRecord
has_many :proposals, -> { with_hidden }, foreign_key: :author_id, inverse_of: :author
has_many :activities
has_many :budget_investments, -> { with_hidden },
class_name: "Budget::Investment",
class_name: "Budget::Investment",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :comments, -> { with_hidden }, inverse_of: :user
has_many :failed_census_calls
has_many :notifications
has_many :direct_messages_sent,
class_name: "DirectMessage",
class_name: "DirectMessage",
foreign_key: :sender_id,
inverse_of: :sender
inverse_of: :sender
has_many :direct_messages_received,
class_name: "DirectMessage",
class_name: "DirectMessage",
foreign_key: :receiver_id,
inverse_of: :receiver
inverse_of: :receiver
has_many :legislation_answers, class_name: "Legislation::Answer", dependent: :destroy, inverse_of: :user
has_many :follows
has_many :legislation_annotations,
class_name: "Legislation::Annotation",
class_name: "Legislation::Annotation",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :legislation_proposals,
class_name: "Legislation::Proposal",
class_name: "Legislation::Proposal",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :legislation_questions,
class_name: "Legislation::Question",
class_name: "Legislation::Question",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :polls, foreign_key: :author_id, inverse_of: :author
has_many :poll_answers,
class_name: "Poll::Answer",
class_name: "Poll::Answer",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :poll_pair_answers,
class_name: "Poll::PairAnswer",
class_name: "Poll::PairAnswer",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :poll_partial_results,
class_name: "Poll::PartialResult",
class_name: "Poll::PartialResult",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :poll_questions,
class_name: "Poll::Question",
class_name: "Poll::Question",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :poll_recounts,
class_name: "Poll::Recount",
class_name: "Poll::Recount",
foreign_key: :author_id,
inverse_of: :author
inverse_of: :author
has_many :related_contents, foreign_key: :author_id, inverse_of: :author, dependent: nil
has_many :topics, foreign_key: :author_id, inverse_of: :author
belongs_to :geozone
@@ -136,7 +136,7 @@ class User < ApplicationRecord
oauth_user = User.find_by(email: oauth_email) if oauth_email_confirmed
oauth_user || User.new(
username: auth.info.name || auth.uid,
username: auth.info.name || auth.uid,
email: oauth_email,
oauth_email: oauth_email,
password: Devise.friendly_token[0, 20],

View File

@@ -3,7 +3,7 @@ class Verification::Management::ManagedUser
def self.find(document_type, document_number)
User.where.not(document_number: nil)
.find_or_initialize_by(document_type: document_type,
document_number: document_number)
.find_or_initialize_by(document_type: document_type,
document_number: document_number)
end
end

View File

@@ -29,11 +29,11 @@ class Verification::Residence
user.take_votes_if_erased_document(document_number, document_type)
user.update(document_number: document_number,
document_type: document_type,
geozone: geozone,
date_of_birth: date_of_birth.in_time_zone.to_datetime,
gender: gender,
user.update(document_number: document_number,
document_type: document_type,
geozone: geozone,
date_of_birth: date_of_birth.in_time_zone.to_datetime,
gender: gender,
residence_verified_at: Time.current)
end