Skip to content

Commit 5506067

Browse files
committed
Make linter happy
Ran `bundle exec rubocop -a` then fixed the rest by hand.
1 parent 172bb7a commit 5506067

File tree

15 files changed

+194
-188
lines changed

15 files changed

+194
-188
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

33
# Specify your gem's dependencies in govuk_tech_docs.gemspec
44
gemspec

govuk_tech_docs.gemspec

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# coding: utf-8
2-
lib = File.expand_path("../lib", __FILE__)
1+
require "English"
2+
3+
lib = File.expand_path("lib", __dir__)
34
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
45
require "govuk_tech_docs/version"
56

67
`npm install`
7-
abort 'npm install failed' unless $?.success?
8+
abort "npm install failed" unless $CHILD_STATUS.success?
89

9-
unless File.exist?('node_modules/govuk-frontend/govuk/all.scss')
10-
abort 'govuk-frontend npm package not installed'
10+
unless File.exist?("node_modules/govuk-frontend/govuk/all.scss")
11+
abort "govuk-frontend npm package not installed"
1112
end
1213

1314
Gem::Specification.new do |spec|
@@ -16,8 +17,8 @@ Gem::Specification.new do |spec|
1617
spec.authors = ["Government Digital Service"]
1718
spec.email = ["govuk-dev@digital.cabinet-office.gov.uk"]
1819

19-
spec.summary = %q{Gem to distribute the GOV.UK Tech Docs Template}
20-
spec.description = %q{Gem to distribute the GOV.UK Tech Docs Template. See https://github.com/alphagov/tech-docs-gem for the project.}
20+
spec.summary = "Gem to distribute the GOV.UK Tech Docs Template"
21+
spec.description = "Gem to distribute the GOV.UK Tech Docs Template. See https://github.com/alphagov/tech-docs-gem for the project."
2122
spec.homepage = "https://github.com/alphagov/tech-docs-gem"
2223
spec.license = "MIT"
2324

@@ -30,7 +31,9 @@ Gem::Specification.new do |spec|
3031

3132
spec.bindir = "exe"
3233
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33-
spec.require_paths = ["lib"]
34+
spec.require_paths = %w[lib]
35+
36+
spec.required_ruby_version = ">= 2.7.0"
3437

3538
spec.add_dependency "autoprefixer-rails", "~> 10.2"
3639
spec.add_dependency "chronic", "~> 0.10.2"

lib/govuk_tech_docs.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def format_date(date)
8686
def active_page(page_path)
8787
[
8888
page_path == "/" && current_page.path == "index.html",
89-
("/" + current_page.path) == page_path,
90-
current_page.data.parent != nil && current_page.data.parent.to_s == page_path,
89+
"/#{current_page.path}" == page_path,
90+
!current_page.data.parent.nil? && current_page.data.parent.to_s == page_path,
9191
].any?
9292
end
9393
end
@@ -109,9 +109,9 @@ def active_page(page_path)
109109
search.resources = [""]
110110

111111
search.fields = {
112-
title: { boost: 100, store: true, required: true },
112+
title: { boost: 100, store: true, required: true },
113113
content: { boost: 50, store: true },
114-
url: { index: false, store: true },
114+
url: { index: false, store: true },
115115
}
116116

117117
search.pipeline_remove = %w[stemmer stopWordFilter]

lib/govuk_tech_docs/api_reference/api_reference_extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def initialize(app, options_hash = {}, &block)
3737

3838
def uri?(string)
3939
uri = URI.parse(string)
40-
%w(http https).include?(uri.scheme)
40+
%w[http https].include?(uri.scheme)
4141
rescue URI::BadURIError
4242
false
4343
rescue URI::InvalidURIError

lib/govuk_tech_docs/api_reference/api_reference_renderer.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def schema_properties(schema_data)
124124
properties.merge!(all_of_schema.properties.to_h)
125125
end
126126

127-
properties.each_with_object({}) do |(name, schema), memo|
128-
memo[name] = case schema.type
129-
when "object"
130-
schema_properties(schema.items || schema)
131-
when "array"
132-
schema.items ? [schema_properties(schema.items)] : []
133-
else
134-
schema.example || schema.type
135-
end
127+
properties.transform_values do |schema|
128+
case schema.type
129+
when "object"
130+
schema_properties(schema.items || schema)
131+
when "array"
132+
schema.items ? [schema_properties(schema.items)] : []
133+
else
134+
schema.example || schema.type
135+
end
136136
end
137137
end
138138

@@ -144,7 +144,7 @@ def build_redcarpet(app)
144144
end
145145

146146
def get_renderer(file)
147-
template_path = File.join(File.dirname(__FILE__), "templates/" + file)
147+
template_path = File.join(File.dirname(__FILE__), "templates/#{file}")
148148
template = File.open(template_path, "r").read
149149
ERB.new(template)
150150
end

lib/govuk_tech_docs/redirects.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module GovukTechDocs
22
class Redirects
3-
LEADING_SLASH = %r[\A\/].freeze
3+
LEADING_SLASH = %r{\A/}.freeze
44

55
def initialize(context)
66
@context = context
@@ -11,7 +11,7 @@ def redirects
1111

1212
all_redirects.map do |from, to|
1313
# Middleman needs paths without leading slashes
14-
[from.sub(LEADING_SLASH, ""), to: to.sub(LEADING_SLASH, "")]
14+
[from.sub(LEADING_SLASH, ""), { to: to.sub(LEADING_SLASH, "") }]
1515
end
1616
end
1717

lib/govuk_tech_docs/table_of_contents/heading.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ def initialize(element_name:, text:, attributes:, page_url: "")
99
end
1010

1111
def size
12-
@element_name.scan(/h(\d)/) && $1 && Integer($1)
12+
@element_name.scan(/h(\d)/) && ::Regexp.last_match(1) && Integer(::Regexp.last_match(1))
1313
end
1414

1515
def href
1616
if @page_url != "" && size == 1
1717
@page_url
1818
else
19-
@page_url + "#" + @attributes["id"]
19+
"#{@page_url}##{@attributes['id']}"
2020
end
2121
end
2222

lib/govuk_tech_docs/table_of_contents/heading_tree_renderer.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ def render_tree(tree, indentation: DEFAULT_INDENTATION, level: nil)
2020
output = ""
2121

2222
if tree.heading
23-
output += indentation + %{<a href="#{tree.heading.href}"><span>#{tree.heading.title}</span></a>\n}
23+
output += indentation + %(<a href="#{tree.heading.href}"><span>#{tree.heading.title}</span></a>\n)
2424
end
2525

2626
if tree.children.any? && level < @max_level
27-
output += indentation + "<ul>\n" unless level.zero?
27+
output += "#{indentation}<ul>\n" unless level.zero?
2828

2929
tree.children.each do |child|
30-
output += indentation + INDENTATION_INCREMENT + "<li>\n"
30+
output += "#{indentation}#{INDENTATION_INCREMENT}<li>\n"
3131
output += render_tree(
3232
child,
3333
indentation: indentation + INDENTATION_INCREMENT * 2,
3434
level: level + 1,
3535
)
36-
output += indentation + INDENTATION_INCREMENT + "</li>\n"
36+
output += "#{indentation}#{INDENTATION_INCREMENT}</li>\n"
3737
end
3838

39-
output += indentation + "</ul>\n" unless level.zero?
39+
output += "#{indentation}</ul>\n" unless level.zero?
4040
end
4141

4242
output

lib/govuk_tech_docs/table_of_contents/helpers.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def list_items_from_headings(html, url: "", max_level: nil)
3232
headings = HeadingsBuilder.new(html, url).headings
3333

3434
if headings.none? { |heading| heading.size == 1 }
35-
raise "No H1 tag found. You have to at least add one H1 heading to the page: " + url
35+
raise "No H1 tag found. You have to at least add one H1 heading to the page: #{url}"
3636
end
3737

3838
tree = HeadingTreeBuilder.new(headings).tree
@@ -67,12 +67,12 @@ def render_page_tree(resources, current_page, config, current_page_html)
6767
if config[:http_prefix].end_with?("/")
6868
config[:http_prefix]
6969
else
70-
config[:http_prefix] + "/"
70+
"#{config[:http_prefix]}/"
7171
end
7272

7373
link_value = get_path_to_resource(config, resource, current_page)
7474
if resource.children.any? && resource.url != home_url
75-
output += %{<li><a href="#{link_value}"><span>#{resource.data.title}</span></a>\n}
75+
output += %(<li><a href="#{link_value}"><span>#{resource.data.title}</span></a>\n)
7676
output += render_page_tree(resource.children, current_page, config, current_page_html)
7777
output += "</li>\n"
7878
else

spec/api_reference/renderer_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require "capybara/rspec"
33
require "govuk_tech_docs/api_reference/api_reference_renderer"
44

5-
65
RSpec.describe GovukTechDocs::ApiReference::Renderer do
76
describe ".api_full" do
87
before(:each) do

0 commit comments

Comments
 (0)