Skip to content

[partner-portal-58] Enable rubocop #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# The behavior of RuboCop can be controlled via the .rubocop.yml
# configuration file. It makes it possible to enable/disable
# certain cops (checks) and to alter their behavior if they accept
# any parameters. The file can be placed either in your home
# directory or in some project directory.
#
# RuboCop will start looking for the configuration file in the directory
# where the inspected file is and continue its way up to the root directory.
#
# See https://docs.rubocop.org/rubocop/configuration

plugins:
- rubocop-capybara
- rubocop-rspec

AllCops:
NewCops: enable

# Conveniences because we're using Jekyll

RSpec/DescribeClass:
Enabled: false

Style/Documentation:
Enabled: false

RSpec/ExampleLength:
Max: 15

# end Jekyl-specific choices

# Settings copied over from team preferences for Partner Portal

RSpec/NotToNot:
EnforcedStyle: to_not

Capybara/NegationMatcher:
EnforcedStyle: not_to

Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

RSpec/ExpectChange:
# A couple people expressed a preference for block
EnforcedStyle: block

Naming/RescuedExceptionsVariableName:
PreferredName: err

Style/HashSyntax:
EnforcedShorthandSyntax: consistent

Layout/DotPosition:
EnforcedStyle: leading

Layout/MultilineMethodCallIndentation:
Enabled: false

Layout/FirstArgumentIndentation:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

# End team settings from Partner Portal

# Ruby 3.4 doesn't need this

Style/FrozenStringLiteralComment:
EnforcedStyle: never
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.5
3.4.1
10 changes: 7 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ source 'https://rubygems.org'

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

gem 'csv'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bump in Ruby version changes where Ruby's CSV lives

gem 'jekyll', '~> 4.3.0'
gem 'jekyll-sass-converter', '~> 3.0.0'
gem 'kramdown-parser-gfm', '~> 1.0'
gem 'jekyll-redirect-from'
gem 'jekyll-sass-converter', '~> 3.0.0'
gem 'jekyll-sitemap'
gem 'kramdown-parser-gfm', '~> 1.0'

group :development, :test do
gem 'pry-byebug'
gem 'rubocop', require: false
gem 'rubocop-capybara', require: false
gem 'rubocop-rspec', require: false
end

group :test do
gem 'capybara'
gem 'html-proofer', '~> 4.0'
gem 'nokogiri', '>= 1.10.5'
gem 'rackup' # required for `Capybara.server = :webrick`
gem 'rack-jekyll'
gem 'rackup' # required for `Capybara.server = :webrick`
gem 'rspec'
gem 'rspec_junit_formatter', require: false
gem 'selenium-webdriver'
Expand Down
36 changes: 35 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ GEM
specs:
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.3)
base64 (0.3.0)
bigdecimal (3.1.8)
byebug (12.0.0)
Expand All @@ -18,6 +19,7 @@ GEM
coderay (1.1.3)
colorator (1.1.0)
concurrent-ruby (1.3.4)
csv (3.3.5)
diff-lcs (1.5.1)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
Expand Down Expand Up @@ -66,10 +68,13 @@ GEM
jekyll (>= 3.7, < 5.0)
jekyll-watch (2.2.1)
listen (~> 3.0)
json (2.12.2)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
liquid (4.0.4)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
Expand All @@ -84,8 +89,12 @@ GEM
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.26.3)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
pathutil (0.16.2)
forwardable-extended (~> 2.6)
prism (1.4.0)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -127,6 +136,27 @@ GEM
rspec-support (3.13.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.76.1)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.45.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.45.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-capybara (2.22.1)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop-rspec (3.6.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
ruby-progressbar (1.13.0)
rubyzip (2.4.1)
safe_yaml (1.0.5)
sass-embedded (1.80.6)
Expand Down Expand Up @@ -155,6 +185,7 @@ PLATFORMS

DEPENDENCIES
capybara
csv
html-proofer (~> 4.0)
jekyll (~> 4.3.0)
jekyll-redirect-from
Expand All @@ -167,10 +198,13 @@ DEPENDENCIES
rackup
rspec
rspec_junit_formatter
rubocop
rubocop-capybara
rubocop-rspec
selenium-webdriver

RUBY VERSION
ruby 3.2.5p208
ruby 3.4.1p0

BUNDLED WITH
2.6.9
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ exclude:
- .sass-cache/
- .jekyll-cache/
- assets/scss
- bin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't currently used in this repo, but bundle binstubs might still be created locally depending on your dev env and should be ignored

- gemfiles/
- Gemfile
- Gemfile.lock
- node_modules/
- scripts
- spec
- vendor/bundle/
- vendor/cache/
- vendor/gems/
Expand Down
34 changes: 22 additions & 12 deletions _plugins/content_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@

# Include tabindex for accessibility reasons
# See: https://github.com/rouge-ruby/rouge?tab=readme-ov-file#formatters
class Rouge::Formatters::HTMLPygmentsA11y < Rouge::Formatters::HTMLPygments
def stream(tokens, &b)
yield %(<div class="highlight"><pre class="#{@css_class}" tabindex="0"><code>)
@inner.stream(tokens, &b)
yield "</code></pre></div>"
module Rouge
module Formatters
class HTMLPygmentsA11y < Rouge::Formatters::HTMLPygments
def stream(tokens, &)
yield %(<div class="highlight"><pre class="#{@css_class}" tabindex="0"><code>)
@inner.stream(tokens, &)
yield '</code></pre></div>'
end
end
end
end

class Rouge::Formatters::HTMLLegacyA11y < Rouge::Formatters::HTMLLegacy
def initialize(opts={})
@formatter = opts[:inline_theme] ? Rouge::Formatters::HTMLInline.new(opts[:inline_theme])
: Rouge::Formatters::HTML.new
module Rouge
module Formatters
class HTMLLegacyA11y < Rouge::Formatters::HTMLLegacy
def initialize(opts = {}) # rubocop:disable Lint/MissingSuper
@formatter = if opts[:inline_theme]
Rouge::Formatters::HTMLInline.new(opts[:inline_theme])
else
Rouge::Formatters::HTML.new
end

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

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

if opts.fetch(:wrap, true)
@formatter = Rouge::Formatters::HTMLPygmentsA11y.new(@formatter, opts.fetch(:css_class, 'codehilite'))
@formatter = Rouge::Formatters::HTMLPygmentsA11y.new(@formatter, opts.fetch(:css_class, 'codehilite'))
end
end
end
end
4 changes: 3 additions & 1 deletion _plugins/content_typography.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module Kramdown
module Parser
class Kramdown
# rubocop:disable Naming/MethodParameterName
prepend(Module.new do
def add_link(el, *args)
add_link_class!(el) if el.type == :a
super(el, *args)
super
end

def parse_autolink
Expand All @@ -17,6 +18,7 @@ def add_link_class!(el)
el.attr['class'] = [*el.attr['class'], 'usa-link'].join(' ')
end
end)
# rubocop:enable Naming/MethodParameterName
end
end
end
2 changes: 1 addition & 1 deletion _plugins/copy_to_destination.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Jekyll
module CopyToDestination
class CopyGenerator < Generator
def generate(site)
def generate(site) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
folders = site.config['copy_to_destination'] || []

static_files = folders.map do |relative_path|
Expand Down
6 changes: 1 addition & 5 deletions _plugins/pretty_jsonify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
module LoginGov
module PrettyJsonify
def pretty_jsonify(input)
json = if input.kind_of?(String)
JSON.parse(input)
else
json
end
json = JSON.parse(input) if input.is_a?(String)

JSON.pretty_generate(json)
end
Expand Down
2 changes: 1 addition & 1 deletion _plugins/yaml_content_disposition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Commands
class Serve
class Servlet < WEBrick::HTTPServlet::FileHandler
prepend(Module.new do
def do_GET(req, res)
def do_GET(req, res) # rubocop:disable Naming/MethodName
res.header.merge!('Content-Disposition' => 'attachment') if req.path.end_with?('.yml')
super
end
Expand Down
3 changes: 1 addition & 2 deletions scripts/htmlproofer
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ proofer_options.merge!(
typhoeus: {
ssl_verifypeer: false,
ssl_verifyhost: 0,
followlocation: false,
followlocation: false
},
swap_urls: {
"http://localhost:#{site_config['port']}" => 'https://developers.login.gov'
Expand All @@ -39,7 +39,6 @@ proofer.before_request do |request|
# Some URLs behave differently if `accept-language` header is not included. Remove this in the
# future if it's no longer needed.
request.options[:headers]['Accept-Language'] = '*'

end

proofer.run
4 changes: 2 additions & 2 deletions spec/page.md_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def redirect_page?(path)

RSpec.describe 'all pages' do
files = Dir.glob('_site/**/*.html')
files.reject! {|path| redirect_page?(path) }
files.reject! { |path| redirect_page?(path) }
files.each do |page|
describe page do
let(:doc) { Nokogiri::HTML(File.new(page.to_s)) }
Expand All @@ -24,7 +24,7 @@ def redirect_page?(path)
expect(doc.to_s).to include('https://www.googletagmanager.com/gtag/js')
end

it 'does not include markdown markup in description meta tags', aggregate_failures: true do
it 'does not include markdown markup in description meta tags', :aggregate_failures do
description = doc.at_css('meta[name=description]')
expect(description[:content]).to_not(include('](')) if description

Expand Down
4 changes: 2 additions & 2 deletions spec/risc.json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:json) { JSON.parse(File.read('_site/data/risc.json')) }

it 'is is an array of supported_events' do
expect(json).to be
expect(json).to be_any
expect(json['supported_events']).to be_a(Array)
end
end
end
5 changes: 1 addition & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require 'rspec'
require 'pathname'
require 'nokogiri'
require 'set'
require 'uri'

Dir['spec/support/**.rb'].each { |f| require File.expand_path(f) }

RSpec.configure do |config|
config.disable_monkey_patching!
end
RSpec.configure(&:disable_monkey_patching!)
6 changes: 2 additions & 4 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
doc = actual

doc.css('a[href^=http]').each do |a|
next if !a.ancestors('nav').empty?
next unless a.ancestors('nav').empty?

missing_target_blank << a[:href] if a[:target] != '_blank'
end
Expand Down Expand Up @@ -59,9 +59,7 @@
ids = Set.new

doc.css('[id]').each do |tag|
if ids.include?(tag[:id])
duplicate_ids << tag[:id]
end
duplicate_ids << tag[:id] if ids.include?(tag[:id])

ids << tag[:id]
end
Expand Down
Loading