Skip to content

Commit 26fa867

Browse files
authored
Merge pull request #464 from x-govuk/upgrade-rubocop-target-version-and-apply-suggestions
Upgrade Rubocop target Ruby version and apply suggested fixes
2 parents 67aca08 + b4df313 commit 26fa867

25 files changed

+99
-100
lines changed

.rubocop.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ inherit_gem:
66
- config/rails.yml
77

88
AllCops:
9+
TargetRubyVersion: 3.1
910
Exclude:
1011
- govuk_design_system_formbuilder.gemspec
1112
Rails/Date:
@@ -38,7 +39,5 @@ Style/CommentAnnotation:
3839
Enabled: false
3940
Style/EmptyCaseCondition:
4041
Enabled: false
41-
Style/HashSyntax:
42-
Enabled: false
4342
Style/FormatString:
4443
EnforcedStyle: format

guide/lib/helpers/header_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module HeaderHelper
33
def header(level: 2, id: nil, classes: nil)
44
tag = "h#{level}"
55

6-
{ tag: tag, id: id, class: classes }.compact
6+
{ tag:, id:, class: classes }.compact
77
end
88
end
99
end

guide/lib/setup/example_data.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ def custom_error_presenter
154154

155155
def form_data
156156
{
157-
departments: departments,
158-
departments_collection: departments_collection,
159-
contact_types: contact_types,
160-
lunch_options: lunch_options,
161-
grouped_lunch_options: grouped_lunch_options,
162-
primary_colours: primary_colours,
163-
laptops: laptops,
164-
custom_error_presenter: custom_error_presenter,
157+
departments:,
158+
departments_collection:,
159+
contact_types:,
160+
lunch_options:,
161+
grouped_lunch_options:,
162+
primary_colours:,
163+
laptops:,
164+
custom_error_presenter:,
165165
}
166166
end
167167
end

lib/govuk_design_system_formbuilder/builder.rb

+53-53
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module Builder
5353
# label: -> { tag.h3('Call-sign') }
5454
#
5555
def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
56-
Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
56+
Elements::Inputs::Text.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
5757
end
5858

5959
# Generates a input of type +tel+
@@ -107,7 +107,7 @@ def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: ni
107107
# label: -> { tag.h3('Work number') }
108108
#
109109
def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
110-
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
110+
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
111111
end
112112

113113
# Generates a input of type +email+
@@ -159,7 +159,7 @@ def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: n
159159
# label: -> { tag.h3('Personal email address') }
160160
#
161161
def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
162-
Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
162+
Elements::Inputs::Email.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
163163
end
164164

165165
# Generates a input of type +password+
@@ -210,7 +210,7 @@ def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: n
210210
# label: -> { tag.h3('What is your secret pass code?') }
211211
#
212212
def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, extra_letter_spacing: false, form_group: {}, caption: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
213-
Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
213+
Elements::Inputs::Password.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
214214
end
215215

216216
# Generates a input of type +url+
@@ -262,7 +262,7 @@ def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, extra_
262262
# label: -> { tag.h3("Enter your company's website") }
263263
#
264264
def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
265-
Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
265+
Elements::Inputs::URL.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
266266
end
267267

268268
# Generates a input of type +number+
@@ -317,7 +317,7 @@ def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil
317317
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
318318
#
319319
def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
320-
Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
320+
Elements::Inputs::Number.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
321321
end
322322

323323
# Generates a +textarea+ element with a label, optional hint. Also offers
@@ -373,7 +373,7 @@ def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width:
373373
# label: -> { tag.h3("How do you set it up?") }
374374
#
375375
def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block)
376-
Elements::TextArea.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, form_group: form_group, **kwargs, &block).html
376+
Elements::TextArea.new(self, object_name, attribute_name, hint:, label:, caption:, max_words:, max_chars:, rows:, threshold:, form_group:, **kwargs, &block).html
377377
end
378378

379379
# Generates a +select+ element containing +option+ for each member in the provided collection
@@ -422,13 +422,13 @@ def govuk_collection_select(attribute_name, collection, value_method, text_metho
422422
object_name,
423423
attribute_name,
424424
collection,
425-
value_method: value_method,
426-
text_method: text_method,
427-
hint: hint,
428-
label: label,
429-
caption: caption,
430-
options: options,
431-
form_group: form_group,
425+
value_method:,
426+
text_method:,
427+
hint:,
428+
label:,
429+
caption:,
430+
options:,
431+
form_group:,
432432
**kwargs,
433433
&block
434434
).html
@@ -466,7 +466,7 @@ def govuk_collection_select(attribute_name, collection, value_method, text_metho
466466
# = f.govuk_select :hat_colour, options_for_select(@colours)
467467
#
468468
def govuk_select(attribute_name, choices = nil, options: {}, label: {}, hint: {}, form_group: {}, caption: {}, **kwargs, &block)
469-
Elements::Select.new(self, object_name, attribute_name, choices, options: options, label: label, hint: hint, form_group: form_group, caption: caption, **kwargs, &block).html
469+
Elements::Select.new(self, object_name, attribute_name, choices, options:, label:, hint:, form_group:, caption:, **kwargs, &block).html
470470
end
471471

472472
# Generates a radio button for each item in the supplied collection
@@ -546,17 +546,17 @@ def govuk_collection_radio_buttons(attribute_name, collection, value_method, tex
546546
object_name,
547547
attribute_name,
548548
collection,
549-
value_method: value_method,
550-
text_method: text_method,
551-
hint_method: hint_method,
552-
hint: hint,
553-
legend: legend,
554-
caption: caption,
555-
inline: inline,
556-
small: small,
557-
bold_labels: bold_labels,
558-
form_group: form_group,
559-
include_hidden: include_hidden,
549+
value_method:,
550+
text_method:,
551+
hint_method:,
552+
hint:,
553+
legend:,
554+
caption:,
555+
inline:,
556+
small:,
557+
bold_labels:,
558+
form_group:,
559+
include_hidden:,
560560
**kwargs,
561561
&block
562562
).html
@@ -611,7 +611,7 @@ def govuk_collection_radio_buttons(attribute_name, collection, value_method, tex
611611
# = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
612612
#
613613
def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, form_group: {}, **kwargs, &block)
614-
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, inline: inline, small: small, form_group: form_group, **kwargs, &block).html
614+
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint:, legend:, caption:, inline:, small:, form_group:, **kwargs, &block).html
615615
end
616616

617617
# Generates a radio button
@@ -643,7 +643,7 @@ def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption:
643643
# = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
644644
#
645645
def govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, **kwargs, &block)
646-
Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, **kwargs, &block).html
646+
Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint:, label:, link_errors:, **kwargs, &block).html
647647
end
648648

649649
# Inserts a text divider into a list of radio buttons
@@ -725,15 +725,15 @@ def govuk_collection_check_boxes(attribute_name, collection, value_method, text_
725725
object_name,
726726
attribute_name,
727727
collection,
728-
value_method: value_method,
729-
text_method: text_method,
730-
hint_method: hint_method,
731-
hint: hint,
732-
legend: legend,
733-
caption: caption,
734-
small: small,
735-
form_group: form_group,
736-
include_hidden: include_hidden,
728+
value_method:,
729+
text_method:,
730+
hint_method:,
731+
hint:,
732+
legend:,
733+
caption:,
734+
small:,
735+
form_group:,
736+
include_hidden:,
737737
**kwargs,
738738
&block
739739
).html
@@ -782,12 +782,12 @@ def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}
782782
self,
783783
object_name,
784784
attribute_name,
785-
hint: hint,
786-
legend: legend,
787-
caption: caption,
788-
small: small,
789-
form_group: form_group,
790-
multiple: multiple,
785+
hint:,
786+
legend:,
787+
caption:,
788+
small:,
789+
form_group:,
790+
multiple:,
791791
**kwargs,
792792
&block
793793
).html
@@ -830,11 +830,11 @@ def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, la
830830
attribute_name,
831831
value,
832832
unchecked_value,
833-
hint: hint,
834-
label: label,
835-
link_errors: link_errors,
836-
multiple: multiple,
837-
exclusive: exclusive,
833+
hint:,
834+
label:,
835+
link_errors:,
836+
multiple:,
837+
exclusive:,
838838
**kwargs,
839839
&block
840840
).html
@@ -883,7 +883,7 @@ def govuk_check_box_divider(text = config.default_check_box_divider_text)
883883
# = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
884884
#
885885
def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, inverse: false, prevent_double_click: true, validate: config.default_submit_validate, disabled: false, **kwargs, &block)
886-
Elements::Submit.new(self, text, warning: warning, secondary: secondary, inverse: inverse, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, **kwargs, &block).html
886+
Elements::Submit.new(self, text, warning:, secondary:, inverse:, prevent_double_click:, validate:, disabled:, **kwargs, &block).html
887887
end
888888

889889
# Generates three inputs for the +day+, +month+ and +year+ components of a date
@@ -932,7 +932,7 @@ def govuk_submit(text = config.default_submit_button_text, warning: false, secon
932932
# = f.govuk_date_field :finishes_on,
933933
# legend: -> { tag.h3('Which category do you belong to?') }
934934
def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, maxlength_enabled: false, form_group: {}, **kwargs, &block)
935-
Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, maxlength_enabled: maxlength_enabled, form_group: form_group, **kwargs, &block).html
935+
Elements::Date.new(self, object_name, attribute_name, hint:, legend:, caption:, date_of_birth:, omit_day:, maxlength_enabled:, form_group:, **kwargs, &block).html
936936
end
937937

938938
# Generates a summary of errors in the form, each linking to the corresponding
@@ -962,7 +962,7 @@ def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_
962962
#
963963
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
964964
def govuk_error_summary(title = config.default_error_summary_title, presenter: config.default_error_summary_presenter, link_base_errors_to: nil, order: nil, **kwargs, &block)
965-
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, order: order, presenter: presenter, **kwargs, &block).html
965+
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to:, order:, presenter:, **kwargs, &block).html
966966
end
967967

968968
# Generates a fieldset containing the contents of the block
@@ -995,7 +995,7 @@ def govuk_error_summary(title = config.default_error_summary_title, presenter: c
995995
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
996996
# @return [ActiveSupport::SafeBuffer] HTML output
997997
def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, **kwargs, &block)
998-
Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, **kwargs, &block).html
998+
Containers::Fieldset.new(self, legend:, caption:, described_by:, **kwargs, &block).html
999999
end
10001000

10011001
# Generates an input of type +file+
@@ -1036,7 +1036,7 @@ def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_
10361036
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
10371037
# the Rails documentation} for more information
10381038
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
1039-
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **kwargs, &block).html
1039+
Elements::File.new(self, object_name, attribute_name, label:, caption:, hint:, form_group:, **kwargs, &block).html
10401040
end
10411041
end
10421042
end

lib/govuk_design_system_formbuilder/builder_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module BuilderHelper
2626
def govuk_field_id(object, attribute_name, object_name = nil, value: nil, link_errors: true)
2727
(object_name = retrieve_object_name(object)) if object_name.nil?
2828

29-
proxy_base(object, object_name, attribute_name, value: value).field_id(link_errors: link_errors)
29+
proxy_base(object, object_name, attribute_name, value:).field_id(link_errors:)
3030
end
3131

3232
# Renders an error summary
@@ -51,7 +51,7 @@ def govuk_error_summary(object, object_name = nil, *args, **kwargs, &block)
5151
private
5252

5353
def proxy_base(object, object_name, attribute_name, value: nil)
54-
GOVUKDesignSystemFormBuilder::Proxy.new(object, object_name, attribute_name, value: value)
54+
GOVUKDesignSystemFormBuilder::Proxy.new(object, object_name, attribute_name, value:)
5555
end
5656

5757
def proxy_builder(object, object_name, template, options)

lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def collection
6464
@attribute_name,
6565
check_box,
6666
@hint_method,
67-
link_errors: link_errors
67+
link_errors:
6868
).html.tap { link_errors = false }
6969
end
7070
end

lib/govuk_design_system_formbuilder/elements/date.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def input(segment, link_errors, width, value)
114114
name: name(segment),
115115
type: 'text',
116116
inputmode: 'numeric',
117-
value: value,
117+
value:,
118118
autocomplete: date_of_birth_autocomplete_value(segment),
119119
maxlength: (width if maxlength_enabled?),
120120
)
@@ -134,7 +134,7 @@ def classes(width)
134134
# in the normal fashion
135135
def id(segment, link_errors)
136136
if has_errors? && link_errors
137-
field_id(link_errors: link_errors)
137+
field_id(link_errors:)
138138
else
139139
[@object_name, @attribute_name, SEGMENTS.fetch(segment)].join("_")
140140
end

lib/govuk_design_system_formbuilder/traits/localisation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Traits
33
module Localisation
44
# starts with an letter that is followed by other word characters or
55
# spaces, zero or more times
6-
BASE_NAME_REGEXP = %r{[[:alpha:]](?:[\w\s]*)}.freeze
6+
BASE_NAME_REGEXP = %r{[[:alpha:]](?:[\w\s]*)}
77

88
private
99

spec/govuk_design_system_formbuilder/builder/check_boxes/check_box_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
with_tag('input', with: {
1717
id: "person-stationery-#{value_with_dashes}-field",
1818
type: 'checkbox',
19-
value: value
19+
value:
2020
})
2121
end
2222
end

spec/govuk_design_system_formbuilder/builder/check_boxes/fieldset_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
let(:caption_class) { "govuk-caption-#{caption_size}" }
6060

6161
subject do
62-
builder.send(*args, legend: legend, caption: caption, &example_block)
62+
builder.send(*args, legend:, caption:, &example_block)
6363
end
6464

6565
context 'with a legend' do

spec/govuk_design_system_formbuilder/builder/error_summary_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
builder.safe_join(
270270
[
271271
builder.govuk_error_summary,
272-
builder.govuk_date_field(:born_on, omit_day: omit_day)
272+
builder.govuk_date_field(:born_on, omit_day:)
273273
]
274274
)
275275
end
@@ -397,7 +397,7 @@
397397

398398
context 'when an override is specified' do
399399
let(:link_base_errors_to) { :name }
400-
subject { builder.send(method, link_base_errors_to: link_base_errors_to) }
400+
subject { builder.send(method, link_base_errors_to:) }
401401

402402
specify 'the override field should be linked to' do
403403
expect(subject).to have_tag("a", text: error, with: { href: %(#person-#{link_base_errors_to}-field) })

spec/govuk_design_system_formbuilder/builder/fieldset_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
let(:caption_class) { "govuk-caption-#{caption_size}" }
103103

104104
subject do
105-
builder.send(method, legend: legend, caption: caption, &example_block)
105+
builder.send(method, legend:, caption:, &example_block)
106106
end
107107

108108
context 'with a legend' do

0 commit comments

Comments
 (0)