Skip to content

Commit 7d32cf8

Browse files
committed
Merge pull request #2474 from alphagov/fix-auto-correctable-rubocop-violations
Fix auto-correctable Rubocop violations (feedback addressed)
2 parents 7bfde86 + 80a6145 commit 7d32cf8

File tree

166 files changed

+608
-1047
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+608
-1047
lines changed

.rubocop_todo.yml

-416
Large diffs are not rendered by default.

app/controllers/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def error_404; error(404); end
1818
def error_503(e = nil); error(503, e); end
1919

2020
def error(status_code, exception = nil)
21-
if exception and defined? Airbrake
21+
if exception && defined? Airbrake
2222
env["airbrake.error_id"] = notify_airbrake(exception)
2323
end
2424

app/controllers/smart_answers_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def render_text?(presenter)
6161
def with_format(format, &block)
6262
old_formats = self.formats
6363
self.formats = [format]
64-
result = yield
64+
result = block.call
6565
self.formats = old_formats
6666
result
6767
end
@@ -98,7 +98,7 @@ def set_expiry(duration = 30.minutes)
9898
# if the artefact returned from the Content API is blank, or if
9999
# the request to the Content API fails, set a very short cache so
100100
# we don't cache an incomplete page for a while
101-
duration = 5.seconds if @presenter.present? and @presenter.artefact.blank?
101+
duration = 5.seconds if @presenter.present? && @presenter.artefact.blank?
102102

103103
if Rails.configuration.set_http_cache_control_expiry_time
104104
expires_in(duration, public: true)

app/models/world_location.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.reset_cache
1414
def self.all
1515
cache_fetch("all") do
1616
Services.worldwide_api.world_locations.with_subsequent_pages.map do |l|
17-
new(l) if l.format == "World location" and l.details and l.details.slug.present?
17+
new(l) if l.format == "World location" && l.details && l.details.slug.present?
1818
end.compact
1919
end
2020
end
@@ -53,7 +53,7 @@ def initialize(data)
5353
end
5454

5555
def ==(other)
56-
other.is_a?(self.class) and other.slug == self.slug
56+
other.is_a?(self.class) && other.slug == self.slug
5757
end
5858

5959
def_delegators :@data, :title, :details
@@ -65,6 +65,6 @@ def organisations
6565
end
6666

6767
def fco_organisation
68-
self.organisations.find { |o| o.fco_sponsored? }
68+
self.organisations.find(&:fco_sponsored?)
6969
end
7070
end

app/presenters/flow_registration_presenter.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class FlowRegistrationPresenter
2-
32
def initialize(flow)
43
@flow = flow
54
end
@@ -33,7 +32,7 @@ def description
3332
end
3433

3534
module MethodMissingHelper
36-
def method_missing(method, *args, &block)
35+
def method_missing(method, *_args, &_block)
3736
MethodMissingObject.new(method, parent_method = nil, blank_to_s = true)
3837
end
3938
end

app/presenters/govspeak_presenter.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class GovspeakPresenter
2-
32
def initialize(markup)
43
@markup = markup
54
end

bin/setup

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'pathname'
33

44
# path to your application root.
5-
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
5+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
66

77
Dir.chdir APP_ROOT do
88
# This script is a starting point to setup your application.

config.ru

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# This file is used by Rack-based servers to start the application.
22

3-
require ::File.expand_path('../config/environment', __FILE__)
3+
require ::File.expand_path('../config/environment', __FILE__)
44
run SmartAnswers::Application

config/environments/test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
config.action_dispatch.show_exceptions = false
2222

2323
# Disable request forgery protection in test environment
24-
config.action_controller.allow_forgery_protection = false
24+
config.action_controller.allow_forgery_protection = false
2525

2626
# Use SQL instead of Active Record's schema dumper when creating the test database.
2727
# This is necessary if your schema can't be completely dumped by the schema dumper,

config/initializers/airbrake.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
config.api_key = ENV["ERRBIT_API_KEY"]
55
config.host = ENV["ERRBIT_HOST"]
66
config.environment_name = ENV["ERRBIT_ENV"]
7-
config.secure = ENV["ERRBIT_API_KEY"].present?
7+
config.secure = ENV["ERRBIT_API_KEY"].present?
88
end

lib/data/finance_weighting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def score(answer)
2525

2626
class BandedWeightingScore < Struct.new(:bands, :weight)
2727
def score(answer)
28-
range = bands.find { |b| b[:min] <= answer and (!b.has_key?(:max) or b[:max] >= answer) }[:score]
28+
range = bands.find { |b| b[:min] <= answer && (!b.has_key?(:max) || b[:max] >= answer) }[:score]
2929
range * weight
3030
end
3131
end

lib/friendly_time_diff.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module FriendlyTimeDiff
2-
32
def friendly_time_diff(from_time, to_time)
43
FriendlyDateDiff.new(from_time.to_date, to_time.to_date).describe
54
end
65

76
private
7+
88
class FriendlyDateDiff
99
include ActionView::Helpers::TextHelper
1010
attr_reader :from_date, :to_date
@@ -19,6 +19,7 @@ def describe
1919
end
2020

2121
private
22+
2223
def date_parts
2324
[
2425
date_part('year', whole_years_away),

lib/graph_presenter.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,22 @@ def to_hash
4545
end
4646

4747
private
48+
4849
def graph_label_text(node)
4950
text = node.class.to_s.split("::").last + "\n-\n"
5051
case node
5152
when SmartAnswer::Question::MultipleChoice
5253
text << word_wrap(node_title(node))
5354
text << "\n\n"
5455
text << node.permitted_options.map do |option|
55-
"( ) #{option}"
56-
end.join("\n")
56+
"( ) #{option}"
57+
end.join("\n")
5758
when SmartAnswer::Question::Checkbox
5859
text << word_wrap(node_title(node))
5960
text << "\n\n"
6061
text << node.options.map do |option|
61-
"[ ] #{option}"
62-
end.join("\n")
62+
"[ ] #{option}"
63+
end.join("\n")
6364
when SmartAnswer::Question::Base
6465
text << word_wrap(node_title(node))
6566
when SmartAnswer::Outcome
@@ -77,7 +78,7 @@ def word_wrap(text, line_width = 40)
7778
end
7879

7980
module MethodMissingHelper
80-
def method_missing(method, *args, &block)
81+
def method_missing(method, *_args, &_block)
8182
MethodMissingObject.new(method)
8283
end
8384
end

lib/graphviz_presenter.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def label_lines
3333
)
3434
end
3535
attribute_clause = attrs.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
36-
%Q{#{normalize_name(name)} [#{attribute_clause}]}
36+
%{#{normalize_name(name)} [#{attribute_clause}]}
3737
end
3838
end
3939

@@ -49,7 +49,7 @@ def edge_lines
4949
adjacency_list.map do |name, exits|
5050
exits.map do |nextnode, label|
5151
next unless nextnode
52-
%Q{#{normalize_name(name)}->#{normalize_name(nextnode)} [label="#{label}"];}
52+
%{#{normalize_name(name)}->#{normalize_name(nextnode)} [label="#{label}"];}
5353
end
5454
end.flatten
5555
end
@@ -58,7 +58,7 @@ def metadata_lines
5858
[
5959
'overlap=false;',
6060
'splines=true;',
61-
%Q{label="#{escape(presenter.title)}";},
61+
%{label="#{escape(presenter.title)}";},
6262
'fontsize=12;'
6363
]
6464
end

lib/method_missing_object.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def initialize(method, parent_method = nil, blank_to_s = false)
55
@blank_to_s = blank_to_s
66
end
77

8-
def method_missing(method, *args, &block)
8+
def method_missing(method, *_args, &_block)
99
MethodMissingObject.new(method, parent_method = self, blank_to_s = @blank_to_s)
1010
end
1111

lib/smart_answer/age_related_allowance_chooser.rb

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module SmartAnswer
22
class AgeRelatedAllowanceChooser
3-
43
# created for married couples allowance calculator.
54
# this could be extended for use across smart answers
65
# and/or GOV.UK
@@ -40,6 +39,5 @@ def get_age_related_allowance(birth_date)
4039
age_related_allowance = @over_75_allowance
4140
end
4241
end
43-
4442
end
4543
end

lib/smart_answer/calculators/arrested_abroad.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize
88
end
99

1010
def generate_url_for_download(country, field, text)
11-
country_data = @data.select { |c| c["slug"] == country }.first
11+
country_data = @data.find { |c| c["slug"] == country }
1212
return "" unless country_data
1313

1414
url = country_data[field]
@@ -35,7 +35,7 @@ def countries_with_regions
3535
end
3636

3737
def get_country_regions(slug)
38-
@data.select { |c| c["slug"] == slug }.first["regions"]
38+
@data.find { |c| c["slug"] == slug }["regions"]
3939
end
4040
end
4141
end

lib/smart_answer/calculators/birth_calculator.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ def initialize(match_or_due_date)
1010

1111
def expected_week
1212
expected_start = @due_date - @due_date.wday
13-
expected_start .. expected_start + 6.days
13+
expected_start..expected_start + 6.days
1414
end
1515

1616
def qualifying_week
1717
qualifying_start = 15.weeks.ago(expected_week.first)
18-
qualifying_start .. qualifying_start + 6.days
18+
qualifying_start..qualifying_start + 6.days
1919
end
2020

2121
def employment_start
2222
25.weeks.ago(qualifying_week.last)
2323
end
24-
2524
end
2625
end

lib/smart_answer/calculators/child_maintenance_calculator.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module SmartAnswer::Calculators
22
class ChildMaintenanceCalculator
3-
43
attr_accessor :income, :number_of_other_children, :number_of_shared_care_nights
54

65
SCHEME_BASE_AMOUNT = 7.00

lib/smart_answer/calculators/commodity_code_calculator.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module SmartAnswer::Calculators
22
class CommodityCodeCalculator
3-
43
attr_reader :matrix_data, :commodity_code_matrix
54
attr_accessor :milk_protein_weight
65

lib/smart_answer/calculators/country_name_formatter.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module SmartAnswer::Calculators
22
class CountryNameFormatter
3-
43
COUNTRIES_WITH_DEFINITIVE_ARTICLES = %w(bahamas british-virgin-islands cayman-islands czech-republic democratic-republic-of-congo dominican-republic falkland-islands gambia maldives marshall-islands netherlands philippines seychelles solomon-islands south-georgia-and-south-sandwich-islands turks-and-caicos-islands united-arab-emirates)
54

65
FRIENDLY_COUNTRY_NAME = {

lib/smart_answer/calculators/holiday_entitlement.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def method_missing(symbol, *args)
9999
end
100100

101101
def respond_to?(symbol, include_all = false)
102-
formatting_method(symbol).present?
102+
formatting_method(symbol).present? || super
103103
end
104104

105105
private

lib/smart_answer/calculators/landlord_immigration_check_calculator.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module SmartAnswer::Calculators
22
class LandlordImmigrationCheckCalculator
3-
43
VALID_COUNTRIES = %w( England )
54

65
attr_reader :postcode

lib/smart_answer/calculators/legalisation_documents_data_query.rb

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module SmartAnswer::Calculators
22
class LegalisationDocumentsDataQuery
3-
43
attr_reader :legalisation_document_data, :data
54

65
def initialize
@@ -15,6 +14,5 @@ def find_document_data(documents)
1514
def self.legalisation_document_data
1615
@legalisation_document_data ||= YAML.load_file(Rails.root.join("lib", "data", "legalisation_documents_data.yml"))
1716
end
18-
1917
end
2018
end

lib/smart_answer/calculators/maternity_paternity_calculator.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ class MaternityPaternityCalculator
1212
:a_notice_leave, :last_payday, :pre_offset_payday, :pay_date, :paternity_leave_duration,
1313
:pay_day_in_month, :pay_day_in_week, :pay_method, :pay_week_in_month, :work_days, :date_of_birth, :awe
1414

15-
DAYS_OF_THE_WEEK = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
15+
DAYS_OF_THE_WEEK = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
1616

1717
def initialize(match_or_due_date, leave_type = "maternity")
1818
expected_start = match_or_due_date - match_or_due_date.wday
1919
qualifying_start = 15.weeks.ago(expected_start)
2020

2121
@due_date = @match_date = match_or_due_date
2222
@leave_type = leave_type
23-
@expected_week = @matched_week = expected_start .. expected_start + 6.days
23+
@expected_week = @matched_week = expected_start..expected_start + 6.days
2424
@notice_of_leave_deadline = next_saturday(qualifying_start)
25-
@qualifying_week = qualifying_start .. qualifying_start + 6.days
25+
@qualifying_week = qualifying_start..qualifying_start + 6.days
2626
@employment_start = 25.weeks.ago(@qualifying_week.last)
2727
@a_employment_start = 25.weeks.ago(@matched_week.last)
2828
@leave_earliest_start_date = 11.weeks.ago(@expected_week.first)
@@ -206,7 +206,7 @@ def paydates_weekly
206206
def paydates_weekly_starting
207207
[].tap do |ary|
208208
pay_start_date.step(pay_end_date) do |d|
209-
ary << d if d.wday == (pay_start_date - 1).wday and d > pay_start_date
209+
ary << d if d.wday == (pay_start_date - 1).wday && d > pay_start_date
210210
end
211211
end
212212
end
@@ -217,7 +217,7 @@ def paydates_a_certain_week_day_each_month
217217
weekdays = weekdays_for_month(date, pay_day_in_week)
218218
ary << weekdays.send(pay_week_in_month)
219219
end
220-
if ary.last and ary.last < pay_end_date
220+
if ary.last && ary.last < pay_end_date
221221
weekdays = weekdays_for_month(1.month.since(pay_end_date), pay_day_in_week)
222222
ary << weekdays.send(pay_week_in_month)
223223
end
@@ -231,7 +231,7 @@ def statutory_rate(date)
231231
{ min: uprating_date(2014), max: uprating_date(2015), amount: 138.18 },
232232
{ min: uprating_date(2014), max: uprating_date(2100), amount: 139.58 } ### Change year in future
233233
]
234-
rate = rates.find { |r| r[:min] <= date and date < r[:max] } || rates.last
234+
rate = rates.find { |r| r[:min] <= date && date < r[:max] } || rates.last
235235
rate[:amount]
236236
end
237237

@@ -256,7 +256,7 @@ def months_between_dates(start_date, end_date)
256256
end
257257

258258
def within_pay_date_range?(day)
259-
pay_start_date <= day and day <= pay_end_date
259+
pay_start_date <= day && day <= pay_end_date
260260
end
261261

262262
def rate_changes?(week)
@@ -266,7 +266,7 @@ def rate_changes?(week)
266266
def pay_for_period(start_date, end_date)
267267
pay = 0.0
268268
(start_date..end_date).each_slice(7) do |week|
269-
if week.size < 7 or !within_pay_date_range?(week.last) or rate_changes?(week)
269+
if week.size < 7 || !within_pay_date_range?(week.last) || rate_changes?(week)
270270
# When calculating a partial SMP pay week divide the weekly rate by 7
271271
# truncating the result at 5 decimal places and increment the total pay
272272
# for each day of the partial week
@@ -322,7 +322,7 @@ def first_sunday_in_month(month, year)
322322
end
323323

324324
def uprating_date(year)
325-
date = first_sunday_in_month(4 , year)
325+
date = first_sunday_in_month(4, year)
326326
date += leave_start_date.wday if leave_start_date
327327
date
328328
end

0 commit comments

Comments
 (0)