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

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 = ["[email protected]"]
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

spec/govuk_tech_docs/tech_docs_html_renderer_spec.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
RSpec.describe GovukTechDocs::TechDocsHTMLRenderer do
44
let(:app) { double("app") }
55
let(:context) { double("context") }
6-
let(:processor) {
6+
let(:processor) do
77
Redcarpet::Markdown.new(described_class.new(context: context), tables: true, fenced_code_blocks: true)
8-
}
8+
end
99

1010
before :each do
1111
allow(context).to receive(:app) { app }
1212
allow(app).to receive(:api)
1313
end
1414

1515
describe "#render a table" do
16-
let(:output) {
16+
let(:output) do
1717
processor.render <<~MARKDOWN
1818
| A | B |
1919
|------|---|
2020
|# C | D |
2121
| E | F |
2222
|# *G* | H |
2323
MARKDOWN
24-
}
24+
end
2525

2626
it "treats cells in the heading row as headings" do
2727
expect(output).to include("<th>A</th>")
@@ -45,7 +45,7 @@
4545
end
4646

4747
describe "#render a code block" do
48-
let(:output) {
48+
let(:output) do
4949
processor.render <<~MARKDOWN
5050
Hello world:
5151
@@ -55,12 +55,12 @@ def hello_world
5555
end
5656
```
5757
MARKDOWN
58-
}
58+
end
5959

6060
context "without syntax highlighting" do
61-
let(:processor) {
61+
let(:processor) do
6262
Redcarpet::Markdown.new(described_class.new(context: context), fenced_code_blocks: true)
63-
}
63+
end
6464

6565
it "sets tab index to 0" do
6666
expect(output).to include('<pre tabindex="0">')
@@ -73,14 +73,13 @@ def hello_world
7373
end
7474
end
7575

76-
7776
context "with syntax highlighting" do
78-
let(:processor) {
77+
let(:processor) do
7978
renderer_class = described_class.clone.tap do |c|
8079
c.send :include, Middleman::Syntax::RedcarpetCodeRenderer
8180
end
8281
Redcarpet::Markdown.new(renderer_class.new(context: context), fenced_code_blocks: true)
83-
}
82+
end
8483

8584
it "sets tab index to 0" do
8685
expect(output).to include('<pre class=" ruby" tabindex="0">')

spec/spec_helper.rb

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -56,57 +56,55 @@
5656
# triggering implicit auto-inclusion in groups with matching metadata.
5757
config.shared_context_metadata_behavior = :apply_to_host_groups
5858

59-
# The settings below are suggested to provide a good initial experience
60-
# with RSpec, but feel free to customize to your heart's content.
61-
=begin
62-
# This allows you to limit a spec run to individual examples or groups
63-
# you care about by tagging them with `:focus` metadata. When nothing
64-
# is tagged with `:focus`, all examples get run. RSpec also provides
65-
# aliases for `it`, `describe`, and `context` that include `:focus`
66-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
67-
config.filter_run_when_matching :focus
68-
69-
# Allows RSpec to persist some state between runs in order to support
70-
# the `--only-failures` and `--next-failure` CLI options. We recommend
71-
# you configure your source control system to ignore this file.
72-
config.example_status_persistence_file_path = "spec/examples.txt"
73-
74-
# Limits the available syntax to the non-monkey patched syntax that is
75-
# recommended. For more details, see:
76-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
77-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
78-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
79-
config.disable_monkey_patching!
80-
81-
# This setting enables warnings. It's recommended, but in some cases may
82-
# be too noisy due to issues in dependencies.
83-
config.warnings = true
84-
85-
# Many RSpec users commonly either run the entire suite or an individual
86-
# file, and it's useful to allow more verbose output when running an
87-
# individual spec file.
88-
if config.files_to_run.one?
89-
# Use the documentation formatter for detailed output,
90-
# unless a formatter has already been configured
91-
# (e.g. via a command-line flag).
92-
config.default_formatter = 'doc'
93-
end
94-
95-
# Print the 10 slowest examples and example groups at the
96-
# end of the spec run, to help surface which specs are running
97-
# particularly slow.
98-
config.profile_examples = 10
99-
100-
# Run specs in random order to surface order dependencies. If you find an
101-
# order dependency and want to debug it, you can fix the order by providing
102-
# the seed, which is printed after each run.
103-
# --seed 1234
104-
config.order = :random
105-
106-
# Seed global randomization in this process using the `--seed` CLI option.
107-
# Setting this allows you to use `--seed` to deterministically reproduce
108-
# test failures related to randomization by passing the same `--seed` value
109-
# as the one that triggered the failure.
110-
Kernel.srand config.seed
111-
=end
59+
# The settings below are suggested to provide a good initial experience
60+
# with RSpec, but feel free to customize to your heart's content.
61+
# # This allows you to limit a spec run to individual examples or groups
62+
# # you care about by tagging them with `:focus` metadata. When nothing
63+
# # is tagged with `:focus`, all examples get run. RSpec also provides
64+
# # aliases for `it`, `describe`, and `context` that include `:focus`
65+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
66+
# config.filter_run_when_matching :focus
67+
#
68+
# # Allows RSpec to persist some state between runs in order to support
69+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
70+
# # you configure your source control system to ignore this file.
71+
# config.example_status_persistence_file_path = "spec/examples.txt"
72+
#
73+
# # Limits the available syntax to the non-monkey patched syntax that is
74+
# # recommended. For more details, see:
75+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
76+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
77+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
78+
# config.disable_monkey_patching!
79+
#
80+
# # This setting enables warnings. It's recommended, but in some cases may
81+
# # be too noisy due to issues in dependencies.
82+
# config.warnings = true
83+
#
84+
# # Many RSpec users commonly either run the entire suite or an individual
85+
# # file, and it's useful to allow more verbose output when running an
86+
# # individual spec file.
87+
# if config.files_to_run.one?
88+
# # Use the documentation formatter for detailed output,
89+
# # unless a formatter has already been configured
90+
# # (e.g. via a command-line flag).
91+
# config.default_formatter = 'doc'
92+
# end
93+
#
94+
# # Print the 10 slowest examples and example groups at the
95+
# # end of the spec run, to help surface which specs are running
96+
# # particularly slow.
97+
# config.profile_examples = 10
98+
#
99+
# # Run specs in random order to surface order dependencies. If you find an
100+
# # order dependency and want to debug it, you can fix the order by providing
101+
# # the seed, which is printed after each run.
102+
# # --seed 1234
103+
# config.order = :random
104+
#
105+
# # Seed global randomization in this process using the `--seed` CLI option.
106+
# # Setting this allows you to use `--seed` to deterministically reproduce
107+
# # test failures related to randomization by passing the same `--seed` value
108+
# # as the one that triggered the failure.
109+
# Kernel.srand config.seed
112110
end

0 commit comments

Comments
 (0)