From d9cafc113952d8eed117ff835416b9a8922f04bc Mon Sep 17 00:00:00 2001 From: Brett McHargue Date: Mon, 4 Dec 2023 14:04:06 +0000 Subject: [PATCH] Update rubocop and add corrections --- Gemfile | 2 +- Gemfile.lock | 57 +++++++++++-------- .../admin/content_pages_controller.rb | 2 +- app/models/content_page.rb | 12 ++-- app/models/govspeak_decorator.rb | 2 +- db/seeds.rb | 2 +- ...get_help_to_improve_your_practice_seeds.rb | 12 ++-- lib/tasks/load.rake | 8 +-- spec/models/content_asset_spec.rb | 2 +- spec/rails_helper.rb | 2 +- spec/requests/admin/content_blocks_spec.rb | 6 +- .../admin/content_page_versions_spec.rb | 2 +- spec/requests/admin/content_pages_spec.rb | 6 +- spec/requests/admin/user_request_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 15 files changed, 65 insertions(+), 54 deletions(-) diff --git a/Gemfile b/Gemfile index ff0c34c3b..200e0af36 100644 --- a/Gemfile +++ b/Gemfile @@ -60,7 +60,7 @@ group :development, :test do gem "byebug", platforms: %i[mri mingw x64_mingw] # GOV.UK interpretation of rubocop for linting Ruby - gem "rubocop-govuk", "~> 4.2" + gem "rubocop-govuk", "~> 4.12" gem "scss_lint-govuk" # Debugging diff --git a/Gemfile.lock b/Gemfile.lock index 8a675684b..541d53364 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -248,9 +248,11 @@ GEM concurrent-ruby (~> 1.0) ice_nine (0.11.2) jmespath (1.5.0) + json (2.7.0) kgio (2.11.4) kramdown (2.3.1) rexml + language_server-protocol (3.17.0.3) launchy (2.5.0) addressable (~> 2.7) listen (3.7.1) @@ -306,9 +308,10 @@ GEM racc (~> 1.4) orm_adapter (0.5.0) pagy (6.2.0) - parallel (1.21.0) - parser (3.1.0.0) + parallel (1.23.0) + parser (3.2.2.4) ast (~> 2.4.1) + racc pg (1.5.4) plek (4.0.0) protobuf-cucumber (3.10.8) @@ -374,7 +377,7 @@ GEM rb-fsevent (0.11.0) rb-inotify (0.10.1) ffi (~> 1.0) - regexp_parser (2.2.0) + regexp_parser (2.8.2) request_store (1.5.0) rack (>= 1.4) responders (3.1.1) @@ -404,32 +407,40 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.3) - rubocop (1.23.0) + rubocop (1.55.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.2.2.3) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.12.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.13.0) - parser (>= 3.0.1.1) - rubocop-govuk (4.2.0) - rubocop (= 1.23.0) - rubocop-ast (= 1.13.0) - rubocop-rails (= 2.12.4) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.29.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.19.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.24.0) + rubocop (~> 1.33) + rubocop-govuk (4.12.0) + rubocop (= 1.55.0) + rubocop-ast (= 1.29.0) + rubocop-rails (= 2.20.2) rubocop-rake (= 0.6.0) - rubocop-rspec (= 2.6.0) - rubocop-rails (2.12.4) + rubocop-rspec (= 2.22.0) + rubocop-rails (2.20.2) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.7.0, < 2.0) + rubocop (>= 1.33.0, < 2.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.6.0) - rubocop (~> 1.19) - ruby-progressbar (1.11.0) + rubocop-rspec (2.22.0) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + ruby-progressbar (1.13.0) rubyzip (2.3.2) sanitize (6.0.1) crass (~> 1.0.2) @@ -485,7 +496,7 @@ GEM timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.1.0) + unicode-display_width (2.5.0) unicorn (5.8.0) kgio (~> 2.6) raindrops (~> 0.7) @@ -562,7 +573,7 @@ DEPENDENCIES launchy listen (>= 3.0.5, < 3.8) pg (>= 0.18, < 2.0) - pry-byebug + pry-byebug (~> 3.10.1) puma (~> 5.5) pundit (~> 2.1) rails (~> 6.1.7) @@ -571,7 +582,7 @@ DEPENDENCIES rspec (~> 3.10) rspec-expectations (~> 3.10) rspec-rails (~> 5.0) - rubocop-govuk (~> 4.2) + rubocop-govuk (~> 4.12) scss_lint-govuk selenium-webdriver sentry-rails diff --git a/app/controllers/admin/content_pages_controller.rb b/app/controllers/admin/content_pages_controller.rb index 1d8c87285..0da91d64f 100644 --- a/app/controllers/admin/content_pages_controller.rb +++ b/app/controllers/admin/content_pages_controller.rb @@ -92,7 +92,7 @@ def destroy def preview html = GovspeakDecorator.translate_markdown(params["markdown"]) - render json: { html: html } + render json: { html: } end def preview_of_live diff --git a/app/models/content_page.rb b/app/models/content_page.rb index 0e441a8b9..db4acae21 100644 --- a/app/models/content_page.rb +++ b/app/models/content_page.rb @@ -10,7 +10,7 @@ class ContentPage < ApplicationRecord scope :published, -> { where("is_published = true") } CHARS_TO_OMIT_FROM_SLUG = ",:()".freeze - ONLY_ALPHA_NUMERIC_COMMA_HYPHEN_SPACE_AND_ROUND_BRACES = /\A[a-zA-Z0-9,:\-() ]+\Z/.freeze + ONLY_ALPHA_NUMERIC_COMMA_HYPHEN_SPACE_AND_ROUND_BRACES = /\A[a-zA-Z0-9,:\-() ]+\Z/ TITLE_FORMAT_ERROR_MESSAGE = "Heading should only contain alphabetic, numeric and -#{CHARS_TO_OMIT_FROM_SLUG}".freeze validates :title, format: { with: ONLY_ALPHA_NUMERIC_COMMA_HYPHEN_SPACE_AND_ROUND_BRACES, message: TITLE_FORMAT_ERROR_MESSAGE } validates :title, presence: true, uniqueness: true @@ -27,12 +27,12 @@ class ContentPage < ApplicationRecord end def create_first_version - ContentPageVersion.create!(title: title, - markdown: markdown, - content_list: content_list, + ContentPageVersion.create!(title:, + markdown:, + content_list:, content_page_id: id, - author: author, - description: description) + author:, + description:) end after_save do diff --git a/app/models/govspeak_decorator.rb b/app/models/govspeak_decorator.rb index fdf5bf8f7..5b63987b4 100644 --- a/app/models/govspeak_decorator.rb +++ b/app/models/govspeak_decorator.rb @@ -2,7 +2,7 @@ class GovspeakDecorator < DelegateClass(Govspeak::Document) ALLOWED_TAGS = %w[details summary p h1 h2 h3 h4 ul li img div ol a span strong iframe].freeze def self.translate_markdown(markdown, sanitize: true) - newdoc = new(Govspeak::Document.new(markdown, sanitize: sanitize, allowed_elements: ALLOWED_TAGS)) + newdoc = new(Govspeak::Document.new(markdown, sanitize:, allowed_elements: ALLOWED_TAGS)) newdoc.to_html end diff --git a/db/seeds.rb b/db/seeds.rb index 74d7b886d..979f1641c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,7 +6,7 @@ def seed_content_pages_from(path) Seeder.objects_from(path).each do |slug, attributes| - content_page = ContentPage.find_or_initialize_by(slug: slug) + content_page = ContentPage.find_or_initialize_by(slug:) attributes.merge!(parent: ContentPage.find_by(slug: attributes.delete("parent"))) if attributes["parent"].present? content_page.update!(attributes) end diff --git a/db/seeds/archive/get_help_to_improve_your_practice_seeds.rb b/db/seeds/archive/get_help_to_improve_your_practice_seeds.rb index a92dd8216..50114a36f 100644 --- a/db/seeds/archive/get_help_to_improve_your_practice_seeds.rb +++ b/db/seeds/archive/get_help_to_improve_your_practice_seeds.rb @@ -21,7 +21,7 @@ attrs = { title: "Get help to improve your practice", - markdown: markdown, + markdown:, position: 8, } parent_page = ContentPage.new attrs @@ -40,7 +40,7 @@ attrs = { title: "Planning", - markdown: markdown, + markdown:, position: 1, parent_id: parent_page.id, } @@ -60,7 +60,7 @@ attrs = { title: "Reducing paperwork", - markdown: markdown, + markdown:, position: 2, parent_id: parent_page.id, } @@ -80,7 +80,7 @@ attrs = { title: "Identifying and supporting children with special educational needs and disability", - markdown: markdown, + markdown:, position: 3, parent_id: parent_page.id, } @@ -99,7 +99,7 @@ attrs = { title: "Promoting oral health as part of the safeguarding and welfare requirements", - markdown: markdown, + markdown:, position: 4, parent_id: parent_page.id, } @@ -126,7 +126,7 @@ attrs = { title: "Working in partnership with parents", - markdown: markdown, + markdown:, position: 5, parent_id: parent_page.id, } diff --git a/lib/tasks/load.rake b/lib/tasks/load.rake index ad3c200f9..7718eed76 100644 --- a/lib/tasks/load.rake +++ b/lib/tasks/load.rake @@ -8,7 +8,7 @@ namespace :load do parent_page.save! puts "Updated #{parent_page.reload.inspect}" { oral_health: "Oral health", food_safety: "Food safety" }.each do |key, title| - ContentPage.new(title: title, parent_id: parent_page.id) do |child_page| + ContentPage.new(title:, parent_id: parent_page.id) do |child_page| attrs = I18n.t("content.#{key}") puts "Update #{child_page.inspect}" child_page.update!(attrs) @@ -36,9 +36,9 @@ namespace :load do first_name, last_name, role = name.split(".") user_attributes = { email: "#{first_name}@education.gov.uk", - first_name: first_name, - last_name: last_name, - role: role, + first_name:, + last_name:, + role:, } user = User.first_or_initialize(user_attributes).tap do |admin| admin.password = Rails.application.credentials.test_password diff --git a/spec/models/content_asset_spec.rb b/spec/models/content_asset_spec.rb index 9d53dec40..94179ff49 100644 --- a/spec/models/content_asset_spec.rb +++ b/spec/models/content_asset_spec.rb @@ -34,7 +34,7 @@ application/vnd.openxmlformats-officedocument.wordprocessingml.document ].each do |content_type| it "has valid content type" do - content_asset.asset_file.attach(io: File.open(file_fixture("sample.jpeg")), filename: "sample.jpeg", content_type: content_type) + content_asset.asset_file.attach(io: File.open(file_fixture("sample.jpeg")), filename: "sample.jpeg", content_type:) content_asset.validate expect(content_asset).to be_valid end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 22c4149aa..b8e112c88 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -37,7 +37,7 @@ end RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = Rails.root.join("spec/fixtures").to_s # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false diff --git a/spec/requests/admin/content_blocks_spec.rb b/spec/requests/admin/content_blocks_spec.rb index ab9a18cff..fe455d35c 100644 --- a/spec/requests/admin/content_blocks_spec.rb +++ b/spec/requests/admin/content_blocks_spec.rb @@ -29,7 +29,7 @@ let(:params) do { content_block: attributes_for(:content_block) } end - subject { post admin_content_blocks_path, params: params } + subject { post admin_content_blocks_path, params: } it "creates a new content block" do expect { subject }.to change(ContentBlock, :count).by(1) @@ -78,9 +78,9 @@ let(:content_block) { create :content_block } let(:name) { Faker::Superhero.name.delete(" ") } let(:params) do - { content_block: { name: name } } + { content_block: { name: } } end - subject { patch admin_content_block_path(content_block), params: params } + subject { patch admin_content_block_path(content_block), params: } it "updates the content block" do original_name = content_block.name diff --git a/spec/requests/admin/content_page_versions_spec.rb b/spec/requests/admin/content_page_versions_spec.rb index a3dc676e9..6b01d0ddb 100644 --- a/spec/requests/admin/content_page_versions_spec.rb +++ b/spec/requests/admin/content_page_versions_spec.rb @@ -52,7 +52,7 @@ content_page_version: attributes_for(:content_page_version), } end - subject { patch admin_content_page_content_page_version_path(content_page, content_page_version), params: params } + subject { patch admin_content_page_content_page_version_path(content_page, content_page_version), params: } it "updates the content page version" do subject diff --git a/spec/requests/admin/content_pages_spec.rb b/spec/requests/admin/content_pages_spec.rb index fe7f1a9b8..3a7f9c796 100644 --- a/spec/requests/admin/content_pages_spec.rb +++ b/spec/requests/admin/content_pages_spec.rb @@ -127,11 +127,11 @@ end it "creates a new content_page_version" do - expect { patch admin_content_page_path(content_page), params: params }.to change(ContentPageVersion, :count).by(1) + expect { patch admin_content_page_path(content_page), params: }.to change(ContentPageVersion, :count).by(1) end it "populates content page version from input" do - patch admin_content_page_path(content_page), params: params + patch(admin_content_page_path(content_page), params:) content_page_version = content_page.content_page_versions.last expect(content_page_version.title).to eq(valid_attributes[:title]) expect(content_page_version.content_list).to eq(valid_attributes[:content_list]) @@ -141,7 +141,7 @@ end it "redirects to the content_page versions" do - patch admin_content_page_path(content_page), params: params + patch(admin_content_page_path(content_page), params:) expect(response).to redirect_to(versions_admin_content_page_path(content_page)) end end diff --git a/spec/requests/admin/user_request_spec.rb b/spec/requests/admin/user_request_spec.rb index 10c2a4ae1..cc2c2eb4e 100644 --- a/spec/requests/admin/user_request_spec.rb +++ b/spec/requests/admin/user_request_spec.rb @@ -140,7 +140,7 @@ context "with admin and matching passwords" do let(:password) { "#{Faker::Lorem.word}!!12XX" } - let(:user_attributes) { attributes_for :user, password: password, password_confirmation: password } + let(:user_attributes) { attributes_for :user, password:, password_confirmation: password } before { sign_in create(:admin) } it "modifies the user" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3b7870ec4..cd9b37d16 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,7 +19,7 @@ ], } - Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: capabilities) + Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities:) end Capybara.javascript_driver = :chrome_headless