Skip to content
Open
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
58 changes: 15 additions & 43 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
require:
inherit_from:
- .rubocop_todo.yml

inherit_mode:
merge:
- Exclude

plugins:
- rubocop-performance
- rubocop-rspec
- rubocop-rake

AllCops:
NewCops: enable
TargetRubyVersion: 3.2
Exclude:
- 'bin/**/*'
- 'tmp/**/*'

Bundler/OrderedGems:
Enabled: false

Expand Down Expand Up @@ -54,28 +68,12 @@ Style/TrailingCommaInHashLiteral:
Style/FormatStringToken:
Enabled: false

Metrics/BlockLength:
Max: 30
Exclude:
- 'spec/**/*.rb'
- 'config/environments/**/*.rb'
- 'config/routes.rb'
- "config/initializers/simple_form_bootstrap.rb"
- 'db/**/*'

Metrics/AbcSize:
Max: 20
Exclude:
- 'db/**/*'

Metrics/MethodLength:
Max: 20
CountAsOne:
- array
- hash
- heredoc
Exclude:
- 'db/migrate/*'

Metrics/ModuleLength:
CountAsOne:
Expand All @@ -88,28 +86,13 @@ Metrics/ClassLength:
- array
- hash
- heredoc
Exclude:
- 'db/**/*'

Metrics/ParameterLists:
Max: 7
MaxOptionalParameters: 5
Exclude:
- "spec/components/**/*.rb"
- "app/components/**/*.rb"

Naming/InclusiveLanguage:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/DescribeClass:
Exclude:
- 'spec/routing/**/*'
- 'spec/system/**/*'
- 'spec/views/**/*'

RSpec/DescribedClass:
SkipBlocks: true

Expand All @@ -119,10 +102,6 @@ RSpec/EmptyExampleGroup:
RSpec/ExampleLength:
Enabled: false

RSpec/InstanceVariable:
Exclude:
- 'spec/views/**/*'

RSpec/NestedGroups:
Max: 6

Expand All @@ -143,10 +122,3 @@ RSpec/AnyInstance:

RSpec/VerifiedDoubles:
Enabled: false

AllCops:
NewCops: enable
TargetRubyVersion: 3.2
Exclude:
- 'bin/**/*'
- 'tmp/**/*'
157 changes: 157 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-12-15 16:17:55 UTC using RuboCop version 1.81.7.
# 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: 8
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Exclude:
- 'lib/phony/countries/brazil.rb'
- 'lib/phony/countries/cambodia.rb'
- 'lib/phony/countries/ireland.rb'
- 'lib/phony/countries/italy.rb'
- 'lib/phony/countries/somalia.rb'
- 'lib/phony/countries/united_kingdom.rb'
- 'phony.gemspec'

# Offense count: 1
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Exclude:
- 'lib/phony/national_splitters/fixed.rb'

# Offense count: 5
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 27

# Offense count: 9
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 758

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 126

# Offense count: 9
# Configuration parameters: LengthThreshold.
Metrics/CollectionLiteralLength:
Exclude:
- 'lib/phony/countries/argentina.rb'
- 'lib/phony/countries/germany.rb'
- 'lib/phony/countries/india.rb'
- 'lib/phony/countries/japan.rb'
- 'lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb'
- 'lib/phony/countries/ukraine.rb'
- 'lib/phony/countries/united_kingdom.rb'
- 'spec/functional/plausibility_spec.rb'

# Offense count: 6
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 13

# Offense count: 2
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Exclude:
- 'lib/phony/country.rb'
- 'spec/functional/plausibility_spec.rb'

# Offense count: 1
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Metrics/ParameterLists:
Max: 7

# Offense count: 5
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 13

# Offense count: 2
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros, UseSorbetSigs.
# NamePrefix: is_, has_, have_, does_
# ForbiddenPrefixes: is_, has_, have_, does_
# AllowedMethods: is_a?
# MethodDefinitionMacros: define_method, define_singleton_method
Naming/PredicatePrefix:
Exclude:
- 'lib/phony/config.rb'

# Offense count: 8
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'Gemfile'
- 'lib/phony/countries/brazil.rb'
- 'lib/phony/countries/sweden.rb'

# Offense count: 1
RSpec/BeforeAfterAll:
Exclude:
- 'spec/functional/config_spec.rb'

# Offense count: 2
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- 'spec/functional/plausibility_spec.rb'
- 'spec/lib/phony/countries_spec.rb'

# Offense count: 1
RSpec/IdenticalEqualityAssertion:
Exclude:
- 'spec/lib/phony/national_splitters/fixed_spec.rb'

# Offense count: 1
RSpec/MultipleDescribes:
Exclude:
- 'spec/lib/phony_spec.rb'

# Offense count: 1
RSpec/PendingWithoutReason:
Exclude:
- 'spec/lib/phony/country_spec.rb'

# Offense count: 1
RSpec/RemoveConst:
Exclude:
- 'spec/functional/config_spec.rb'

# Offense count: 4
RSpec/RepeatedExample:
Exclude:
- 'spec/lib/phony/country_codes_spec.rb'

# Offense count: 4
RSpec/RepeatedExampleGroupDescription:
Exclude:
- 'spec/lib/phony/countries_spec.rb'
- 'spec/lib/phony/national_splitters/fixed_spec.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowOnConstant, AllowOnSelfClass.
Style/CaseEquality:
Exclude:
- 'lib/phony/country.rb'
- 'lib/phony/country_codes.rb'
- 'lib/phony/local_splitters/fixed.rb'

# Offense count: 11
Style/ClassVars:
Exclude:
- 'lib/phony/country.rb'
- 'lib/phony/country_codes.rb'
- 'lib/phony/vanity.rb'
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'http://rubygems.org'

gem 'rake', require: false
Expand Down
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ GEM
diff-lcs (1.6.2)
docile (1.4.1)
gem-release (2.2.4)
json (2.12.0)
json (2.16.0)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
parallel (1.27.0)
parser (3.3.8.0)
parser (3.3.10.0)
ast (~> 2.4.1)
racc
pippi (0.0.14)
prism (1.4.0)
prism (1.6.0)
qed (2.9.2)
ansi
brass
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.10.0)
regexp_parser (2.11.3)
rexml (3.4.4)
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand All @@ -40,18 +40,18 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.3)
rubocop (1.75.7)
rubocop (1.81.7)
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.44.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.44.1)
rubocop-ast (1.48.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-performance (1.25.0)
Expand Down Expand Up @@ -80,9 +80,9 @@ GEM
simplecov_json_formatter (0.1.4)
terminal-table (4.0.0)
unicode-display_width (>= 1.1.1, < 4)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)

PLATFORMS
arm64-darwin-23
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rspec'
require 'rspec/core/rake_task'

Expand Down
14 changes: 7 additions & 7 deletions lib/phony.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def initialize
#
class SplittingError < ArgumentError
def initialize(number)
super(%(Phony could not split the given number. Is #{(number.nil? || number == '') ? 'it' : number.inspect} a phone number?))
super(%(Phony could not split the given number. Is #{number.nil? || number == '' ? 'it' : number.inspect} a phone number?))
end
end

Expand Down Expand Up @@ -169,8 +169,8 @@ def normalize(phone_number, options = {})
#
def normalize!(phone_number, options = {})
@codes.normalize phone_number, options
rescue
raise NormalizationError.new
rescue StandardError
raise NormalizationError
end

# Splits the phone number into pieces according to the country codes.
Expand Down Expand Up @@ -209,9 +209,9 @@ def split(phone_number)
#
def split!(phone_number, error_number = nil)
@codes.split phone_number
rescue
rescue StandardError
# NB The error_number (reference) is used because phone_number is destructively handled.
raise SplittingError.new(error_number)
raise SplittingError, error_number
end

# Formats a normalized E164 number according to a country's formatting scheme.
Expand Down Expand Up @@ -265,8 +265,8 @@ def format(phone_number, options = {})
#
def format!(phone_number, options = {})
@codes.format phone_number, options
rescue
raise FormattingError.new
rescue StandardError
raise FormattingError
end
alias formatted format
alias formatted! format!
Expand Down
6 changes: 4 additions & 2 deletions lib/phony/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ def self.load *options
end

# Set defaults.
only, except = [only || [], except || []]
only ||= []
except ||= []
# Convert to expected format if possible.
only, except = [only.map(&:to_s), except.map(&:to_s)]
only = only.map(&:to_s)
except = except.map(&:to_s)

# Check params.
raise "Params given to Phony::Config.load must be Array-like. The one given was: #{only}" unless only.respond_to?(:to_ary)
Expand Down
Loading
Loading