Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
# .rubocop.yml
require:
rubocop-rspec

# Omakase Ruby styling for Rails
inherit_gem:
rubocop-govuk:
- config/default.yml
- config/rails.yml
- config/rspec.yml
rubocop-rails-omakase: rubocop.yml

inherit_mode:
merge:
- Exclude

# **************************************************************
# TRY NOT TO ADD OVERRIDES IN THIS FILE
#
# This repo is configured to follow the RuboCop GOV.UK styleguide.
# Any rules you override here will cause this repo to diverge from
# the way we write code in all other GOV.UK repos.
#
# See https://github.com/alphagov/rubocop-govuk/blob/main/CONTRIBUTING.md
# **************************************************************

RSpec/SpecFilePathFormat:
CustomTransform:
OmniAuth: omniauth

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ group :development, :test do
gem "i18n-tasks", "~> 1.0.14"
gem "rails-controller-testing"
gem "rspec-rails", ">= 3.9.0"
gem "rubocop-govuk", require: false
gem "rubocop-rails-omakase", require: false
gem "rubocop-rspec", require: false

# For security auditing gem vulnerabilities. RUN IN CI
gem "bundler-audit", "~> 0.9.2"
Expand Down
37 changes: 19 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ GEM
json (2.9.1)
jwt (2.8.2)
base64
language_server-protocol (3.17.0.3)
language_server-protocol (3.17.0.4)
logger (1.6.5)
lograge (0.14.0)
actionpack (>= 4)
Expand Down Expand Up @@ -418,35 +418,35 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.2)
rubocop (1.70.0)
rubocop (1.71.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
rubocop-ast (1.38.0)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-govuk (5.0.8)
rubocop (= 1.70.0)
rubocop-ast (= 1.37.0)
rubocop-capybara (= 2.21.0)
rubocop-rails (= 2.28.0)
rubocop-rake (= 0.6.0)
rubocop-rspec (= 3.3.0)
rubocop-rails (2.28.0)
rubocop-minitest (0.36.0)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.23.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.29.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (3.3.0)
rubocop-rails-omakase (1.0.0)
rubocop
rubocop-minitest
rubocop-performance
rubocop-rails
rubocop-rspec (3.4.0)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
rubyzip (2.4.1)
Expand Down Expand Up @@ -565,7 +565,8 @@ DEPENDENCIES
rails (= 8.0.1)
rails-controller-testing
rspec-rails (>= 3.9.0)
rubocop-govuk
rubocop-rails-omakase
rubocop-rspec
selenium-webdriver
sentry-rails
sentry-ruby
Expand Down
6 changes: 3 additions & 3 deletions app/components/act_as_user_banner_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def acting_user_details_content

user_text = if @acting_as_user.organisation_admin?
"an organisation admin"
elsif @acting_as_user.standard?
elsif @acting_as_user.standard?
"a standard user"
else
else
"a user with role: #{@acting_as_user.role}"
end
end

"#{user_text} #{organisation_text}"
end
Expand Down
2 changes: 1 addition & 1 deletion app/components/mark_complete_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(form_model: false, generate_form: true, form_builder: nil, path:
end

def mark_complete_options
[OpenStruct.new(value: "true", name: t("mark_complete.true")), OpenStruct.new(value: "false", name: t("mark_complete.false"))]
[ OpenStruct.new(value: "true", name: t("mark_complete.true")), OpenStruct.new(value: "false", name: t("mark_complete.false")) ]
end

def before_render
Expand Down
2 changes: 1 addition & 1 deletion app/components/markdown_editor_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def form_field_id
end

def allowed_formats
["links", *(%w[headings] if allow_headings), "bulleted_lists", "numbered_lists"]
[ "links", *(%w[headings] if allow_headings), "bulleted_lists", "numbered_lists" ]
end

def preview_button_translation
Expand Down
2 changes: 1 addition & 1 deletion app/components/metrics_summary_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class View < ViewComponent::Base

def initialize(form_live_date, metrics_data)
super
@start_date = [form_live_date, 7.days.ago.to_date].max
@start_date = [ form_live_date, 7.days.ago.to_date ].max
@end_date = 1.day.ago.to_date
@heading = heading_text.html_safe

Expand Down
2 changes: 1 addition & 1 deletion app/components/page_list_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def process_routing_conditions
.values
.flat_map { |conditions|
conditions.map.with_index(1) do |condition, index|
[condition.routing_page_id, [condition, index]] # inclde routing_page_id, so we can group by it
[ condition.routing_page_id, [ condition, index ] ] # inclde routing_page_id, so we can group by it
end
}
.group_by(&:first)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def set_logging_attributes
def set_request_id
# Pass the request id to the API to enable tracing
if Rails.env.production?
[Api::V1::FormResource, Api::V1::PageResource].each do |active_resource_model|
[ Api::V1::FormResource, Api::V1::PageResource ].each do |active_resource_model|
active_resource_model.headers["X-Request-ID"] = request.request_id
end
end
Expand All @@ -75,7 +75,7 @@ def set_request_id
# enough for our basic monitoring
def user_ip(forwarded_for = "")
first_ip_string = forwarded_for.split(",").first
Regexp.union([Resolv::IPv4::Regex, Resolv::IPv6::Regex]).match(first_ip_string) && first_ip_string
Regexp.union([ Resolv::IPv4::Regex, Resolv::IPv6::Regex ]).match(first_ip_string) && first_ip_string
end

def warden
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/forms/declaration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def create
if @declaration_input.submit
success_message = if @declaration_input.mark_complete == "true"
t("banner.success.form.declaration_saved_and_completed")
else
else
t("banner.success.form.declaration_saved")
end
end

redirect_to form_path(@declaration_input.form), success: success_message
else
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def mark_pages_section_completed
if @mark_complete_input.submit
success_message = if @mark_complete_input.mark_complete == "true"
t("banner.success.form.pages_saved_and_section_completed")
else
else
t("banner.success.form.pages_saved")
end
end
redirect_to form_path(current_form.id), success: success_message
else
@mark_complete_input.mark_complete = "false"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/pages/selection/options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ def include_none_of_the_above_param_values

def input_params
params.require(:pages_selection_options_input)
.permit(:include_none_of_the_above, selection_options: [:name]).to_h.deep_symbolize_keys
.permit(:include_none_of_the_above, selection_options: [ :name ]).to_h.deep_symbolize_keys
end
end
8 changes: 4 additions & 4 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def move_page

position = if move_params[:direction] == :up
page_to_move.position - 1
else
else
page_to_move.position + 1
end
end

redirect_to form_pages_path, success: t("banner.success.form.page_moved", question_text: page_to_move.question_text, direction: move_params[:direction], position:)
end
Expand All @@ -105,9 +105,9 @@ def page
def draft_question
@draft_question ||= if params[:page_id].present?
setup_draft_question_for_existing_page
else
else
DraftQuestion.find_or_initialize_by(form_id: current_form.id, user_id: current_user.id)
end
end
end

def move_params
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ApplicationHelper
def page_title
[content_for(:title), "GOV.UK Forms"].compact.join(I18n.t("page_titles.separator"))
[ content_for(:title), "GOV.UK Forms" ].compact.join(I18n.t("page_titles.separator"))
end

def set_page_title(title)
Expand Down
6 changes: 3 additions & 3 deletions app/input_objects/forms/contact_details_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def submit
end

def assign_form_values
self.contact_details_supplied |= [:supply_email] if form.support_email.present?
self.contact_details_supplied |= [:supply_phone] if form.support_phone.present?
self.contact_details_supplied |= [:supply_link] if form.support_url.present?
self.contact_details_supplied |= [ :supply_email ] if form.support_email.present?
self.contact_details_supplied |= [ :supply_phone ] if form.support_phone.present?
self.contact_details_supplied |= [ :supply_link ] if form.support_url.present?

self.email = form.support_email
self.phone = form.support_phone
Expand Down
4 changes: 2 additions & 2 deletions app/input_objects/forms/submission_email_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def submit

form_processed = if form_submission_email.nil?
create_submission_email_record(confirmation_code)
else
else
update_submission_email_record(confirmation_code, form_submission_email)
end
end

if form_processed && temporary_submission_email.present?
# send notify email?
Expand Down
2 changes: 1 addition & 1 deletion app/input_objects/group_member_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def submit
end

def role_options
Membership.roles.keys.map { |role| [I18n.t("membership.roles.#{role}"), role] }
Membership.roles.keys.map { |role| [ I18n.t("membership.roles.#{role}"), role ] }
end

def invited_user
Expand Down
4 changes: 2 additions & 2 deletions app/input_objects/pages/question_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def update_page(page)
end

def default_options
[OpenStruct.new(id: "false"), OpenStruct.new(id: "true")]
[ OpenStruct.new(id: "false"), OpenStruct.new(id: "true") ]
end

def repeatable_options
[OpenStruct.new(id: "true"), OpenStruct.new(id: "false")]
[ OpenStruct.new(id: "true"), OpenStruct.new(id: "false") ]
end

def validate_number_of_selection_options
Expand Down
2 changes: 1 addition & 1 deletion app/input_objects/pages/selection/bulk_options_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def submit
end

def none_of_the_above_options
[OpenStruct.new(id: "true"), OpenStruct.new(id: "false")]
[ OpenStruct.new(id: "true"), OpenStruct.new(id: "false") ]
end

def only_one_option?
Expand Down
4 changes: 2 additions & 2 deletions app/input_objects/pages/selection/options_input.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Pages::Selection::OptionsInput < BaseInput
include LoggingHelper

DEFAULT_OPTIONS = { selection_options: [{ name: "" }, { name: "" }] }.freeze
DEFAULT_OPTIONS = { selection_options: [ { name: "" }, { name: "" } ] }.freeze
INCLUDE_NONE_OF_THE_ABOVE_OPTIONS = %w[true false].freeze
MAXIMUM_CHOOSE_ONLY_ONE_OPTION = 1000
MAXIMUM_CHOOSE_MORE_THAN_ONE_OPTION = 30
Expand Down Expand Up @@ -42,7 +42,7 @@ def selection_options_form_objects
end

def include_none_of_the_above_options
[OpenStruct.new(id: "true"), OpenStruct.new(id: "false")]
[ OpenStruct.new(id: "true"), OpenStruct.new(id: "false") ]
end

def maximum_options
Expand Down
2 changes: 1 addition & 1 deletion app/input_objects/pages/selection/type_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def submit
end

def only_one_option_options
[OpenStruct.new(id: "true"), OpenStruct.new(id: "false")]
[ OpenStruct.new(id: "true"), OpenStruct.new(id: "false") ]
end

def need_to_reduce_options?
Expand Down
2 changes: 1 addition & 1 deletion app/input_objects/pages/type_of_answer_input.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Pages::TypeOfAnswerInput < BaseInput
attr_accessor :answer_type, :draft_question, :answer_types, :current_form

SELECTION_DEFAULT_OPTIONS = { selection_options: [{ name: "" }, { name: "" }] }.freeze
SELECTION_DEFAULT_OPTIONS = { selection_options: [ { name: "" }, { name: "" } ] }.freeze

validates :draft_question, presence: true
validates :answer_type, presence: true, inclusion: { in: :answer_types }
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UserAuthenticationException < StandardError; end
validates :name, presence: true, if: :requires_name?
validates :role, presence: true
validates :organisation_id, presence: true, if: :requires_organisation?
validates :has_access, inclusion: [true, false]
validates :has_access, inclusion: [ true, false ]
validates :role, exclusion: %w[organisation_admin], unless: :current_org_has_mou?
validates :email, uniqueness: { case_sensitive: false }

Expand Down
6 changes: 3 additions & 3 deletions app/presenters/form_list_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def head
end

def rows
forms.sort_by { |form| [form.name.downcase, form.created_at] }.map do |form|
[{ text: form_name_link(form) },
forms.sort_by { |form| [ form.name.downcase, form.created_at ] }.map do |form|
[ { text: form_name_link(form) },
{ text: find_creator_name(form) },
{ text: form_status_tags(form), numeric: true }].compact
{ text: form_status_tags(form), numeric: true } ].compact
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/presenters/route_summary_card_data_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def secondary_skip_card
edit_secondary_skip_link,
delete_secondary_skip_link,
]
else
else
[]
end
end

{
card: {
Expand Down
2 changes: 1 addition & 1 deletion app/services/default_group_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DefaultGroupService
def create_user_default_trial_group!(user)
return unless user.name.present? && user.organisation.present?

forms = FormRepository.where(creator_id: user.id).to_h { [_1.id, _1] }
forms = FormRepository.where(creator_id: user.id).to_h { [ _1.id, _1 ] }
form_ids = forms.keys
group_form_ids = GroupForm.where(form_id: form_ids).pluck(:form_id)
not_group_form_ids = form_ids.to_set - group_form_ids
Expand Down
Loading