Skip to content

Commit

Permalink
Sync up my Rubocop default file
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Jan 31, 2020
1 parent c65e0e4 commit c14c3ed
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
inherit_from:
- .rubocop_defaults.yml
- .rubocop_opinionated.yml

AllCops:
Exclude:
Expand Down
29 changes: 3 additions & 26 deletions .rubocop_defaults.yml → .rubocop_opinionated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ Layout/LineLength:
- 'test/**/*_test.rb'
Max: 100

# Array indentation should be considered like MultilineMethodCallIndentation indentation
# and use 4 spaces instead of 2.
Layout/FirstArrayElementIndentation:
IndentationWidth: 4

# Hash indentation should be considered like MultilineMethodCallIndentation indentation
# and use 4 spaces instead of 2.
Layout/FirstHashElementIndentation:
IndentationWidth: 4

# Multi-line differs from standard indentation, they are indented twice.
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
IndentationWidth: 4

# [codesmell]
Metrics/AbcSize:
Enabled: false
Expand Down Expand Up @@ -120,17 +105,6 @@ Style/FormatString:
Style/FormatStringToken:
Enabled: false

# Prefer the latest Hash syntax
Style/HashSyntax:
Exclude:
# But Rakefiles generally have some definition like
# :default => :test
# that looks nicer with the old rocket syntax.
- 'Rakefile'

Style/RescueStandardError:
Enabled: false

# unless is not always cool.
Style/NegatedIf:
Enabled: false
Expand All @@ -145,6 +119,9 @@ Style/PercentLiteralDelimiters:
Style/RescueModifier:
Enabled: false

Style/SymbolArray:
EnforcedStyle: brackets

# Sorry, but using trailing spaces helps readability.
#
# %w( foo bar )
Expand Down
58 changes: 29 additions & 29 deletions test/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
class AcceptanceTest < Minitest::Test

VALID_CASES = [
["example.com", "example.com", [nil, "example", "com"]],
["foo.example.com", "example.com", ["foo", "example", "com"]],
["example.com", "example.com", [nil, "example", "com"]],
["foo.example.com", "example.com", ["foo", "example", "com"]],

["verybritish.co.uk", "verybritish.co.uk", [nil, "verybritish", "co.uk"]],
["foo.verybritish.co.uk", "verybritish.co.uk", ["foo", "verybritish", "co.uk"]],
["verybritish.co.uk", "verybritish.co.uk", [nil, "verybritish", "co.uk"]],
["foo.verybritish.co.uk", "verybritish.co.uk", ["foo", "verybritish", "co.uk"]],

["parliament.uk", "parliament.uk", [nil, "parliament", "uk"]],
["foo.parliament.uk", "parliament.uk", ["foo", "parliament", "uk"]],
["parliament.uk", "parliament.uk", [nil, "parliament", "uk"]],
["foo.parliament.uk", "parliament.uk", ["foo", "parliament", "uk"]],
].freeze

def test_valid
Expand All @@ -34,10 +34,10 @@ def test_valid


INVALID_CASES = [
["nic.bd", PublicSuffix::DomainNotAllowed],
[nil, PublicSuffix::DomainInvalid],
["", PublicSuffix::DomainInvalid],
[" ", PublicSuffix::DomainInvalid],
["nic.bd", PublicSuffix::DomainNotAllowed],
[nil, PublicSuffix::DomainInvalid],
["", PublicSuffix::DomainInvalid],
[" ", PublicSuffix::DomainInvalid],
].freeze

def test_invalid
Expand All @@ -49,16 +49,16 @@ def test_invalid


REJECTED_CASES = [
["www. .com", true],
["foo.co..uk", true],
["goo,gle.com", true],
["-google.com", true],
["google-.com", true],

# This case was covered in GH-15.
# I decided to cover this case because it's not easily reproducible with URI.parse
# and can lead to several false positives.
["http://google.com", false],
["www. .com", true],
["foo.co..uk", true],
["goo,gle.com", true],
["-google.com", true],
["google-.com", true],

# This case was covered in GH-15.
# I decided to cover this case because it's not easily reproducible with URI.parse
# and can lead to several false positives.
["http://google.com", false],
].freeze

def test_rejected
Expand All @@ -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
Expand All @@ -90,10 +90,10 @@ def test_ignore_case


INCLUDE_PRIVATE_CASES = [
["blogspot.com", true, "blogspot.com"],
["blogspot.com", false, nil],
["subdomain.blogspot.com", true, "blogspot.com"],
["subdomain.blogspot.com", false, "subdomain.blogspot.com"],
["blogspot.com", true, "blogspot.com"],
["blogspot.com", false, nil],
["subdomain.blogspot.com", true, "blogspot.com"],
["subdomain.blogspot.com", false, "subdomain.blogspot.com"],
].freeze

def test_ignore_private
Expand All @@ -115,14 +115,14 @@ def test_ignore_private
def valid_uri?(name)
uri = URI.parse(name)
!uri.host.nil?
rescue
rescue StandardError
false
end

def valid_domain?(name)
uri = URI.parse(name)
!uri.host.nil? && uri.scheme.nil?
rescue
rescue StandardError
false
end

Expand Down
22 changes: 11 additions & 11 deletions test/unit/public_suffix_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,23 @@ def test_self_domain_with_blank_sld

def test_self_normalize
[
["com", "com"],
["example.com", "example.com"],
["www.example.com", "www.example.com"],
["com", "com"],
["example.com", "example.com"],
["www.example.com", "www.example.com"],

["example.com.", "example.com"], # strip FQDN
[" example.com ", "example.com"], # strip spaces
["Example.COM", "example.com"], # downcase
["example.com.", "example.com"], # strip FQDN
[" example.com ", "example.com"], # strip spaces
["Example.COM", "example.com"], # downcase
].each do |input, output|
assert_equal output, PublicSuffix.normalize(input)
end
end

def test_normalize_blank
[
nil,
"",
" ",
nil,
"",
" ",
].each do |input|
error = PublicSuffix.normalize(input)
assert_instance_of PublicSuffix::DomainInvalid, error
Expand All @@ -167,7 +167,7 @@ def test_normalize_blank

def test_normalize_scheme
[
"https://google.com",
"https://google.com",
].each do |input|
error = PublicSuffix.normalize(input)
assert_instance_of PublicSuffix::DomainInvalid, error
Expand All @@ -177,7 +177,7 @@ def test_normalize_scheme

def test_normalize_leading_dot
[
".google.com",
".google.com",
].each do |input|
error = PublicSuffix.normalize(input)
assert_instance_of PublicSuffix::DomainInvalid, error
Expand Down
60 changes: 30 additions & 30 deletions test/unit/rule_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,36 @@ def test_equality_with_internals

def test_match
[
# standard match
[PublicSuffix::Rule.factory("uk"), "uk", true],
[PublicSuffix::Rule.factory("uk"), "example.uk", true],
[PublicSuffix::Rule.factory("uk"), "example.co.uk", true],
[PublicSuffix::Rule.factory("co.uk"), "example.co.uk", true],

# FIXME
# [PublicSuffix::Rule.factory("*.com"), "com", false],
[PublicSuffix::Rule.factory("*.com"), "example.com", true],
[PublicSuffix::Rule.factory("*.com"), "foo.example.com", true],
[PublicSuffix::Rule.factory("!example.com"), "com", false],
[PublicSuffix::Rule.factory("!example.com"), "example.com", true],
[PublicSuffix::Rule.factory("!example.com"), "foo.example.com", true],

# TLD mismatch
[PublicSuffix::Rule.factory("gk"), "example.uk", false],
[PublicSuffix::Rule.factory("gk"), "example.co.uk", false],
[PublicSuffix::Rule.factory("co.uk"), "uk", false],

# general mismatch
[PublicSuffix::Rule.factory("uk.co"), "example.co.uk", false],
[PublicSuffix::Rule.factory("go.uk"), "example.co.uk", false],
[PublicSuffix::Rule.factory("co.uk"), "uk", false],

# partial matches/mismatches
[PublicSuffix::Rule.factory("co"), "example.co.uk", false],
[PublicSuffix::Rule.factory("example"), "example.uk", false],
[PublicSuffix::Rule.factory("le.it"), "example.it", false],
[PublicSuffix::Rule.factory("le.it"), "le.it", true],
[PublicSuffix::Rule.factory("le.it"), "foo.le.it", true],
# standard match
[PublicSuffix::Rule.factory("uk"), "uk", true],
[PublicSuffix::Rule.factory("uk"), "example.uk", true],
[PublicSuffix::Rule.factory("uk"), "example.co.uk", true],
[PublicSuffix::Rule.factory("co.uk"), "example.co.uk", true],

# FIXME
# [PublicSuffix::Rule.factory("*.com"), "com", false],
[PublicSuffix::Rule.factory("*.com"), "example.com", true],
[PublicSuffix::Rule.factory("*.com"), "foo.example.com", true],
[PublicSuffix::Rule.factory("!example.com"), "com", false],
[PublicSuffix::Rule.factory("!example.com"), "example.com", true],
[PublicSuffix::Rule.factory("!example.com"), "foo.example.com", true],

# TLD mismatch
[PublicSuffix::Rule.factory("gk"), "example.uk", false],
[PublicSuffix::Rule.factory("gk"), "example.co.uk", false],
[PublicSuffix::Rule.factory("co.uk"), "uk", false],

# general mismatch
[PublicSuffix::Rule.factory("uk.co"), "example.co.uk", false],
[PublicSuffix::Rule.factory("go.uk"), "example.co.uk", false],
[PublicSuffix::Rule.factory("co.uk"), "uk", false],

# partial matches/mismatches
[PublicSuffix::Rule.factory("co"), "example.co.uk", false],
[PublicSuffix::Rule.factory("example"), "example.uk", false],
[PublicSuffix::Rule.factory("le.it"), "example.it", false],
[PublicSuffix::Rule.factory("le.it"), "le.it", true],
[PublicSuffix::Rule.factory("le.it"), "foo.le.it", true],

].each do |rule, input, expected|
assert_equal expected, rule.match?(input)
Expand Down

0 comments on commit c14c3ed

Please sign in to comment.