Skip to content

Commit

Permalink
Run Rubocop with autocorrect
Browse files Browse the repository at this point in the history
This is mainly:

* tidying up hashes where the values are variables named after the key
* removing unnecessary freezing
  • Loading branch information
peteryates committed Jan 28, 2024
1 parent c2d633e commit 064baad
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion guide/lib/helpers/header_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module HeaderHelper
def header(level: 2, id: nil, classes: nil)
tag = "h#{level}"

{ tag: tag, id: id, class: classes }.compact
{ tag:, id:, class: classes }.compact
end
end
end
16 changes: 8 additions & 8 deletions guide/lib/setup/example_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ def custom_error_presenter

def form_data
{
departments: departments,
departments_collection: departments_collection,
contact_types: contact_types,
lunch_options: lunch_options,
grouped_lunch_options: grouped_lunch_options,
primary_colours: primary_colours,
laptops: laptops,
custom_error_presenter: custom_error_presenter,
departments:,
departments_collection:,
contact_types:,
lunch_options:,
grouped_lunch_options:,
primary_colours:,
laptops:,
custom_error_presenter:,
}
end
end
Expand Down
106 changes: 53 additions & 53 deletions lib/govuk_design_system_formbuilder/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module Builder
# label: -> { tag.h3('Call-sign') }
#
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)
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
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
end

# Generates a input of type +tel+
Expand Down Expand Up @@ -107,7 +107,7 @@ def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: ni
# label: -> { tag.h3('Work number') }
#
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)
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
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
end

# Generates a input of type +email+
Expand Down Expand Up @@ -159,7 +159,7 @@ def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: n
# label: -> { tag.h3('Personal email address') }
#
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)
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
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
end

# Generates a input of type +password+
Expand Down Expand Up @@ -210,7 +210,7 @@ def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: n
# label: -> { tag.h3('What is your secret pass code?') }
#
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)
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
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
end

# Generates a input of type +url+
Expand Down Expand Up @@ -262,7 +262,7 @@ def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, extra_
# label: -> { tag.h3("Enter your company's website") }
#
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)
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
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
end

# Generates a input of type +number+
Expand Down Expand Up @@ -317,7 +317,7 @@ def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
#
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)
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
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
end

# Generates a +textarea+ element with a label, optional hint. Also offers
Expand Down Expand Up @@ -373,7 +373,7 @@ def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width:
# label: -> { tag.h3("How do you set it up?") }
#
def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block)
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
Elements::TextArea.new(self, object_name, attribute_name, hint:, label:, caption:, max_words:, max_chars:, rows:, threshold:, form_group:, **kwargs, &block).html
end

# Generates a +select+ element containing +option+ for each member in the provided collection
Expand Down Expand Up @@ -422,13 +422,13 @@ def govuk_collection_select(attribute_name, collection, value_method, text_metho
object_name,
attribute_name,
collection,
value_method: value_method,
text_method: text_method,
hint: hint,
label: label,
caption: caption,
options: options,
form_group: form_group,
value_method:,
text_method:,
hint:,
label:,
caption:,
options:,
form_group:,
**kwargs,
&block
).html
Expand Down Expand Up @@ -466,7 +466,7 @@ def govuk_collection_select(attribute_name, collection, value_method, text_metho
# = f.govuk_select :hat_colour, options_for_select(@colours)
#
def govuk_select(attribute_name, choices = nil, options: {}, label: {}, hint: {}, form_group: {}, caption: {}, **kwargs, &block)
Elements::Select.new(self, object_name, attribute_name, choices, options: options, label: label, hint: hint, form_group: form_group, caption: caption, **kwargs, &block).html
Elements::Select.new(self, object_name, attribute_name, choices, options:, label:, hint:, form_group:, caption:, **kwargs, &block).html
end

# Generates a radio button for each item in the supplied collection
Expand Down Expand Up @@ -546,17 +546,17 @@ def govuk_collection_radio_buttons(attribute_name, collection, value_method, tex
object_name,
attribute_name,
collection,
value_method: value_method,
text_method: text_method,
hint_method: hint_method,
hint: hint,
legend: legend,
caption: caption,
inline: inline,
small: small,
bold_labels: bold_labels,
form_group: form_group,
include_hidden: include_hidden,
value_method:,
text_method:,
hint_method:,
hint:,
legend:,
caption:,
inline:,
small:,
bold_labels:,
form_group:,
include_hidden:,
**kwargs,
&block
).html
Expand Down Expand Up @@ -611,7 +611,7 @@ def govuk_collection_radio_buttons(attribute_name, collection, value_method, tex
# = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
#
def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, form_group: {}, **kwargs, &block)
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
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint:, legend:, caption:, inline:, small:, form_group:, **kwargs, &block).html
end

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

# Inserts a text divider into a list of radio buttons
Expand Down Expand Up @@ -725,15 +725,15 @@ def govuk_collection_check_boxes(attribute_name, collection, value_method, text_
object_name,
attribute_name,
collection,
value_method: value_method,
text_method: text_method,
hint_method: hint_method,
hint: hint,
legend: legend,
caption: caption,
small: small,
form_group: form_group,
include_hidden: include_hidden,
value_method:,
text_method:,
hint_method:,
hint:,
legend:,
caption:,
small:,
form_group:,
include_hidden:,
**kwargs,
&block
).html
Expand Down Expand Up @@ -782,12 +782,12 @@ def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}
self,
object_name,
attribute_name,
hint: hint,
legend: legend,
caption: caption,
small: small,
form_group: form_group,
multiple: multiple,
hint:,
legend:,
caption:,
small:,
form_group:,
multiple:,
**kwargs,
&block
).html
Expand Down Expand Up @@ -830,11 +830,11 @@ def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, la
attribute_name,
value,
unchecked_value,
hint: hint,
label: label,
link_errors: link_errors,
multiple: multiple,
exclusive: exclusive,
hint:,
label:,
link_errors:,
multiple:,
exclusive:,
**kwargs,
&block
).html
Expand Down Expand Up @@ -883,7 +883,7 @@ def govuk_check_box_divider(text = config.default_check_box_divider_text)
# = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
#
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)
Elements::Submit.new(self, text, warning: warning, secondary: secondary, inverse: inverse, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, **kwargs, &block).html
Elements::Submit.new(self, text, warning:, secondary:, inverse:, prevent_double_click:, validate:, disabled:, **kwargs, &block).html
end

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

# Generates a summary of errors in the form, each linking to the corresponding
Expand Down Expand Up @@ -962,7 +962,7 @@ def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_
#
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
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)
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, order: order, presenter: presenter, **kwargs, &block).html
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to:, order:, presenter:, **kwargs, &block).html
end

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

# Generates an input of type +file+
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
# the Rails documentation} for more information
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **kwargs, &block).html
Elements::File.new(self, object_name, attribute_name, label:, caption:, hint:, form_group:, **kwargs, &block).html
end
end
end
4 changes: 2 additions & 2 deletions lib/govuk_design_system_formbuilder/builder_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module BuilderHelper
def govuk_field_id(object, attribute_name, object_name = nil, value: nil, link_errors: true)
(object_name = retrieve_object_name(object)) if object_name.nil?

proxy_base(object, object_name, attribute_name, value: value).field_id(link_errors: link_errors)
proxy_base(object, object_name, attribute_name, value:).field_id(link_errors:)
end

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

def proxy_base(object, object_name, attribute_name, value: nil)
GOVUKDesignSystemFormBuilder::Proxy.new(object, object_name, attribute_name, value: value)
GOVUKDesignSystemFormBuilder::Proxy.new(object, object_name, attribute_name, value:)
end

def proxy_builder(object, object_name, template, options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def collection
@attribute_name,
check_box,
@hint_method,
link_errors: link_errors
link_errors:
).html.tap { link_errors = false }
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/govuk_design_system_formbuilder/elements/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def input(segment, link_errors, width, value)
name: name(segment),
type: 'text',
inputmode: 'numeric',
value: value,
value:,
autocomplete: date_of_birth_autocomplete_value(segment),
maxlength: (width if maxlength_enabled?),
)
Expand All @@ -134,7 +134,7 @@ def classes(width)
# in the normal fashion
def id(segment, link_errors)
if has_errors? && link_errors
field_id(link_errors: link_errors)
field_id(link_errors:)
else
[@object_name, @attribute_name, SEGMENTS.fetch(segment)].join("_")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk_design_system_formbuilder/traits/localisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Traits
module Localisation
# starts with an letter that is followed by other word characters or
# spaces, zero or more times
BASE_NAME_REGEXP = %r{[[:alpha:]](?:[\w\s]*)}.freeze
BASE_NAME_REGEXP = %r{[[:alpha:]](?:[\w\s]*)}

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
with_tag('input', with: {
id: "person-stationery-#{value_with_dashes}-field",
type: 'checkbox',
value: value
value:
})
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
let(:caption_class) { "govuk-caption-#{caption_size}" }

subject do
builder.send(*args, legend: legend, caption: caption, &example_block)
builder.send(*args, legend:, caption:, &example_block)
end

context 'with a legend' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
builder.safe_join(
[
builder.govuk_error_summary,
builder.govuk_date_field(:born_on, omit_day: omit_day)
builder.govuk_date_field(:born_on, omit_day:)
]
)
end
Expand Down Expand Up @@ -397,7 +397,7 @@

context 'when an override is specified' do
let(:link_base_errors_to) { :name }
subject { builder.send(method, link_base_errors_to: link_base_errors_to) }
subject { builder.send(method, link_base_errors_to:) }

specify 'the override field should be linked to' do
expect(subject).to have_tag("a", text: error, with: { href: %(#person-#{link_base_errors_to}-field) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
let(:caption_class) { "govuk-caption-#{caption_size}" }

subject do
builder.send(method, legend: legend, caption: caption, &example_block)
builder.send(method, legend:, caption:, &example_block)
end

context 'with a legend' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
let(:hint_method) { nil }

subject do
builder.send(*args.push(hint_method), bold_labels: bold_labels)
builder.send(*args.push(hint_method), bold_labels:)
end

context 'when bold_labels: nil' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
let(:caption_class) { "govuk-caption-#{caption_size}" }

subject do
builder.send(*args, legend: legend, caption: caption, &example_block)
builder.send(*args, legend:, caption:, &example_block)
end

context 'with a legend' do
Expand Down
Loading

0 comments on commit 064baad

Please sign in to comment.