diff --git a/.rubocop.yml b/.rubocop.yml index af922f52..f9117f32 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,7 @@ AllCops: # Other - 'test/benchmarks/**/*' - 'test/profilers/**/*' + TargetRubyVersion: 2.6 # I often use @_variable to avoid clashing. Naming/MemoizedInstanceVariableName: diff --git a/.rubocop_opinionated.yml b/.rubocop_opinionated.yml index 761e2c7d..a9bc89bc 100644 --- a/.rubocop_opinionated.yml +++ b/.rubocop_opinionated.yml @@ -15,12 +15,6 @@ Layout/LineLength: - 'test/**/*_test.rb' Max: 100 -Lint/ConstantDefinitionInBlock: - Exclude: - - 'Rakefile' - - 'spec/**/*' - - 'test/**/*' - # [codesmell] Metrics/AbcSize: Enabled: false @@ -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 %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: @@ -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: @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index b6178f56..8b1729f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Gemfile b/Gemfile index 8c679696..b41c6f2e 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/README.md b/README.md index 0747354f..4cf31e3a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Requirements -PublicSuffix requires **Ruby >= 2.3**. For an older versions of Ruby use a previous release. +PublicSuffix requires **Ruby >= 2.6**. For an older versions of Ruby use a previous release. ## Installation diff --git a/Rakefile b/Rakefile index 26a6c994..59b3b3b7 100644 --- a/Rakefile +++ b/Rakefile @@ -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? @@ -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 diff --git a/lib/public_suffix.rb b/lib/public_suffix.rb index c0f3fab6..a4ed1403 100644 --- a/lib/public_suffix.rb +++ b/lib/public_suffix.rb @@ -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 diff --git a/lib/public_suffix/rule.rb b/lib/public_suffix/rule.rb index d41a4807..c89304e6 100644 --- a/lib/public_suffix/rule.rb +++ b/lib/public_suffix/rule.rb @@ -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. @@ -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. @@ -299,7 +299,7 @@ def decompose(domain) # # @return [Array] def parts - @value.split(DOT)[1..-1] + @value.split(DOT)[1..] end end diff --git a/public_suffix.gemspec b/public_suffix.gemspec index ae552fc9..cbf035c1 100644 --- a/public_suffix.gemspec +++ b/public_suffix.gemspec @@ -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") diff --git a/test/acceptance_test.rb b/test/acceptance_test.rb index 371bfe13..6e114f45 100644 --- a/test/acceptance_test.rb +++ b/test/acceptance_test.rb @@ -64,7 +64,7 @@ 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 @@ -72,9 +72,9 @@ def test_rejected 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 diff --git a/test/psl_test.rb b/test/psl_test.rb index fae398f7..919029b4 100644 --- a/test/psl_test.rb +++ b/test/psl_test.rb @@ -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 diff --git a/test/unit/domain_test.rb b/test/unit/domain_test.rb index 968462d9..f3ae4bed 100644 --- a/test/unit/domain_test.rb +++ b/test/unit/domain_test.rb @@ -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 diff --git a/test/unit/list_test.rb b/test/unit/list_test.rb index 98529352..3b0160e5 100644 --- a/test/unit/list_test.rb +++ b/test/unit/list_test.rb @@ -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 diff --git a/test/unit/rule_test.rb b/test/unit/rule_test.rb index d1cc6094..81d4522e 100644 --- a/test/unit/rule_test.rb +++ b/test/unit/rule_test.rb @@ -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 @@ -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 @@ -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 @@ -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