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

@@ -64,6 +64,13 @@ Layout/FirstArrayElementIndentation:
Enabled: true
EnforcedStyle: consistent
Layout/FirstHashElementIndentation:
Enabled: true
EnforcedStyle: consistent
Layout/HashAlignment:
Enabled: true
Layout/HeredocIndentation:
Enabled: true
@@ -92,6 +99,12 @@ Layout/MultilineArrayBraceLayout:
Layout/MultilineBlockLayout:
Enabled: true
Layout/MultilineHashBraceLayout:
Enabled: true
Layout/MultilineHashKeyLineBreaks:
Enabled: true
Layout/SpaceAfterColon:
Enabled: true

View File

@@ -1,6 +1,7 @@
<% if user %>
<li id="notifications">
<%= link_to notifications_path, rel: "nofollow", title: text,
<%= link_to notifications_path, rel: "nofollow",
title: text,
class: "notifications #{notifications_class}" do %>
<span class="show-for-sr">
<%= t("layouts.header.notification_item.notifications") %>

View File

@@ -37,8 +37,10 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BudgetsWizard::BaseContro
end
def allowed_params
valid_attributes = [:currency_symbol, :voting_style, :hide_money, administrator_ids: [],
valuator_ids: [], image_attributes: image_attributes]
valid_attributes = [:currency_symbol, :voting_style, :hide_money,
administrator_ids: [],
valuator_ids: [],
image_attributes: image_attributes]
[*valid_attributes, translation_params(Budget)]
end

View File

@@ -30,7 +30,8 @@ class Dashboard::ActionsController < Dashboard::BaseController
def execute
authorize! :dashboard, proposal
Dashboard::ExecutedAction.create(proposal: proposal, action: dashboard_action,
Dashboard::ExecutedAction.create(proposal: proposal,
action: dashboard_action,
executed_at: Time.current)
redirect_to request.referer
end

View File

@@ -203,7 +203,8 @@ class Budget
end
def searchable_values
{ author.username => "B",
{
author.username => "B",
heading.name => "B",
tag_list.join(" ") => "B"
}.merge(searchable_globalized_values)

View File

@@ -44,17 +44,20 @@
<div class="row expanded margin-top">
<div class="small-12 medium-4 column">
<%= f.number_field :day_offset, step: 1, min: 0,
<%= f.number_field :day_offset, step: 1,
min: 0,
hint: t("admin.dashboard.actions.form.help_text") %>
</div>
<div class="small-12 medium-4 column">
<%= f.number_field :required_supports, step: 1, min: 0,
<%= f.number_field :required_supports, step: 1,
min: 0,
hint: t("admin.dashboard.actions.form.help_text") %>
</div>
<div class="small-12 medium-4 column">
<%= f.number_field :order, step: 1, min: 0,
<%= f.number_field :order, step: 1,
min: 0,
hint: t("admin.dashboard.actions.form.help_text") %>
</div>
</div>

View File

@@ -1,8 +1,11 @@
<%= render "shared/globalize_locales", resource: @draft_version %>
<%= translatable_form_for [:admin, @process, @draft_version], url: url,
html: { data: { markdown_changes_message: I18n.t("admin.legislation.draft_versions.edit.markdown_changes_message") }} do |f| %>
html: {
data: {
markdown_changes_message: I18n.t("admin.legislation.draft_versions.edit.markdown_changes_message")
}
} do |f| %>
<%= render "shared/errors", resource: @draft_version %>
<div class="row">
@@ -50,7 +53,8 @@
</div>
<div class="small-12 medium-6 column markdown-area">
<%= translations_form.text_area :body, label: false, rows: 10,
<%= translations_form.text_area :body, label: false,
rows: 10,
class: "legislation-draft-version-body" %>
</div>

View File

@@ -21,7 +21,8 @@
</div>
<div class="small-12 medium-6 column">
<%= f.text_field :slug, size: 80, maxlength: 80,
<%= f.text_field :slug, size: 80,
maxlength: 80,
hint: sanitize(t("admin.site_customization.pages.new.slug_help")) %>
</div>
</div>

View File

@@ -24,7 +24,8 @@
<% end %>
</div>
<%= form_for poll, remote: true, data: { type: :json },
<%= form_for poll, remote: true,
data: { type: :json },
url: proposal_dashboard_poll_path(proposal, poll) do |f| %>
<%= f.check_box :results_enabled, class: "js-submit-on-change" %>
<% end %>

View File

@@ -6,7 +6,8 @@
<%= f.hidden_field :reset_password_token %>
<div class="field">
<%= f.password_field :password, autofocus: true, autocomplete: "off",
<%= f.password_field :password, autofocus: true,
autocomplete: "off",
label: t("devise_views.passwords.edit.password_label") %>
</div>

View File

@@ -1,7 +1,9 @@
<li id="<%= dom_id(document) %>">
<%= link_to t("documents.buttons.download_document"),
document.attachment, target: "_blank",
rel: "nofollow", class: "button hollow medium float-right" %>
document.attachment,
target: "_blank",
rel: "nofollow",
class: "button hollow medium float-right" %>
<strong><%= document.title %></strong>
<br>

View File

@@ -24,7 +24,8 @@
<%= link_to t("management.users.create_user"),
new_management_user_path(user: {
document_number: @email_verification.document_number,
document_type: @email_verification.document_type }),
document_type: @email_verification.document_type
}),
class: "button success" %>
</p>
</li>

View File

@@ -6,7 +6,8 @@
</h1>
<%= link_to t("notifications.index.mark_all_as_read"),
mark_all_as_read_notifications_path, method: :put,
mark_all_as_read_notifications_path,
method: :put,
class: "button hollow float-right-medium" %>
<ul class="menu simple clear">

View File

@@ -4,8 +4,10 @@
</p>
</td>
<td id="actions" class="text-center">
<%= form_for @user, as: :voter, url: officing_voters_path,
method: :post, remote: true,
<%= form_for @user, as: :voter,
url: officing_voters_path,
method: :post,
remote: true,
html: { id: "new_officing_voter" } do |f| %>
<%= f.hidden_field :poll_id, value: poll.id %>
<%= f.hidden_field :user_id, value: @user.id %>

View File

@@ -32,7 +32,8 @@
class: "button hollow expanded" %>
<%= link_to t("community.show.topic.destroy"),
community_topic_path(@community.id, @topic), method: :delete,
community_topic_path(@community.id, @topic),
method: :delete,
class: "button hollow expanded alert" %>
</aside>
<% end %>

View File

@@ -3,7 +3,7 @@ devise_for :users, controllers: {
sessions: "users/sessions",
confirmations: "users/confirmations",
omniauth_callbacks: "users/omniauth_callbacks"
}
}
devise_scope :user do
patch "/user/confirmation", to: "users/confirmations#update", as: :update_user_confirmation

View File

@@ -35,44 +35,57 @@ section "Creating Users" do
manager = create_user("manager@consul.dev", "manager")
manager.create_manager
manager.update!(residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1",
verified_at: Time.current, document_number: unique_document_number)
confirmed_phone: Faker::PhoneNumber.phone_number,
document_type: "1",
verified_at: Time.current,
document_number: unique_document_number)
valuator = create_user("valuator@consul.dev", "valuator")
valuator.create_valuator
valuator.update!(residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1",
verified_at: Time.current, document_number: unique_document_number)
confirmed_phone: Faker::PhoneNumber.phone_number,
document_type: "1",
verified_at: Time.current,
document_number: unique_document_number)
poll_officer = create_user("poll_officer@consul.dev", "Paul O. Fisher")
poll_officer.create_poll_officer
poll_officer.update!(residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1",
verified_at: Time.current, document_number: unique_document_number)
confirmed_phone: Faker::PhoneNumber.phone_number,
document_type: "1",
verified_at: Time.current,
document_number: unique_document_number)
poll_officer2 = create_user("poll_officer2@consul.dev", "Pauline M. Espinosa")
poll_officer2.create_poll_officer
poll_officer2.update!(residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1",
verified_at: Time.current, document_number: unique_document_number)
confirmed_phone: Faker::PhoneNumber.phone_number,
document_type: "1",
verified_at: Time.current,
document_number: unique_document_number)
sdg_manager = create_user("sdg_manager@consul.dev", "SDG manager")
sdg_manager.create_sdg_manager
sdg_manager.update!(residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1",
verified_at: Time.current, document_number: unique_document_number)
confirmed_phone: Faker::PhoneNumber.phone_number,
document_type: "1",
verified_at: Time.current,
document_number: unique_document_number)
create_user("unverified@consul.dev", "unverified")
level_2 = create_user("leveltwo@consul.dev", "level 2")
level_2.update!(residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number,
document_number: unique_document_number, document_type: "1")
document_number: unique_document_number,
document_type: "1")
verified = create_user("verified@consul.dev", "verified")
verified.update!(residence_verified_at: Time.current,
confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1",
verified_at: Time.current, document_number: unique_document_number)
confirmed_phone: Faker::PhoneNumber.phone_number,
document_type: "1",
verified_at: Time.current,
document_number: unique_document_number)
[
I18n.t("seeds.organizations.neighborhood_association"),

View File

@@ -10,8 +10,10 @@ describe "rake db:seed" do
SiteCustomization::Page.destroy_all
load Rails.root.join("db", "pages.rb")
paths = { accessibility: "pages.accessibility.title", conditions: "pages.conditions.title",
faq: "pages.help.faq.page.title", privacy: "pages.privacy.title",
paths = { accessibility: "pages.accessibility.title",
conditions: "pages.conditions.title",
faq: "pages.help.faq.page.title",
privacy: "pages.privacy.title",
welcome_not_verified: "welcome.welcome.title",
welcome_level_two_verified: "welcome.welcome.title",
welcome_level_three_verified: "welcome.welcome.title" }

View File

@@ -522,17 +522,23 @@ describe MachineLearning do
machine_learning = MachineLearning.new(job)
tags_data = [
{ id: 0,
name: "Existing tag" },
{ id: 1,
name: "Machine learning tag" }
{
id: 0,
name: "Existing tag"
},
{
id: 1,
name: "Machine learning tag"
}
]
taggings_data = [
{ tag_id: 0,
{
tag_id: 0,
taggable_id: proposal.id
},
{ tag_id: 1,
{
tag_id: 1,
taggable_id: proposal.id
}
]
@@ -564,17 +570,23 @@ describe MachineLearning do
machine_learning = MachineLearning.new(job)
tags_data = [
{ id: 0,
name: "Existing tag" },
{ id: 1,
name: "Machine learning tag" }
{
id: 0,
name: "Existing tag"
},
{
id: 1,
name: "Machine learning tag"
}
]
taggings_data = [
{ tag_id: 0,
{
tag_id: 0,
taggable_id: investment.id
},
{ tag_id: 1,
{
tag_id: 1,
taggable_id: investment.id
}
]

View File

@@ -104,44 +104,51 @@ describe Poll do
it "is valid when overlapping but different proposals" do
other_proposal = create(:proposal)
_other_poll = create(:poll, related: other_proposal, starts_at: poll.starts_at,
_other_poll = create(:poll, related: other_proposal,
starts_at: poll.starts_at,
ends_at: poll.ends_at)
expect(poll).to be_valid
end
it "is valid when same proposal but not overlapping" do
_other_poll = create(:poll, related: proposal, starts_at: poll.ends_at + 1.day,
_other_poll = create(:poll, related: proposal,
starts_at: poll.ends_at + 1.day,
ends_at: poll.ends_at + 8.days)
expect(poll).to be_valid
end
it "is not valid when overlaps from the beginning" do
_other_poll = create(:poll, related: proposal, starts_at: poll.starts_at - 8.days,
_other_poll = create(:poll, related: proposal,
starts_at: poll.starts_at - 8.days,
ends_at: poll.starts_at)
expect(poll).not_to be_valid
end
it "is not valid when overlaps from the end" do
_other_poll = create(:poll, related: proposal, starts_at: poll.ends_at,
_other_poll = create(:poll, related: proposal,
starts_at: poll.ends_at,
ends_at: poll.ends_at + 8.days)
expect(poll).not_to be_valid
end
it "is not valid when overlaps with same interval" do
_other_poll = create(:poll, related: proposal, starts_at: poll.starts_at,
_other_poll = create(:poll, related: proposal,
starts_at: poll.starts_at,
ends_at: poll.ends_at)
expect(poll).not_to be_valid
end
it "is not valid when overlaps with interval contained" do
_other_poll = create(:poll, related: proposal, starts_at: poll.starts_at + 1.day,
_other_poll = create(:poll, related: proposal,
starts_at: poll.starts_at + 1.day,
ends_at: poll.ends_at - 1.day)
expect(poll).not_to be_valid
end
it "is not valid when overlaps with interval containing" do
_other_poll = create(:poll, related: proposal, starts_at: poll.starts_at - 8.days,
_other_poll = create(:poll, related: proposal,
starts_at: poll.starts_at - 8.days,
ends_at: poll.ends_at + 8.days)
expect(poll).not_to be_valid
end

View File

@@ -19,7 +19,9 @@ describe Poll::Stats do
it "supports every channel" do
3.times { create(:poll_voter, :from_web, poll: poll) }
create(:poll_recount, :from_booth, poll: poll,
total_amount: 8, white_amount: 4, null_amount: 1)
total_amount: 8,
white_amount: 4,
null_amount: 1)
expect(stats.total_participants_web).to eq(3)
expect(stats.total_participants_booth).to eq(13)
@@ -153,7 +155,9 @@ describe Poll::Stats do
it "is relative to the total amount of votes" do
3.times { create(:poll_voter, :from_web, poll: poll) }
create(:poll_recount, :from_booth, poll: poll,
total_amount: 8, white_amount: 5, null_amount: 4)
total_amount: 8,
white_amount: 5,
null_amount: 4)
expect(stats.total_valid_percentage).to eq(50)
expect(stats.total_white_percentage).to eq(30)

View File

@@ -67,7 +67,8 @@ describe "Admin budget investments", :admin do
admin = create(:administrator, user: create(:user, username: "Gema"))
budget_investment1 = create(:budget_investment, budget: budget, valuators: [valuator1])
budget_investment2 = create(:budget_investment, budget: budget, valuators: [valuator1, valuator2],
budget_investment2 = create(:budget_investment, budget: budget,
valuators: [valuator1, valuator2],
valuator_groups: [valuator_group])
budget_investment3 = create(:budget_investment, budget: budget)
@@ -147,7 +148,8 @@ describe "Admin budget investments", :admin do
administrator = create(:administrator, user: user)
administrator2 = create(:administrator, user: user2, description: "Alias")
budget.administrators = [administrator, administrator2]
create(:budget_investment, title: "Realocate visitors", budget: budget,
create(:budget_investment, title: "Realocate visitors",
budget: budget,
administrator: administrator)
create(:budget_investment, title: "Destroy the city", budget: budget)
@@ -400,7 +402,8 @@ describe "Admin budget investments", :admin do
scenario "Filtering by assignment status" do
create(:budget_investment, :with_administrator, title: "Assigned idea", budget: budget)
create(:budget_investment, :with_valuator, title: "Evaluating...", budget: budget)
create(:budget_investment, title: "With group", budget: budget,
create(:budget_investment, title: "With group",
budget: budget,
valuator_groups: [create(:valuator_group)])
visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "valuation_open")
@@ -613,7 +616,8 @@ describe "Admin budget investments", :admin do
administrator = create(:administrator, user: user)
budget.administrators = [administrator]
educate_children = create(:budget_investment, budget: budget, title: "Educate the children",
educate_children = create(:budget_investment, budget: budget,
title: "Educate the children",
administrator: administrator)
create(:budget_investment, budget: budget, title: "More schools",
administrator: administrator)
@@ -686,7 +690,8 @@ describe "Admin budget investments", :admin do
educate_children = create(:budget_investment, :feasible, :finished,
budget: budget, title: "Educate the children", administrator: administrator)
create(:budget_investment, :feasible, :finished, budget: budget, title: "More schools",
create(:budget_investment, :feasible, :finished, budget: budget,
title: "More schools",
administrator: administrator)
create(:budget_investment, budget: budget, title: "More hospitals",
administrator: administrator)

View File

@@ -452,7 +452,8 @@ describe "Admin budgets", :admin do
scenario "For a Budget in reviewing balloting" do
budget = create(:budget, :reviewing_ballots)
heading = create(:budget_heading, budget: budget, price: 4)
unselected = create(:budget_investment, :unselected, heading: heading, price: 1,
unselected = create(:budget_investment, :unselected, heading: heading,
price: 1,
ballot_lines_count: 3)
winner = create(:budget_investment, :selected, heading: heading, price: 3,
ballot_lines_count: 2)

View File

@@ -154,12 +154,14 @@ describe "Proposal's dashboard" do
requested = create(:dashboard_action, :resource, :admin_request, :active)
executed_action = create(:dashboard_executed_action, action: requested,
proposal: proposal, executed_at: Time.current)
proposal: proposal,
executed_at: Time.current)
_task = create(:dashboard_administrator_task, :pending, source: executed_action)
solved = create(:dashboard_action, :resource, :admin_request, :active)
executed_solved_action = create(:dashboard_executed_action, action: solved,
proposal: proposal, executed_at: Time.current)
proposal: proposal,
executed_at: Time.current)
_solved_task = create(:dashboard_administrator_task, :done, source: executed_solved_action)
unavailable = create(:dashboard_action, :resource, :active,
@@ -199,12 +201,14 @@ describe "Proposal's dashboard" do
requested = create(:dashboard_action, :resource, :admin_request, :active)
executed_action = create(:dashboard_executed_action, action: requested,
proposal: proposal, executed_at: Time.current)
proposal: proposal,
executed_at: Time.current)
_task = create(:dashboard_administrator_task, :pending, source: executed_action)
solved = create(:dashboard_action, :resource, :admin_request, :active)
executed_solved_action = create(:dashboard_executed_action, action: solved,
proposal: proposal, executed_at: Time.current)
proposal: proposal,
executed_at: Time.current)
_solved_task = create(:dashboard_administrator_task, :done, source: executed_solved_action)
unavailable = create(:dashboard_action, :resource, :active,

View File

@@ -202,7 +202,8 @@ describe "Valuation budget investments" do
create(:valuator, user: create(:user, username: "Rick", email: "rick@valuators.org"))
end
let(:investment) do
create(:budget_investment, :unfeasible, budget: budget, price: 1234,
create(:budget_investment, :unfeasible, budget: budget,
price: 1234,
unfeasibility_explanation: "It is impossible",
administrator: administrator,
valuators: [valuator, second_valuator])