Skip to content

Commit

Permalink
bump rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
benbalter committed Nov 13, 2020
1 parent b48e801 commit 1f4c03a
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 67 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-performance
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
Exclude:
Expand Down
84 changes: 84 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-11-13 00:12:15 UTC using RuboCop version 1.3.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: MinSize.
Performance/CollectionLiteralInLoop:
Exclude:
- 'spec/gman/domains_spec.rb'

# Offense count: 40
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/gman/bin_spec.rb'
- 'spec/gman/domain_list_spec.rb'
- 'spec/gman/identifier_spec.rb'
- 'spec/gman/importer_spec.rb'
- 'spec/gman/locality_spec.rb'
- 'spec/gman_spec.rb'

# Offense count: 4
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- 'spec/gman/bin_spec.rb'
- 'spec/gman/country_code_spec.rb'
- 'spec/gman/domains_spec.rb'
- 'spec/gman/identifier_spec.rb'

# Offense count: 3
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/gman/bin_spec.rb'
- 'spec/gman/country_code_spec.rb'
- 'spec/gman/domains_spec.rb'

# Offense count: 2
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/gman/importer_spec.rb'

# Offense count: 23
RSpec/MultipleExpectations:
Max: 3

# Offense count: 24
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 9

# Offense count: 81
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/gman/country_code_spec.rb'
- 'spec/gman/domain_list_spec.rb'
- 'spec/gman/identifier_spec.rb'
- 'spec/gman/importer_spec.rb'
- 'spec/gman_spec.rb'

# Offense count: 10
RSpec/NestedGroups:
Max: 5

# Offense count: 2
RSpec/ScatteredSetup:
Exclude:
- 'spec/gman/importer_spec.rb'

# Offense count: 4
Security/Open:
Exclude:
- 'script/reconcile-us'
- 'script/vendor-federal-de'
- 'script/vendor-municipal-de'
- 'script/vendor-us'
6 changes: 3 additions & 3 deletions bin/gman
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ gman = Gman.new(domain)
puts "Domain : #{gman.domain}"

if gman.domain.nil?
puts 'Status : ' + 'Invalid domain'.red
puts "Status : #{'Invalid domain'.red}"
exit 1
end

unless gman.valid?
puts 'Status : ' + 'Not a government domain'.red
puts "Status : #{'Not a government domain'.red}"
exit 1
end

puts 'Status : ' + 'Valid government domain'.green
puts "Status : #{'Valid government domain'.green}"

%w[type country state city agency].each do |key|
value = gman.send(key)
Expand Down
4 changes: 2 additions & 2 deletions bin/gman_filter
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
require './lib/gman'

# Auto-flush
STDOUT.sync = true
STDERR.sync = true
$stdout.sync = true
$stderr.sync = true

ARGF.each do |line|
puts line if Gman.valid?(line)
Expand Down
4 changes: 3 additions & 1 deletion gman.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Gem::Specification.new do |s|
s.add_development_dependency('parallel', '~> 1.6')
s.add_development_dependency('pry', '~> 0.10')
s.add_development_dependency('rspec', '~> 3.5')
s.add_development_dependency('rubocop', '~> 0.37')
s.add_development_dependency('rubocop', '~> 1.0')
s.add_development_dependency('rubocop-performance', '~> 1.5')
s.add_development_dependency('rubocop-rspec', '~> 2.0')
s.add_development_dependency('ruby-prof', '~> 0.15')
s.add_development_dependency('swot', '~> 1.0')
end
4 changes: 2 additions & 2 deletions lib/gman/country_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def country

@country ||= begin
IsoCountryCodes.find(alpha2) if alpha2
rescue IsoCountryCodes::UnknownCodeError
nil
rescue IsoCountryCodes::UnknownCodeError
nil
end
end
end
2 changes: 1 addition & 1 deletion lib/gman/domain_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def array_to_hash(lines)
domain_hash = {}
group = ''
lines.each do |line|
if line =~ COMMENT_REGEX
if COMMENT_REGEX.match?(line)
group = COMMENT_REGEX.match(line)[1]
else
safe_push(domain_hash, group, line.downcase)
Expand Down
4 changes: 2 additions & 2 deletions lib/gman/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def initialize(domains)
end

def logger
@logger ||= Logger.new(STDOUT)
@logger ||= Logger.new($stdout)
end

def normalize_domain(domain)
Expand Down Expand Up @@ -122,7 +122,7 @@ def domain_resolves?(domain)

def ensure_regex(domain)
REGEX_CHECKS.each do |msg, regex|
return reject(domain, msg) if domain =~ regex
return reject(domain, msg) if domain&.match?(regex)
end
true
end
Expand Down
2 changes: 1 addition & 1 deletion script/profile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ end

result = RubyProf.stop
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
printer.print($stdout)
2 changes: 1 addition & 1 deletion script/reconcile-us
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data = data.split(/\r?\n/).reject(&:empty?)
domains = {}
group = ''
data.each do |row|
if row =~ /^\w/
if /^\w/.match?(row)
group = row
domains[group] = []
else
Expand Down
6 changes: 3 additions & 3 deletions script/vendor-public-suffix
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ PublicSuffix::List.default.each do |rule|
domain = nil

if rule.parts.length == 1
domain = rule.parts.first if ".#{rule.value}" =~ REGEX
elsif ".#{rule.value}" =~ REGEX
domain = rule.parts.first if REGEX.match?(".#{rule.value}")
elsif REGEX.match?(".#{rule.value}")
domain = rule.parts.pop(2).join('.')
end

domains.push domain unless domain.nil? || domains.include?(domain)
end

# Note: We want to skip resolution here, because a domain like `gov.sv` may be
# NOTE: We want to skip resolution here, because a domain like `gov.sv` may be
# a valid TLD, not have any top-level sites, and we'd still want it listed
Gman::Importer.new('non-us gov' => domains).import(skip_resolve: true)
2 changes: 1 addition & 1 deletion script/vendor-se
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ response = agent.submit(form, submit_button)

rows = CSV.parse(response.content, headers: true, col_sep: "\t")
domains = rows.map do |row|
row['Webbadress'] unless row['Namn'] =~ /UNIVERSITET/
row['Webbadress'] unless /UNIVERSITET/.match?(row['Namn'])
end

Gman::Importer.new('Swedish Administrative Authorities' => domains).import
2 changes: 1 addition & 1 deletion script/vendor-us
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data = data.split(/\r?\n/).reject(&:empty?)
domains = {}
group = ''
data.each do |row|
if row =~ /^\w/
if /^\w/.match?(row)
group = row
domains[group] = []
else
Expand Down
8 changes: 4 additions & 4 deletions spec/gman/bin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

it "knows it's valid" do
expect(output).to match('Valid government domain')
expect(exit_code).to eql(0)
expect(exit_code).to be(0)
end

it 'knows the type' do
Expand Down Expand Up @@ -50,7 +50,7 @@
let(:args) { [domain, '--no-color'] }

it "doesn't color" do
expect(output).to_not match(/\e\[32m/)
expect(output).not_to match(/\e\[32m/)
end
end
end
Expand All @@ -68,7 +68,7 @@

it 'knows the domain is invalid' do
expect(output).to match('Invalid domain')
expect(exit_code).to eql(1)
expect(exit_code).to be(1)
end
end

Expand All @@ -77,7 +77,7 @@

it "knows it's not a government domain" do
expect(output).to match('Not a government domain')
expect(exit_code).to eql(1)
expect(exit_code).to be(1)
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/gman/country_code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}.each do |domain, expected_country|
context "given #{domain.inspect}" do
subject { Gman.new(domain) }

let(:country) { subject.country }

it 'knows the country' do
Expand Down
8 changes: 4 additions & 4 deletions spec/gman/domain_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

it 'stores the init var' do
expect(subject.send(type)).to_not be_nil
expect(subject.send(type)).not_to be_nil
end

it 'returns the domain data' do
Expand All @@ -41,11 +41,11 @@
end

it 'knows if a domain is valid' do
expect(subject.valid?('whitehouse.gov')).to eql(true)
expect(subject.valid?('whitehouse.gov')).to be(true)
end

it 'knows if a domain is invalid' do
expect(subject.valid?('example.com')).to eql(false)
expect(subject.valid?('example.com')).to be(false)
end

it 'returns the domain groups' do
Expand All @@ -63,7 +63,7 @@

it 'alphabetizes the list' do
canada.shuffle!
expect(canada.first).to_not eql('100milehouse.com')
expect(canada.first).not_to eql('100milehouse.com')
subject.alphabetize
expect(canada.first).to eql('100milehouse.com')
end
Expand Down
Loading

0 comments on commit 1f4c03a

Please sign in to comment.