From 8979472820046cc5ab77bf9a0dd8930c6751b80c Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 9 Mar 2021 15:39:14 +0000 Subject: [PATCH 1/6] Bump rubocop from 0.91.1 to 0.93.1 Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.91.1 to 0.93.1. - [Release notes](https://github.com/rubocop-hq/rubocop/releases) - [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.91.1...v0.93.1) Signed-off-by: dependabot-preview[bot] --- Gemfile | 2 +- Gemfile.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 7dae10e44..8136dc0b6 100644 --- a/Gemfile +++ b/Gemfile @@ -107,7 +107,7 @@ group :development do gem "pronto-eslint", "~> 0.11.0", require: false gem "pronto-rubocop", "~> 0.11.1", require: false gem "pronto-scss", "~> 0.11.0", require: false - gem "rubocop", "~> 0.91.0", require: false + gem "rubocop", "~> 0.93.1", require: false gem "rubocop-performance", "~> 1.7.1", require: false gem "rubocop-rails", "~> 2.6.0", require: false gem "rubocop-rspec", "~> 1.44.1", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 851473d3b..194a1677b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -542,17 +542,17 @@ GEM rspec-mocks (~> 3.9) rspec-support (~> 3.9) rspec-support (3.9.3) - rubocop (0.91.1) + rubocop (0.93.1) parallel (~> 1.10) - parser (>= 2.7.1.1) + parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8) rexml - rubocop-ast (>= 0.4.0, < 1.0) + rubocop-ast (>= 0.6.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (0.8.0) - parser (>= 2.7.1.5) + rubocop-ast (1.9.0) + parser (>= 3.0.1.1) rubocop-performance (1.7.1) rubocop (>= 0.82.0) rubocop-rails (2.6.0) @@ -770,7 +770,7 @@ DEPENDENCIES rinku (~> 2.0.6) rollbar (~> 3.0.1) rspec-rails (~> 4.0) - rubocop (~> 0.91.0) + rubocop (~> 0.93.1) rubocop-performance (~> 1.7.1) rubocop-rails (~> 2.6.0) rubocop-rspec (~> 1.44.1) From 57d8a59d10e2ec18e3f266bf09a9ea67380ee335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 9 Aug 2021 17:32:45 +0200 Subject: [PATCH 2/6] Add an apply Style/RaiseArgs rubocop rule We were already applying it most of the time. --- .rubocop.yml | 3 +++ app/controllers/management/base_controller.rb | 2 +- app/controllers/users/omniauth_callbacks_controller.rb | 2 +- app/controllers/valuation/budget_investments_controller.rb | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8c19663df..42ebe443e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -449,6 +449,9 @@ Style/PercentLiteralDelimiters: Style/Proc: Enabled: true +Style/RaiseArgs: + Enabled: true + Style/RedundantFileExtensionInRequire: Enabled: true diff --git a/app/controllers/management/base_controller.rb b/app/controllers/management/base_controller.rb index 5bba8fcad..f9e88ed55 100644 --- a/app/controllers/management/base_controller.rb +++ b/app/controllers/management/base_controller.rb @@ -13,7 +13,7 @@ class Management::BaseController < ActionController::Base private def verify_manager - raise ActionController::RoutingError.new("Not Found") if current_manager.blank? + raise ActionController::RoutingError, "Not Found" if current_manager.blank? end def current_manager diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index f5b5350b8..02186e9e9 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -26,7 +26,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController private def sign_in_with(feature, provider) - raise ActionController::RoutingError.new("Not Found") unless Setting["feature.#{feature}"] + raise ActionController::RoutingError, "Not Found" unless Setting["feature.#{feature}"] auth = request.env["omniauth.auth"] diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index e9cd4f21e..475b91b68 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -105,7 +105,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController def restrict_access unless current_user.administrator? || current_budget.valuating? - raise CanCan::AccessDenied.new(I18n.t("valuation.budget_investments.not_in_valuating_phase")) + raise CanCan::AccessDenied, I18n.t("valuation.budget_investments.not_in_valuating_phase") end end @@ -114,7 +114,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController Budget::ValuatorAssignment.exists?(investment_id: params[:id], valuator_id: current_user.valuator.id) - raise ActionController::RoutingError.new("Not Found") + raise ActionController::RoutingError, "Not Found" end def valid_price_params? From 4e3366405533f177f4270c9113e617a9418c8457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 9 Aug 2021 18:54:44 +0200 Subject: [PATCH 3/6] Add and apply Lint/BooleanSymbol rubocop rule --- .rubocop.yml | 3 +++ ...190108133246_add_published_proposal_to_dashboard_actions.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 42ebe443e..d4e0a52e8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -172,6 +172,9 @@ Layout/TrailingWhitespace: Lint/AmbiguousRegexpLiteral: Enabled: true +Lint/BooleanSymbol: + Enabled: true + Lint/ConstantDefinitionInBlock: Enabled: true diff --git a/db/migrate/20190108133246_add_published_proposal_to_dashboard_actions.rb b/db/migrate/20190108133246_add_published_proposal_to_dashboard_actions.rb index a777aa4d7..433669d9b 100644 --- a/db/migrate/20190108133246_add_published_proposal_to_dashboard_actions.rb +++ b/db/migrate/20190108133246_add_published_proposal_to_dashboard_actions.rb @@ -1,5 +1,5 @@ class AddPublishedProposalToDashboardActions < ActiveRecord::Migration[4.2] def change - add_column :dashboard_actions, :published_proposal, :boolean, default: :false + add_column :dashboard_actions, :published_proposal, :boolean, default: false end end From a102f3f0a706525ea9f1af2c24c287d6d35c5ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 9 Aug 2021 19:11:28 +0200 Subject: [PATCH 4/6] Add and apply Style/ExplicitBlockArgument rule We were already applying it in most places. --- app/helpers/globalize_helper.rb | 6 ++---- app/helpers/translatable_form_helper.rb | 12 ++++-------- app/mailers/mailer.rb | 6 ++---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/helpers/globalize_helper.rb b/app/helpers/globalize_helper.rb index f9bedca9f..13e9ec3d4 100644 --- a/app/helpers/globalize_helper.rb +++ b/app/helpers/globalize_helper.rb @@ -130,9 +130,7 @@ module GlobalizeHelper hidden_field_tag("enabled_translations[#{locale}]", (enabled ? 1 : 0)) end - def globalize(locale) - Globalize.with_locale(locale) do - yield - end + def globalize(locale, &block) + Globalize.with_locale(locale, &block) end end diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index 1cc3014b3..fea9b04ef 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -1,8 +1,6 @@ module TranslatableFormHelper - def translatable_form_for(record, options = {}) - form_for(record, options.merge(builder: TranslatableFormBuilder)) do |f| - yield(f) - end + def translatable_form_for(record, options = {}, &block) + form_for(record, options.merge(builder: TranslatableFormBuilder), &block) end def translations_interface_enabled? @@ -48,10 +46,8 @@ module TranslatableFormHelper end end - def fields_for_translation(translation) - fields_for(:translations, translation, builder: TranslationsFieldsBuilder) do |f| - yield f - end + def fields_for_translation(translation, &block) + fields_for(:translations, translation, builder: TranslationsFieldsBuilder, &block) end def translation_for(locale) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index f1cf3f0db..0c0f8ebfe 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -129,10 +129,8 @@ class Mailer < ApplicationMailer private - def with_user(user) - I18n.with_locale(user.locale) do - yield - end + def with_user(user, &block) + I18n.with_locale(user.locale, &block) end def prevent_delivery_to_users_without_email From 99bbad9b1ed111707d29c7cff976f9712246a0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 9 Aug 2021 19:20:07 +0200 Subject: [PATCH 5/6] Add and apply Style/RedundantCondition rule This is a rule we generally follow all the time but accidentally forgot in one place. --- .rubocop.yml | 3 +++ app/helpers/welcome_helper.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index d4e0a52e8..2a0845b42 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -455,6 +455,9 @@ Style/Proc: Style/RaiseArgs: Enabled: true +Style/RedundantCondition: + Enabled: true + Style/RedundantFileExtensionInRequire: Enabled: true diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 85cc2dd33..5962ff682 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -34,7 +34,7 @@ module WelcomeHelper def calculate_carousel_size(debates, proposals, apply_offset) offset = calculate_offset(debates, proposals, apply_offset) centered = calculate_centered(debates, proposals) - "#{offset if offset} #{centered if centered}" + "#{offset} #{centered}" end def calculate_centered(debates, proposals) From 469b39ffa37d2068bc7b7b2eba8ac4c5894f686e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 9 Aug 2021 19:26:32 +0200 Subject: [PATCH 6/6] Add and apply Style/RedundantInterpolation rule Somehow I thought we already had this rule; must have forgotten to actually add it. --- .rubocop.yml | 3 +++ app/helpers/milestones_helper.rb | 2 +- config/initializers/i18n_pluralize.rb | 2 +- spec/mailers/dashboard/mailer_spec.rb | 12 ++++++------ spec/shared/system/relationable.rb | 4 ++-- spec/system/admin/poll/polls_spec.rb | 2 +- spec/system/admin/users_spec.rb | 4 ++-- spec/system/budget_polls/ballot_sheets_spec.rb | 8 ++++---- spec/system/legislation/processes_spec.rb | 2 +- 9 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2a0845b42..26a1f499a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -464,6 +464,9 @@ Style/RedundantFileExtensionInRequire: Style/RedundantFreeze: Enabled: true +Style/RedundantInterpolation: + Enabled: true + Style/RedundantReturn: Enabled: true diff --git a/app/helpers/milestones_helper.rb b/app/helpers/milestones_helper.rb index aa4883a7f..888955e4e 100644 --- a/app/helpers/milestones_helper.rb +++ b/app/helpers/milestones_helper.rb @@ -4,7 +4,7 @@ module MilestonesHelper tag.div class: "progress", role: "progressbar", - "aria-valuenow": "#{progress_bar.percentage}", + "aria-valuenow": progress_bar.percentage, "aria-valuetext": "#{progress_bar.percentage}%", "aria-valuemax": ProgressBar::RANGE.max, "aria-valuemin": "0", diff --git a/config/initializers/i18n_pluralize.rb b/config/initializers/i18n_pluralize.rb index 240310a2c..71415d49e 100644 --- a/config/initializers/i18n_pluralize.rb +++ b/config/initializers/i18n_pluralize.rb @@ -9,7 +9,7 @@ module I18n return entry unless entry.is_a?(Hash) && count key = pluralization_key(entry, count) - return "#{count}" unless entry.has_key?(key) + return count.to_s unless entry.has_key?(key) entry[key] end diff --git a/spec/mailers/dashboard/mailer_spec.rb b/spec/mailers/dashboard/mailer_spec.rb index 5c9315b6a..7a2d2a3b2 100644 --- a/spec/mailers/dashboard/mailer_spec.rb +++ b/spec/mailers/dashboard/mailer_spec.rb @@ -90,10 +90,10 @@ describe Dashboard::Mailer do expect(email).to have_body_text("And to accompany you in this challenge, "\ "here are the news...") expect(email).to have_body_text("NEW UNLOCKED RESOURCE") - expect(email).to have_body_text("#{resource.title}") + expect(email).to have_body_text(resource.title) expect(email).to have_body_text("Take a look at this NEW recommended ACTION:") - expect(email).to have_body_text("#{action.title}") - expect(email).to have_body_text("#{action.description}") + expect(email).to have_body_text(action.title) + expect(email).to have_body_text(action.description) expect(email).to have_body_text("As always, enter the Proposals Panel and we will tell "\ "you in detail how to use these resources and how to get "\ "the most out of it.") @@ -128,7 +128,7 @@ describe Dashboard::Mailer do expect(email).to have_body_text("And so, you have a new resource available to help "\ "you keep moving forward.") expect(email).to have_body_text("NEW UNLOCKED RESOURCE") - expect(email).to have_body_text("#{resource.title}") + expect(email).to have_body_text(resource.title) months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i.months limit_to_archive_proposal = proposal.created_at.to_date + months_to_archive_proposals @@ -139,8 +139,8 @@ describe Dashboard::Mailer do "supports and goes to referendum. Cheer up and keep "\ "spreading. Are you short of ideas?") expect(email).to have_body_text("NEW RECOMMENDED DIFFUSION ACTION") - expect(email).to have_body_text("#{action.title}") - expect(email).to have_body_text("#{action.description}") + expect(email).to have_body_text(action.title) + expect(email).to have_body_text(action.description) expect(email).to have_body_text("As always, enter the Proposals Panel and we will tell "\ "you in detail how to use these resources and how to get "\ "the most out of it.") diff --git a/spec/shared/system/relationable.rb b/spec/shared/system/relationable.rb index f2a07da85..7932f46bb 100644 --- a/spec/shared/system/relationable.rb +++ b/spec/shared/system/relationable.rb @@ -36,7 +36,7 @@ shared_examples "relationable" do |relationable_model_name| expect(page).to have_css ".add-related-content[aria-expanded='true']" within("#related_content") do - fill_in "Link to related content", with: "#{url + related1.url}" + fill_in "Link to related content", with: "#{url}#{related1.url}" click_button "Add" end @@ -53,7 +53,7 @@ shared_examples "relationable" do |relationable_model_name| click_button "Add related content" within("#related_content") do - fill_in "Link to related content", with: "#{url + related2.url}" + fill_in "Link to related content", with: "#{url}#{related2.url}" click_button "Add" end diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index 2e0ad9f77..cc762e41a 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -293,7 +293,7 @@ describe "Admin polls", :admin do within("#totals") do within("#total_final") do - expect(page).to have_content("#{55555 + 63}") + expect(page).to have_content(55555 + 63) end within("#total_system") do diff --git a/spec/system/admin/users_spec.rb b/spec/system/admin/users_spec.rb index a63b8fda0..22fd13272 100644 --- a/spec/system/admin/users_spec.rb +++ b/spec/system/admin/users_spec.rb @@ -29,13 +29,13 @@ describe "Admin users" do visit admin_users_path - expect(page).not_to have_link("#{erased_user.id}", href: user_path(erased_user)) + expect(page).not_to have_link(erased_user.id.to_s, href: user_path(erased_user)) expect(page).to have_link("Erased") click_link "Erased" expect(page).to have_link("Active") - expect(page).to have_link("#{erased_user.id}", href: user_path(erased_user)) + expect(page).to have_link(erased_user.id.to_s, href: user_path(erased_user)) expect(page).to have_content "I don't like this site." expect(page).to have_content("Erased") diff --git a/spec/system/budget_polls/ballot_sheets_spec.rb b/spec/system/budget_polls/ballot_sheets_spec.rb index 3526b4adc..91c6aab56 100644 --- a/spec/system/budget_polls/ballot_sheets_spec.rb +++ b/spec/system/budget_polls/ballot_sheets_spec.rb @@ -26,7 +26,7 @@ describe "Poll budget ballot sheets" do end within("#poll_#{poll.id}") do - expect(page).to have_content("#{poll.name}") + expect(page).to have_content(poll.name) expect(page).to have_content("See ballot sheets list") expect(page).to have_content("Add results") end @@ -51,7 +51,7 @@ describe "Poll budget ballot sheets" do visit officing_poll_ballot_sheets_path(poll) - expect(page).to have_content "#{poll.name}" + expect(page).to have_content poll.name end scenario "Access ballot sheets officing with multiple booth assignments", :with_frozen_time do @@ -103,7 +103,7 @@ describe "Poll budget ballot sheets" do scenario "Ballot sheet is saved" do visit new_officing_poll_ballot_sheet_path(poll) - select "#{booth.name}", from: "officer_assignment_id" + select booth.name, from: "officer_assignment_id" fill_in "data", with: "1234;5678" click_button "Save" @@ -119,7 +119,7 @@ describe "Poll budget ballot sheets" do scenario "Ballot sheet is not saved" do visit new_officing_poll_ballot_sheet_path(poll) - select "#{booth.name}", from: "officer_assignment_id" + select booth.name, from: "officer_assignment_id" click_button "Save" expect(page).to have_content("CSV data can't be blank") diff --git a/spec/system/legislation/processes_spec.rb b/spec/system/legislation/processes_spec.rb index acef919fd..5eccacfa5 100644 --- a/spec/system/legislation/processes_spec.rb +++ b/spec/system/legislation/processes_spec.rb @@ -155,7 +155,7 @@ describe "Legislation" do phases.each do |phase| within(".legislation-process-list") do - find("li", text: "#{phase}").click_link + find("li", text: phase).click_link end expect(page).to have_content(document.title)