Skip to content

Commit

Permalink
Upgrade Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Jul 24, 2022
1 parent 3696c1c commit c36b40c
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 62 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ AllCops:
# Other
- 'test/benchmarks/**/*'
- 'test/profilers/**/*'
TargetRubyVersion: 2.6

# I often use @_variable to avoid clashing.
Naming/MemoizedInstanceVariableName:
Expand Down
28 changes: 0 additions & 28 deletions .rubocop_opinionated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ Layout/LineLength:
- 'test/**/*_test.rb'
Max: 100

Lint/ConstantDefinitionInBlock:
Exclude:
- 'Rakefile'
- 'spec/**/*'
- 'test/**/*'

# [codesmell]
Metrics/AbcSize:
Enabled: false
Expand Down Expand Up @@ -101,12 +95,6 @@ Layout/EmptyLinesAroundModuleBody:
Layout/EmptyLineBetweenDefs:
Enabled: false

# I personally don't care about the format style.
# In most cases I like to use %, but not at the point I want to enforce it
# as a convention in the entire code.
Style/FormatString:
Enabled: false

# Annotated tokens (like %<foo>s) are a good thing, but in most cases we don't need them.
# %s is a simpler and straightforward version that works in almost all cases. So don't complain.
Style/FormatStringToken:
Expand All @@ -116,11 +104,6 @@ Style/FormatStringToken:
Style/NegatedIf:
Enabled: false

# For years, %w() has been the de-facto standard. A lot of libraries are using ().
# Switching to [] would be a nightmare.
Style/PercentLiteralDelimiters:
Enabled: false

# There are cases were the inline rescue is ok. We can either downgrade the severity,
# or rely on the developer judgement on a case-by-case basis.
Style/RescueModifier:
Expand All @@ -129,17 +112,6 @@ Style/RescueModifier:
Style/SymbolArray:
EnforcedStyle: brackets

# Sorry, but using trailing spaces helps readability.
#
# %w( foo bar )
#
# looks better to me than
#
# %w( foo bar )
#
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false

# Hate It or Love It, I prefer double quotes as this is more consistent
# with several other programming languages and the output of puts and inspect.
Style/StringLiterals:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
This project uses [Semantic Versioning 2.0.0](https://semver.org/).


## main

### Changed

- Minimum Ruby version is 2.6


## 4.0.7

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ gem "memory_profiler", require: false
gem "minitest"
gem "minitest-reporters"
gem "mocha"
gem "rubocop", "~>0.90", require: false
gem "rubocop", require: false
gem "yard"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## Requirements

<tt>PublicSuffix</tt> requires **Ruby >= 2.3**. For an older versions of Ruby use a previous release.
<tt>PublicSuffix</tt> requires **Ruby >= 2.6**. For an older versions of Ruby use a previous release.


## Installation
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ task default: [:test, :rubocop]
require "rake/testtask"

Rake::TestTask.new do |t|
t.libs = %w( lib test )
t.libs = %w[lib test]
t.pattern = "test/**/*_test.rb"
t.verbose = !ENV["VERBOSE"].nil?
t.warning = !ENV["WARNING"].nil?
Expand Down Expand Up @@ -42,10 +42,10 @@ desc "Downloads the Public Suffix List file from the repository and stores it lo
task :"update-list" do
require "net/http"

DEFINITION_URL = "https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat"
definition_url = "https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat"

File.open("data/list.txt", "w+") do |f|
response = Net::HTTP.get_response(URI.parse(DEFINITION_URL))
response = Net::HTTP.get_response(URI.parse(definition_url))
response.body
f.write(response.body)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/public_suffix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def self.normalize(name)

return DomainInvalid.new("Name is blank") if name.empty?
return DomainInvalid.new("Name starts with a dot") if name.start_with?(DOT)
return DomainInvalid.new("%s is not expected to contain a scheme" % name) if name.include?("://")
return DomainInvalid.new(format("%s is not expected to contain a scheme", name)) if name.include?("://")

name
end
Expand Down
6 changes: 3 additions & 3 deletions lib/public_suffix/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Wildcard < Base
# @param content [String] the content of the rule
# @param private [Boolean]
def self.build(content, private: false)
new(value: content.to_s[2..-1], private: private)
new(value: content.to_s[2..], private: private)
end

# Initializes a new rule.
Expand Down Expand Up @@ -269,7 +269,7 @@ class Exception < Base
# @param content [#to_s] the content of the rule
# @param private [Boolean]
def self.build(content, private: false)
new(value: content.to_s[1..-1], private: private)
new(value: content.to_s[1..], private: private)
end

# Gets the original rule definition.
Expand Down Expand Up @@ -299,7 +299,7 @@ def decompose(domain)
#
# @return [Array<String>]
def parts
@value.split(DOT)[1..-1]
@value.split(DOT)[1..]
end

end
Expand Down
2 changes: 1 addition & 1 deletion public_suffix.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
"source_code_uri" => "https://github.com/weppos/publicsuffix-ruby/tree/v#{s.version}",
}

s.required_ruby_version = ">= 2.3"
s.required_ruby_version = ">= 2.6"

s.require_paths = ["lib"]
s.files = `git ls-files`.split("\n")
Expand Down
8 changes: 4 additions & 4 deletions test/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ def test_invalid
def test_rejected
REJECTED_CASES.each do |name, expected|
assert_equal expected, PublicSuffix.valid?(name),
"Expected %s to be %s" % [name.inspect, expected.inspect]
format("Expected %s to be %s", name.inspect, expected.inspect)
assert !valid_domain?(name),
"#{name} expected to be invalid"
end
end


CASE_CASES = [
["Www.google.com", %w( www google com )],
["www.Google.com", %w( www google com )],
["www.google.Com", %w( www google com )],
["Www.google.com", %w[www google com]],
["www.Google.com", %w[www google com]],
["www.google.Com", %w[www google com]],
].freeze

def test_ignore_case
Expand Down
2 changes: 1 addition & 1 deletion test/psl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_valid
end

message = "The following #{failures.size} tests fail:\n"
failures.each { |i, o, d| message += "Expected %s to be %s, got %s\n" % [i.inspect, o.inspect, d.inspect] }
failures.each { |i, o, d| message += format("Expected %s to be %s, got %s\n", i.inspect, o.inspect, d.inspect) }
assert_equal 0, failures.size, message
end

Expand Down
6 changes: 3 additions & 3 deletions test/unit/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def setup

# Tokenizes given input into labels.
def test_self_name_to_labels
assert_equal %w( someone spaces live com ),
assert_equal %w[someone spaces live com],
PublicSuffix::Domain.name_to_labels("someone.spaces.live.com")
assert_equal %w( leontina23samiko wiki zoho com ),
assert_equal %w[leontina23samiko wiki zoho com],
PublicSuffix::Domain.name_to_labels("leontina23samiko.wiki.zoho.com")
end

# Converts input into String.
def test_self_name_to_labels_converts_input_to_string
assert_equal %w( someone spaces live com ),
assert_equal %w[someone spaces live com],
PublicSuffix::Domain.name_to_labels(:"someone.spaces.live.com")
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_self_parse
assert_instance_of PublicSuffix::List, list
assert_equal 4, list.size

rules = %w( com *.uk !british-library.uk blogspot.com ).map { |name| PublicSuffix::Rule.factory(name) }
rules = %w[com *.uk !british-library.uk blogspot.com].map { |name| PublicSuffix::Rule.factory(name) }
assert_equal rules, list.each.to_a

# private domains
Expand Down
30 changes: 15 additions & 15 deletions test/unit/rule_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_factory_should_return_rule_wildcard
def test_default_returns_default_wildcard
default = PublicSuffix::Rule.default
assert_equal PublicSuffix::Rule::Wildcard.build("*"), default
assert_equal %w( example tldnotlisted ), default.decompose("example.tldnotlisted")
assert_equal %w( www.example tldnotlisted ), default.decompose("www.example.tldnotlisted")
assert_equal %w[example tldnotlisted], default.decompose("example.tldnotlisted")
assert_equal %w[www.example tldnotlisted], default.decompose("www.example.tldnotlisted")
end

end
Expand Down Expand Up @@ -140,15 +140,15 @@ def test_length
end

def test_parts
assert_equal %w(com), @klass.build("com").parts
assert_equal %w(co com), @klass.build("co.com").parts
assert_equal %w(mx co com), @klass.build("mx.co.com").parts
assert_equal %w[com], @klass.build("com").parts
assert_equal %w[co com], @klass.build("co.com").parts
assert_equal %w[mx co com], @klass.build("mx.co.com").parts
end

def test_decompose
assert_equal [nil, nil], @klass.build("com").decompose("com")
assert_equal %w( example com ), @klass.build("com").decompose("example.com")
assert_equal %w( foo.example com ), @klass.build("com").decompose("foo.example.com")
assert_equal %w[example com], @klass.build("com").decompose("example.com")
assert_equal %w[foo.example com], @klass.build("com").decompose("foo.example.com")
end

end
Expand All @@ -175,14 +175,14 @@ def test_length
end

def test_parts
assert_equal %w( uk ), @klass.build("!british-library.uk").parts
assert_equal %w( tokyo jp ), @klass.build("!metro.tokyo.jp").parts
assert_equal %w[uk], @klass.build("!british-library.uk").parts
assert_equal %w[tokyo jp], @klass.build("!metro.tokyo.jp").parts
end

def test_decompose
assert_equal [nil, nil], @klass.build("!british-library.uk").decompose("uk")
assert_equal %w( british-library uk ), @klass.build("!british-library.uk").decompose("british-library.uk")
assert_equal %w( foo.british-library uk ), @klass.build("!british-library.uk").decompose("foo.british-library.uk")
assert_equal %w[british-library uk], @klass.build("!british-library.uk").decompose("british-library.uk")
assert_equal %w[foo.british-library uk], @klass.build("!british-library.uk").decompose("foo.british-library.uk")
end

end
Expand All @@ -209,14 +209,14 @@ def test_length
end

def test_parts
assert_equal %w( uk ), @klass.build("*.uk").parts
assert_equal %w( co uk ), @klass.build("*.co.uk").parts
assert_equal %w[uk], @klass.build("*.uk").parts
assert_equal %w[co uk], @klass.build("*.co.uk").parts
end

def test_decompose
assert_equal [nil, nil], @klass.build("*.do").decompose("nic.do")
assert_equal %w( google co.uk ), @klass.build("*.uk").decompose("google.co.uk")
assert_equal %w( foo.google co.uk ), @klass.build("*.uk").decompose("foo.google.co.uk")
assert_equal %w[google co.uk], @klass.build("*.uk").decompose("google.co.uk")
assert_equal %w[foo.google co.uk], @klass.build("*.uk").decompose("foo.google.co.uk")
end

end

0 comments on commit c36b40c

Please sign in to comment.