Skip to content

Commit 0c2e641

Browse files
committed
Add rubocop and clean up some code items
1 parent 6290497 commit 0c2e641

16 files changed

+168
-37
lines changed

.rubocop.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# The behavior of RuboCop can be controlled via the .rubocop.yml
2+
# configuration file. It makes it possible to enable/disable
3+
# certain cops (checks) and to alter their behavior if they accept
4+
# any parameters. The file can be placed either in your home
5+
# directory or in some project directory.
6+
#
7+
# RuboCop will start looking for the configuration file in the directory
8+
# where the inspected file is and continue its way up to the root directory.
9+
#
10+
# See https://docs.rubocop.org/rubocop/configuration
11+
12+
plugins:
13+
- rubocop-capybara
14+
- rubocop-rspec
15+
16+
AllCops:
17+
NewCops: enable
18+
19+
# Conveniences because we're using Jekyll
20+
21+
RSpec/DescribeClass:
22+
Enabled: false
23+
24+
Style/Documentation:
25+
Enabled: false
26+
27+
RSpec/ExampleLength:
28+
Max: 15
29+
30+
# end Jekyl-specific choices
31+
32+
# Settings copied over from team preferences for Partner Portal
33+
34+
RSpec/NotToNot:
35+
EnforcedStyle: to_not
36+
37+
Capybara/NegationMatcher:
38+
EnforcedStyle: not_to
39+
40+
Layout/FirstHashElementIndentation:
41+
EnforcedStyle: consistent
42+
43+
RSpec/ExpectChange:
44+
# A couple people expressed a preference for block
45+
EnforcedStyle: block
46+
47+
Naming/RescuedExceptionsVariableName:
48+
PreferredName: err
49+
50+
Style/HashSyntax:
51+
EnforcedShorthandSyntax: consistent
52+
53+
Layout/DotPosition:
54+
EnforcedStyle: leading
55+
56+
Layout/MultilineMethodCallIndentation:
57+
Enabled: false
58+
59+
Layout/FirstArgumentIndentation:
60+
Enabled: false
61+
62+
RSpec/MultipleExpectations:
63+
Enabled: false
64+
65+
# End team settings from Partner Portal

Gemfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
ruby File.read('.ruby-version').strip
46

57
gem 'jekyll', '~> 4.3.0'
6-
gem 'jekyll-sass-converter', '~> 3.0.0'
7-
gem 'kramdown-parser-gfm', '~> 1.0'
88
gem 'jekyll-redirect-from'
9+
gem 'jekyll-sass-converter', '~> 3.0.0'
910
gem 'jekyll-sitemap'
11+
gem 'kramdown-parser-gfm', '~> 1.0'
1012

1113
group :development, :test do
1214
gem 'pry-byebug'
15+
gem 'rubocop', require: false
16+
gem 'rubocop-capybara', require: false
17+
gem 'rubocop-rspec', require: false
1318
end
1419

1520
group :test do
1621
gem 'capybara'
1722
gem 'html-proofer', '~> 4.0'
1823
gem 'nokogiri', '>= 1.10.5'
19-
gem 'rackup' # required for `Capybara.server = :webrick`
2024
gem 'rack-jekyll'
25+
gem 'rackup' # required for `Capybara.server = :webrick`
2126
gem 'rspec'
2227
gem 'rspec_junit_formatter', require: false
2328
gem 'selenium-webdriver'

Gemfile.lock

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ GEM
33
specs:
44
addressable (2.8.7)
55
public_suffix (>= 2.0.2, < 7.0)
6+
ast (2.4.3)
67
base64 (0.3.0)
78
bigdecimal (3.1.8)
89
byebug (12.0.0)
@@ -66,10 +67,13 @@ GEM
6667
jekyll (>= 3.7, < 5.0)
6768
jekyll-watch (2.2.1)
6869
listen (~> 3.0)
70+
json (2.12.2)
6971
kramdown (2.4.0)
7072
rexml
7173
kramdown-parser-gfm (1.1.0)
7274
kramdown (~> 2.0)
75+
language_server-protocol (3.17.0.5)
76+
lint_roller (1.1.0)
7377
liquid (4.0.4)
7478
listen (3.9.0)
7579
rb-fsevent (~> 0.10, >= 0.10.3)
@@ -84,8 +88,12 @@ GEM
8488
mini_portile2 (~> 2.8.2)
8589
racc (~> 1.4)
8690
parallel (1.26.3)
91+
parser (3.3.8.0)
92+
ast (~> 2.4.1)
93+
racc
8794
pathutil (0.16.2)
8895
forwardable-extended (~> 2.6)
96+
prism (1.4.0)
8997
pry (0.15.2)
9098
coderay (~> 1.1)
9199
method_source (~> 1.0)
@@ -127,6 +135,27 @@ GEM
127135
rspec-support (3.13.1)
128136
rspec_junit_formatter (0.6.0)
129137
rspec-core (>= 2, < 4, != 2.12.0)
138+
rubocop (1.76.1)
139+
json (~> 2.3)
140+
language_server-protocol (~> 3.17.0.2)
141+
lint_roller (~> 1.1.0)
142+
parallel (~> 1.10)
143+
parser (>= 3.3.0.2)
144+
rainbow (>= 2.2.2, < 4.0)
145+
regexp_parser (>= 2.9.3, < 3.0)
146+
rubocop-ast (>= 1.45.0, < 2.0)
147+
ruby-progressbar (~> 1.7)
148+
unicode-display_width (>= 2.4.0, < 4.0)
149+
rubocop-ast (1.45.1)
150+
parser (>= 3.3.7.2)
151+
prism (~> 1.4)
152+
rubocop-capybara (2.22.1)
153+
lint_roller (~> 1.1)
154+
rubocop (~> 1.72, >= 1.72.1)
155+
rubocop-rspec (3.6.0)
156+
lint_roller (~> 1.1)
157+
rubocop (~> 1.72, >= 1.72.1)
158+
ruby-progressbar (1.13.0)
130159
rubyzip (2.4.1)
131160
safe_yaml (1.0.5)
132161
sass-embedded (1.80.6)
@@ -167,6 +196,9 @@ DEPENDENCIES
167196
rackup
168197
rspec
169198
rspec_junit_formatter
199+
rubocop
200+
rubocop-capybara
201+
rubocop-rspec
170202
selenium-webdriver
171203

172204
RUBY VERSION

_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ exclude:
4444
- .sass-cache/
4545
- .jekyll-cache/
4646
- assets/scss
47+
- bin
4748
- gemfiles/
4849
- Gemfile
4950
- Gemfile.lock
5051
- node_modules/
52+
- scripts
53+
- spec
5154
- vendor/bundle/
5255
- vendor/cache/
5356
- vendor/gems/

_plugins/content_code.rb

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1+
# frozen_string_literal: true
2+
13
require 'rouge'
24

35
# Include tabindex for accessibility reasons
46
# See: https://github.com/rouge-ruby/rouge?tab=readme-ov-file#formatters
5-
class Rouge::Formatters::HTMLPygmentsA11y < Rouge::Formatters::HTMLPygments
6-
def stream(tokens, &b)
7-
yield %(<div class="highlight"><pre class="#{@css_class}" tabindex="0"><code>)
8-
@inner.stream(tokens, &b)
9-
yield "</code></pre></div>"
7+
module Rouge
8+
module Formatters
9+
class HTMLPygmentsA11y < Rouge::Formatters::HTMLPygments
10+
def stream(tokens, &)
11+
yield %(<div class="highlight"><pre class="#{@css_class}" tabindex="0"><code>)
12+
@inner.stream(tokens, &)
13+
yield '</code></pre></div>'
14+
end
15+
end
1016
end
1117
end
1218

13-
class Rouge::Formatters::HTMLLegacyA11y < Rouge::Formatters::HTMLLegacy
14-
def initialize(opts={})
15-
@formatter = opts[:inline_theme] ? Rouge::Formatters::HTMLInline.new(opts[:inline_theme])
16-
: Rouge::Formatters::HTML.new
19+
module Rouge
20+
module Formatters
21+
class HTMLLegacyA11y < Rouge::Formatters::HTMLLegacy
22+
def initialize(opts = {}) # rubocop:disable Lint/MissingSuper
23+
@formatter = if opts[:inline_theme]
24+
Rouge::Formatters::HTMLInline.new(opts[:inline_theme])
25+
else
26+
Rouge::Formatters::HTML.new
27+
end
1728

29+
@formatter = Rouge::Formatters::HTMLTable.new(@formatter, opts) if opts[:line_numbers]
1830

19-
@formatter = Rouge::Formatters::HTMLTable.new(@formatter, opts) if opts[:line_numbers]
31+
return unless opts.fetch(:wrap, true)
2032

21-
if opts.fetch(:wrap, true)
22-
@formatter = Rouge::Formatters::HTMLPygmentsA11y.new(@formatter, opts.fetch(:css_class, 'codehilite'))
33+
@formatter = Rouge::Formatters::HTMLPygmentsA11y.new(@formatter, opts.fetch(:css_class, 'codehilite'))
34+
end
2335
end
2436
end
2537
end

_plugins/content_typography.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
# frozen_string_literal: true
2+
13
module Kramdown
24
module Parser
35
class Kramdown
6+
# rubocop:disable Naming/MethodParameterName
47
prepend(Module.new do
58
def add_link(el, *args)
69
add_link_class!(el) if el.type == :a
7-
super(el, *args)
10+
super
811
end
912

1013
def parse_autolink
@@ -17,6 +20,7 @@ def add_link_class!(el)
1720
el.attr['class'] = [*el.attr['class'], 'usa-link'].join(' ')
1821
end
1922
end)
23+
# rubocop:enable Naming/MethodParameterName
2024
end
2125
end
2226
end

_plugins/copy_to_destination.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# frozen_string_literal: true
2+
13
module Jekyll
24
module CopyToDestination
35
class CopyGenerator < Generator
4-
def generate(site)
6+
def generate(site) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
57
folders = site.config['copy_to_destination'] || []
68

79
static_files = folders.map do |relative_path|

_plugins/pretty_jsonify.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
# frozen_string_literal: true
2+
13
require 'json'
24

35
module LoginGov
46
module PrettyJsonify
57
def pretty_jsonify(input)
6-
json = if input.kind_of?(String)
7-
JSON.parse(input)
8-
else
9-
json
10-
end
8+
json = JSON.parse(input) if input.is_a?(String)
119

1210
JSON.pretty_generate(json)
1311
end

_plugins/yaml_content_disposition.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# frozen_string_literal: true
2+
13
require 'webrick'
24

35
module Jekyll
46
module Commands
57
class Serve
68
class Servlet < WEBrick::HTTPServlet::FileHandler
79
prepend(Module.new do
8-
def do_GET(req, res)
10+
def do_GET(req, res) # rubocop:disable Naming/MethodName
911
res.header.merge!('Content-Disposition' => 'attachment') if req.path.end_with?('.yml')
1012
super
1113
end

scripts/htmlproofer

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
24
# Run HTMLProofer via Ruby so we can do advanced things like ignore bad peer certificates which turn
35
# up in external links.
46
require 'html-proofer'
@@ -22,7 +24,7 @@ proofer_options.merge!(
2224
typhoeus: {
2325
ssl_verifypeer: false,
2426
ssl_verifyhost: 0,
25-
followlocation: false,
27+
followlocation: false
2628
},
2729
swap_urls: {
2830
"http://localhost:#{site_config['port']}" => 'https://developers.login.gov'
@@ -39,7 +41,6 @@ proofer.before_request do |request|
3941
# Some URLs behave differently if `accept-language` header is not included. Remove this in the
4042
# future if it's no longer needed.
4143
request.options[:headers]['Accept-Language'] = '*'
42-
4344
end
4445

4546
proofer.run

0 commit comments

Comments
 (0)