Skip to content

Commit

Permalink
Update rubocop and add corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrett committed Dec 4, 2023
1 parent 55b386c commit d9cafc1
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 34 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/content_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/models/content_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/govspeak_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions db/seeds/archive/get_help_to_improve_your_practice_seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

attrs = {
title: "Get help to improve your practice",
markdown: markdown,
markdown:,
position: 8,
}
parent_page = ContentPage.new attrs
Expand All @@ -40,7 +40,7 @@

attrs = {
title: "Planning",
markdown: markdown,
markdown:,
position: 1,
parent_id: parent_page.id,
}
Expand All @@ -60,7 +60,7 @@

attrs = {
title: "Reducing paperwork",
markdown: markdown,
markdown:,
position: 2,
parent_id: parent_page.id,
}
Expand All @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -126,7 +126,7 @@

attrs = {
title: "Working in partnership with parents",
markdown: markdown,
markdown:,
position: 5,
parent_id: parent_page.id,
}
Expand Down
8 changes: 4 additions & 4 deletions lib/tasks/load.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/content_asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/admin/content_blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/admin/content_page_versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/admin/content_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/admin/user_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d9cafc1

Please sign in to comment.