From 989c97455e8100a49cb2bac14f9e4e972fd78145 Mon Sep 17 00:00:00 2001 From: Simone Carletti <5387+weppos@users.noreply.github.com> Date: Mon, 1 Dec 2025 19:34:44 +0100 Subject: [PATCH 1/2] Fix Rubocop offenses --- .rubocop.yml | 2 +- Gemfile | 2 ++ Gemfile.lock | 20 ++++++------- Rakefile | 2 ++ lib/phony.rb | 14 ++++----- lib/phony/config.rb | 6 ++-- lib/phony/countries.rb | 8 ++--- lib/phony/countries/bangladesh.rb | 30 +++++++++---------- lib/phony/countries/italy.rb | 4 --- lib/phony/countries/south_korea.rb | 2 +- lib/phony/country.rb | 10 +++---- lib/phony/country_codes.rb | 7 +++-- lib/phony/dsl.rb | 6 ++-- lib/phony/local_splitters/fixed.rb | 4 +-- lib/phony/local_splitters/regex.rb | 2 +- lib/phony/national_splitters/dsl.rb | 4 +-- lib/phony/national_splitters/regex.rb | 4 +-- lib/phony/national_splitters/variable.rb | 2 +- lib/phony/trunk_code.rb | 13 ++++---- misc/issue-snippets/270.rb | 4 ++- performance/perfer.rb | 2 ++ performance/rubinius.rb | 2 ++ performance/stackprof.rb | 12 ++++---- phony.gemspec | 2 ++ qed/applique/ae.rb | 2 ++ qed/applique/phony.rb | 10 ++++--- spec/functional/config_spec.rb | 2 ++ spec/functional/plausibility_spec.rb | 2 ++ spec/lib/phony/countries_spec.rb | 2 ++ spec/lib/phony/country_codes_spec.rb | 8 +++-- spec/lib/phony/country_spec.rb | 8 +++-- spec/lib/phony/dsl_spec.rb | 7 +++-- spec/lib/phony/local_splitters/fixed_spec.rb | 2 ++ spec/lib/phony/local_splitters/regex_spec.rb | 2 ++ spec/lib/phony/national_code_spec.rb | 8 +++-- .../phony/national_splitters/default_spec.rb | 2 ++ .../phony/national_splitters/fixed_spec.rb | 10 ++++--- .../lib/phony/national_splitters/none_spec.rb | 2 ++ .../phony/national_splitters/regex_spec.rb | 2 ++ .../phony/national_splitters/variable_spec.rb | 6 ++-- spec/lib/phony/trunk_code_spec.rb | 2 ++ spec/lib/phony/vanity_spec.rb | 2 ++ spec/lib/phony_spec.rb | 14 +++++---- spec/spec_helper.rb | 2 ++ spec/spec_helper_extensions.rb | 6 ++-- 45 files changed, 162 insertions(+), 103 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 04a0d196..80bb91ab 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,4 @@ -require: +plugins: - rubocop-performance - rubocop-rspec - rubocop-rake diff --git a/Gemfile b/Gemfile index eb3d2899..fe686e37 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'http://rubygems.org' gem 'rake', require: false diff --git a/Gemfile.lock b/Gemfile.lock index ec4f1aad..b6fbb285 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -40,7 +40,7 @@ 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) @@ -48,10 +48,10 @@ GEM 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) @@ -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 diff --git a/Rakefile b/Rakefile index 36af272a..2813167f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rspec' require 'rspec/core/rake_task' diff --git a/lib/phony.rb b/lib/phony.rb index 369c8b11..78794777 100644 --- a/lib/phony.rb +++ b/lib/phony.rb @@ -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 @@ -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. @@ -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. @@ -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! diff --git a/lib/phony/config.rb b/lib/phony/config.rb index 357c9af6..5f43aeb3 100644 --- a/lib/phony/config.rb +++ b/lib/phony/config.rb @@ -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) diff --git a/lib/phony/countries.rb b/lib/phony/countries.rb index 3619ef98..428f0064 100644 --- a/lib/phony/countries.rb +++ b/lib/phony/countries.rb @@ -101,7 +101,7 @@ match(/^(800|90\d)\d+$/) >> split(2, 3) | # Toll free service and premium numbers match(/^(46[056789])\d{6}$/) >> split(2, 2, 2) | # Mobile (Lycamobile, Telenet, Join Experience, Proximus 0460) match(/^(4[789]\d)\d{6}$/) >> split(2, 2, 2) | # Mobile - match(/^(45[156])\d{6}$/) >> split(2, 2, 2) | # Mobile Vikings, Digi and Voo + match(/^(45[156])\d{6}$/) >> split(2, 2, 2) | # Mobile Vikings, Digi and Voo one_of('2', '3', '4', '9') >> split(3, 2, 2) | # Short NDCs fixed(2) >> split(2, 2, 2) # 2-digit NDCs @@ -171,7 +171,7 @@ # Norway. # country '47', - none >> matched_split(/^[1].*$/ => [3], + none >> matched_split(/^1.*$/ => [3], /^[489].*$/ => [3, 2, 3], :fallback => [2, 2, 2, 2]) @@ -251,7 +251,7 @@ match(/^(13)\d+$/) >> split(2, 2) | # 13 local rate fixed(1) >> split(4, 4) # Rest - # country '62' # Indonesia (Republic of), see special file + # country '62' # Indonesia (Republic of), see special file # Philippines (Republic of the) # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PH @@ -902,7 +902,7 @@ country '593', match(/\A(1800)\d+\z/) >> split(3, 3) | # toll free 1800 numbers one_of('9') >> split(4, 4) | - match(/\A([\d]{2})\d{7}\z/) >> split(3, 4) | + match(/\A(\d{2})\d{7}\z/) >> split(3, 4) | fixed(1) >> split(3, 4) country '594', fixed(3) >> split(3, 3) # French Guiana (French Department of) http://www.wtng.info/wtng-594-fr.html diff --git a/lib/phony/countries/bangladesh.rb b/lib/phony/countries/bangladesh.rb index 608f490a..1fc45301 100644 --- a/lib/phony/countries/bangladesh.rb +++ b/lib/phony/countries/bangladesh.rb @@ -17,24 +17,24 @@ ] ndcs_with_5_subscriber_numbers = { - 2 => %w[51 71 81 91], - 3 => %w[321 331 341 351 361 371 381 441 448 421 451 461 471 481 491 468 - 488 498 521 531 541 551 561 571 581 591 628 601 631 641 651 661 668 - 691 731 741 751 761 771 781 791 831 841 851 861 871 921 931 941 951 981], - 4 => %w[3023 3024 3028 3223 3225 3324 3422 3425 3822 - 4033 4226 4227 4322 4323 4326 4327 4328 4422 4423 4424 4426 4455 4624 4625 4626 4655 4656 4657 4823 4854 4922 4924 4925 4953 - 5020 5023 5024 5028 5029 5224 5225 5227 5323 5325 5326 5329 5424 5426 5526 5653 5724 5826 - 6023 6024 6222 6224 6225 6253 6254 6255 6323 6324 6327 6328 6423 6424 6524 6527 6623 6624 6652 6653 6654 6655 - 6722 6723 6724 6725 6822 6823 6824 6825 6922 6923 6924 6925 6926 - 7225 7227 7228 7229 7324 7326 7327 7329 7425 7426 7522 7525 7526 7528 7529 7724 7823 7825 7923 - 8020 8022 8026 8029 8220 8222 8223 8224 8225 8226 8227 8229 8232 8325 8327 8328 8425 8426 8427 8522 8523 8524 - 8622 8623 8624 8625 8626 8723 8725 8727 - 9020 9022 9024 9025 9027 9028 9032 9033 9222 9223 9225 9226 9227 9228 9229 9232 9233 9424 9426 9428 9524 9525 9528 9529 9824 9827] + 2 => %w[51 71 81 91], + 3 => %w[321 331 341 351 361 371 381 441 448 421 451 461 471 481 491 468 + 488 498 521 531 541 551 561 571 581 591 628 601 631 641 651 661 668 + 691 731 741 751 761 771 781 791 831 841 851 861 871 921 931 941 951 981], + 4 => %w[3023 3024 3028 3223 3225 3324 3422 3425 3822 + 4033 4226 4227 4322 4323 4326 4327 4328 4422 4423 4424 4426 4455 4624 4625 4626 4655 4656 4657 4823 4854 4922 4924 4925 4953 + 5020 5023 5024 5028 5029 5224 5225 5227 5323 5325 5326 5329 5424 5426 5526 5653 5724 5826 + 6023 6024 6222 6224 6225 6253 6254 6255 6323 6324 6327 6328 6423 6424 6524 6527 6623 6624 6652 6653 6654 6655 + 6722 6723 6724 6725 6822 6823 6824 6825 6922 6923 6924 6925 6926 + 7225 7227 7228 7229 7324 7326 7327 7329 7425 7426 7522 7525 7526 7528 7529 7724 7823 7825 7923 + 8020 8022 8026 8029 8220 8222 8223 8224 8225 8226 8227 8229 8232 8325 8327 8328 8425 8426 8427 8522 8523 8524 + 8622 8623 8624 8625 8626 8723 8725 8727 + 9020 9022 9024 9025 9027 9028 9032 9033 9222 9223 9225 9226 9227 9228 9229 9232 9233 9424 9426 9428 9524 9525 9528 9529 9824 9827] } -ndcs_with_6_subscriber_numbers = {2 => %w[31 41], 3 => %w[721 821]} +ndcs_with_6_subscriber_numbers = { 2 => %w[31 41], 3 => %w[721 821] } -ndcs_with_7_subscriber_numbers = {1 => %w[2], 3 => %w[431]} +ndcs_with_7_subscriber_numbers = { 1 => %w[2], 3 => %w[431] } Phony.define do country '880', diff --git a/lib/phony/countries/italy.rb b/lib/phony/countries/italy.rb index 4705d9ab..f673ba33 100644 --- a/lib/phony/countries/italy.rb +++ b/lib/phony/countries/italy.rb @@ -271,10 +271,6 @@ ] # Not exhaustive. Unused below - just for info purposes. -free_of_charge_services = %w[ - 800 - 803 -] Phony.define do # NOTE: The 0 does not count towards NDC number length. diff --git a/lib/phony/countries/south_korea.rb b/lib/phony/countries/south_korea.rb index 21ebc8bd..087e9863 100644 --- a/lib/phony/countries/south_korea.rb +++ b/lib/phony/countries/south_korea.rb @@ -19,7 +19,7 @@ Phony.define do country '82', trunk('0') | - match(/^(#{special.join("|")})$/) >> split(3, 3) | # Special actually don't need to be split – but better err. + match(/^(#{special.join('|')})$/) >> split(3, 3) | # Special actually don't need to be split – but better err. one_of(*mobile) >> split(4, 4) | one_of('2') >> matched_split( /\A\d{7}\z/ => [3, 4], diff --git a/lib/phony/country.rb b/lib/phony/country.rb index eb93bddf..f78375bd 100644 --- a/lib/phony/country.rb +++ b/lib/phony/country.rb @@ -103,7 +103,7 @@ def format_cc_ndc(trunk, ndc, local, type, space, parentheses, use_trunk) case type when String trunk &&= trunk.format(space, use_trunk) - type % { trunk: trunk, cc: @cc, ndc: ndc, local: local } + format(type, trunk: trunk, cc: @cc, ndc: ndc, local: local) when nil, :international_absolute, :international, :+ if ndc format_with_ndc(@@international_absolute_format, @cc, format_ndc(ndc, parentheses), local, space) @@ -119,9 +119,9 @@ def format_cc_ndc(trunk, ndc, local, type, space, parentheses, use_trunk) when :national trunk &&= trunk.format(space, use_trunk) if ndc && !ndc.empty? - @@national_format % [trunk, format_ndc(ndc, parentheses), space, local] + format(@@national_format, trunk, format_ndc(ndc, parentheses), space, local) else - @@national_format % [trunk, nil, nil, local] + format(@@national_format, trunk, nil, nil, local) end when :local local @@ -134,11 +134,11 @@ def format_ndc(ndc, parentheses) end def format_with_ndc(format, cc, ndc, local, space) - format % [cc, space, ndc, space, local] + format(format, cc, space, ndc, space, local) end def format_without_ndc(format, cc, local, space) - format % [cc, space, local, nil, nil] + format(format, cc, space, local, nil, nil) end # Cleans all non-numeric characters. diff --git a/lib/phony/country_codes.rb b/lib/phony/country_codes.rb index 3a0a9163..2c500683 100644 --- a/lib/phony/country_codes.rb +++ b/lib/phony/country_codes.rb @@ -104,7 +104,7 @@ def plausible?(number, hints = {}) # False if it fails the basic check. # - return false unless (4..16).include?(normalized.size) # unless hints[:check_length] == false + return false unless (4..16).cover?(normalized.size) # unless hints[:check_length] == false country, cc, rest = partial_split normalized @@ -113,7 +113,10 @@ def plausible?(number, hints = {}) if (ccc = hints[:ccc]) cc, ndc, *local = split ccc - raise ArgumentError.new("The provided ccc option is too long and includes more than a cc ('#{cc}') and ndc ('#{ndc}'). It also includes '#{local.join}'.") unless local.size == 1 && local[0].empty? + unless local.size == 1 && local[0].empty? + raise ArgumentError, + "The provided ccc option is too long and includes more than a cc ('#{cc}') and ndc ('#{ndc}'). It also includes '#{local.join}'." + end hints[:cc] = cc hints[:ndc] = ndc diff --git a/lib/phony/dsl.rb b/lib/phony/dsl.rb index 7711b245..c2360f8d 100644 --- a/lib/phony/dsl.rb +++ b/lib/phony/dsl.rb @@ -13,9 +13,9 @@ module Phony # # Phony.define.country ... # - def self.define(&block) + def self.define(&) dsl = DSL.new - dsl.instance_eval(&block) if block_given? + dsl.instance_eval(&) if block_given? dsl end @@ -160,7 +160,7 @@ def one_of *ndcs def match(regex, options = {}) # Check if regexp has a group in it. # - raise "Regexp /#{regex.source}/ needs a group in it that defines which digits belong to the NDC." unless /\(/.match?(regex.source) + raise "Regexp /#{regex.source}/ needs a group in it that defines which digits belong to the NDC." unless regex.source.include?('(') NationalSplitters::Regex.instance_for regex, options[:on_fail_take], options end diff --git a/lib/phony/local_splitters/fixed.rb b/lib/phony/local_splitters/fixed.rb index 0666a27a..683084b7 100644 --- a/lib/phony/local_splitters/fixed.rb +++ b/lib/phony/local_splitters/fixed.rb @@ -35,7 +35,7 @@ def extract_params(format) if format.last.respond_to? :max last = format.pop length = format.sum - length = (length + last.min..length + last.max) + length = ((length + last.min)..(length + last.max)) format << last.min else length = format.sum @@ -51,7 +51,7 @@ def extract_params(format) def split(number) cursor = 0 @format.each_with_object([]) do |size, result| - result << number.slice(cursor...cursor + size) + result << number.slice(cursor...(cursor + size)) cursor += size return result if cursor >= number.size end diff --git a/lib/phony/local_splitters/regex.rb b/lib/phony/local_splitters/regex.rb index cefd8c27..04b7984e 100644 --- a/lib/phony/local_splitters/regex.rb +++ b/lib/phony/local_splitters/regex.rb @@ -57,7 +57,7 @@ def plausible?(rest, _hints = {}) def split_with(number, format) cursor = 0 format.each_with_object([]) do |size, result| - result << number.slice(cursor...cursor + size) + result << number.slice(cursor...(cursor + size)) cursor += size return result if cursor >= number.size end << number diff --git a/lib/phony/national_splitters/dsl.rb b/lib/phony/national_splitters/dsl.rb index c31cb64e..9dd59f0c 100644 --- a/lib/phony/national_splitters/dsl.rb +++ b/lib/phony/national_splitters/dsl.rb @@ -5,8 +5,8 @@ module NationalSplitters # TODO # class DSL - def >>(local_splitter) - country_for local_splitter + def >>(other) + country_for other end def country_for(local_splitter) diff --git a/lib/phony/national_splitters/regex.rb b/lib/phony/national_splitters/regex.rb index 195fdd7a..866d67f9 100644 --- a/lib/phony/national_splitters/regex.rb +++ b/lib/phony/national_splitters/regex.rb @@ -34,11 +34,11 @@ def initialize(regex, on_fail_take = nil, options = {}) def split(national_number) # Improve matching. # - return [@zero, national_number.slice!(0..::Regexp.last_match(1).size - 1), national_number] if national_number =~ regex + return [@zero, national_number.slice!(0..(::Regexp.last_match(1).size - 1)), national_number] if national_number =~ regex # Not found. # - super(national_number) + super end # A valid length. diff --git a/lib/phony/national_splitters/variable.rb b/lib/phony/national_splitters/variable.rb index 4a7da9b3..93351683 100644 --- a/lib/phony/national_splitters/variable.rb +++ b/lib/phony/national_splitters/variable.rb @@ -19,7 +19,7 @@ def split(national_number) # This if can possibly be removed. # presumed_code = if @mapped_ndc_min_length.positive? - presumed_code = national_number.slice!(0..@mapped_ndc_min_length - 1) + presumed_code = national_number.slice!(0..(@mapped_ndc_min_length - 1)) else '' end diff --git a/lib/phony/trunk_code.rb b/lib/phony/trunk_code.rb index c9930043..a8aeb483 100644 --- a/lib/phony/trunk_code.rb +++ b/lib/phony/trunk_code.rb @@ -12,7 +12,7 @@ class TrunkCode # def initialize(code, options = {}) @code = code - @trunk_code_replacement = /\A#{code.gsub(/%s/, '')}/ + @trunk_code_replacement = /\A#{code.gsub('%s', '')}/ @normalize = options[:normalize] || options[:normalize].nil? @split = options[:split] @format = options[:format] || options[:format].nil? @@ -47,11 +47,12 @@ def normalize(national_number, options = {}) # def format(space, force = nil) return unless force || @format - if @code.size > 1 - (@code % space).gsub(/\D/, ' ') - else - @code - end + + if @code.size > 1 + (@code % space).gsub(/\D/, ' ') + else + @code + end end end end diff --git a/misc/issue-snippets/270.rb b/misc/issue-snippets/270.rb index f8b878f8..68ba3d25 100644 --- a/misc/issue-snippets/270.rb +++ b/misc/issue-snippets/270.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'phony' numbers = %w[ @@ -9,7 +11,7 @@ ] result = numbers.map do |number| - number = number.sub(/^[0\+]*(64+|\b)/, '64') + number = number.sub(/^[0+]*(64+|\b)/, '64') Phony.normalize(number) end diff --git a/performance/perfer.rb b/performance/perfer.rb index e30688f6..b95dcd68 100644 --- a/performance/perfer.rb +++ b/performance/perfer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Run with: # perfer run perfer.rb # diff --git a/performance/rubinius.rb b/performance/rubinius.rb index 6a238464..85603ce9 100644 --- a/performance/rubinius.rb +++ b/performance/rubinius.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Rubinius profiling. # Run with: # ruby -Xprofiler.full_report -Xprofiler.graph performance/rubinius.rb diff --git a/performance/stackprof.rb b/performance/stackprof.rb index 07b5ce5a..ae106392 100644 --- a/performance/stackprof.rb +++ b/performance/stackprof.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + # Run with: # ruby stackprof.rb # require 'stackprof' require_relative '../lib/phony' -def profile(thing, &block) - profile = StackProf.run mode: thing.to_sym, &block +def profile(thing, &) + profile = StackProf.run(mode: thing.to_sym, &) path = "/tmp/stackprof-#{thing}-phony.dump" - File.open(path, 'wb') { |f| f.write Marshal.dump(profile) } + File.binwrite(path, Marshal.dump(profile)) puts `stackprof #{path}` end @@ -15,7 +17,7 @@ def profile(thing, &block) profile thing do 10_000.times { Phony.normalize '+81-3-9999-9999' } end -profile thing do + profile thing do 10_000.times { Phony.format '81399999999' } end - end +end diff --git a/phony.gemspec b/phony.gemspec index 5d7aa103..6c0d4705 100644 --- a/phony.gemspec +++ b/phony.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Gem::Specification.new do |s| s.name = 'phony' s.version = '2.22.7' diff --git a/qed/applique/ae.rb b/qed/applique/ae.rb index 772e6ef0..c9dd4bde 100644 --- a/qed/applique/ae.rb +++ b/qed/applique/ae.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ae' # Add helper methods here. diff --git a/qed/applique/phony.rb b/qed/applique/phony.rb index e9dad3dd..0b58299e 100644 --- a/qed/applique/phony.rb +++ b/qed/applique/phony.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'phony/config' # Plausibility Helpers @@ -7,7 +9,7 @@ def plausible?(examples) # Succeeding expectations. # - succeeding = [*examples[:true]] + succeeding = [*examples[true]] succeeding.each do |numbers| [*numbers].each do |number| Phony.assert.plausible?(number) @@ -23,7 +25,7 @@ def plausible?(examples) # Explicitly failing expectations + fabricated. # - ([*examples[:false]] + fabricated_failing).each do |number| + ([*examples[false]] + fabricated_failing).each do |number| Phony.refute.plausible?(number) end end @@ -45,9 +47,9 @@ def plausible?(examples) rescue LoadError Phony::PERFORMANCE_RATIO = 0 # Ignore speed tests by default. end -def performance_of(&block) +def performance_of(&) GC.disable - result = Benchmark.realtime(&block) + result = Benchmark.realtime(&) GC.enable result * Phony::PERFORMANCE_RATIO end diff --git a/spec/functional/config_spec.rb b/spec/functional/config_spec.rb index b8d0db2b..0fef9774 100644 --- a/spec/functional/config_spec.rb +++ b/spec/functional/config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe 'Phony::Config' do describe 'load' do before do diff --git a/spec/functional/plausibility_spec.rb b/spec/functional/plausibility_spec.rb index ea19d85b..de86ad21 100644 --- a/spec/functional/plausibility_spec.rb +++ b/spec/functional/plausibility_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'plausibility' do diff --git a/spec/lib/phony/countries_spec.rb b/spec/lib/phony/countries_spec.rb index c6b08a69..60a15433 100644 --- a/spec/lib/phony/countries_spec.rb +++ b/spec/lib/phony/countries_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'country descriptions' do diff --git a/spec/lib/phony/country_codes_spec.rb b/spec/lib/phony/country_codes_spec.rb index 3da6fcec..4c0a7d82 100644 --- a/spec/lib/phony/country_codes_spec.rb +++ b/spec/lib/phony/country_codes_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::CountryCodes do - let(:countries) { Phony::CountryCodes.instance } + let(:countries) { described_class.instance } describe '#plausible?' do it 'raises an error on a too long ccc' do @@ -14,14 +16,14 @@ describe 'ccc handling' do it 'splits a ccc correctly' do - cc, ndc, *local = countries.split('1868') + cc, ndc, = countries.split('1868') expect(cc).to eq '1' expect(ndc).to eq '868' end it 'splits a ccc correctly' do - cc, ndc, *local = countries.split('1868') + cc, ndc, = countries.split('1868') expect(cc).to eq '1' expect(ndc).to eq '868' diff --git a/spec/lib/phony/country_spec.rb b/spec/lib/phony/country_spec.rb index 0338c2a6..ac23d09d 100644 --- a/spec/lib/phony/country_spec.rb +++ b/spec/lib/phony/country_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::Country do @@ -7,7 +9,7 @@ local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2] national_code = Phony::NationalCode.new national_splitter, local_splitter - Phony::Country.new national_code + described_class.new national_code end describe '#clean' do @@ -70,7 +72,7 @@ local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2] national_code = Phony::NationalCode.new national_splitter, local_splitter - Phony::Country.new national_code + described_class.new national_code end describe 'split' do @@ -96,7 +98,7 @@ local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2] national_code = Phony::NationalCode.new national_splitter, local_splitter - Phony::Country.new special_code, national_code + described_class.new special_code, national_code end describe 'split' do diff --git a/spec/lib/phony/dsl_spec.rb b/spec/lib/phony/dsl_spec.rb index fa720f31..4fd64279 100644 --- a/spec/lib/phony/dsl_spec.rb +++ b/spec/lib/phony/dsl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::DSL do @@ -15,8 +17,9 @@ describe 'match' do it 'checks for ( in regex' do - expect { - dsl.match(/123/) }.to raise_error('Regexp /123/ needs a group in it that defines which digits belong to the NDC.') + expect do + dsl.include?('123') + end.to raise_error('Regexp /123/ needs a group in it that defines which digits belong to the NDC.') end it 'returns a Phony::NationalSplitters::Regex' do diff --git a/spec/lib/phony/local_splitters/fixed_spec.rb b/spec/lib/phony/local_splitters/fixed_spec.rb index de32c486..653a7ba1 100644 --- a/spec/lib/phony/local_splitters/fixed_spec.rb +++ b/spec/lib/phony/local_splitters/fixed_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::LocalSplitters::Fixed do diff --git a/spec/lib/phony/local_splitters/regex_spec.rb b/spec/lib/phony/local_splitters/regex_spec.rb index c23b3ac3..eb80db8e 100644 --- a/spec/lib/phony/local_splitters/regex_spec.rb +++ b/spec/lib/phony/local_splitters/regex_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' main = self diff --git a/spec/lib/phony/national_code_spec.rb b/spec/lib/phony/national_code_spec.rb index be26438b..d2f0100c 100644 --- a/spec/lib/phony/national_code_spec.rb +++ b/spec/lib/phony/national_code_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::NationalCode do @@ -8,7 +10,7 @@ national_splitter = Phony::NationalSplitters::None.instance_for local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4] - Phony::NationalCode.new national_splitter, local_splitter + described_class.new national_splitter, local_splitter end it 'splits correctly' do @@ -22,7 +24,7 @@ national_splitter = Phony::NationalSplitters::Fixed.instance_for 2 local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2] - Phony::NationalCode.new national_splitter, local_splitter + described_class.new national_splitter, local_splitter end it 'splits correctly' do @@ -47,7 +49,7 @@ national_splitter = Phony::NationalSplitters::Fixed.instance_for 1 local_splitter = Phony::LocalSplitters::Fixed.instance_for [2, 2, 2, 2] - Phony::NationalCode.new national_splitter, local_splitter + described_class.new national_splitter, local_splitter end it 'splits correctly' do diff --git a/spec/lib/phony/national_splitters/default_spec.rb b/spec/lib/phony/national_splitters/default_spec.rb index 7fb4e7cc..d8a4a9ff 100644 --- a/spec/lib/phony/national_splitters/default_spec.rb +++ b/spec/lib/phony/national_splitters/default_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::NationalSplitters::Default do diff --git a/spec/lib/phony/national_splitters/fixed_spec.rb b/spec/lib/phony/national_splitters/fixed_spec.rb index ef0bda11..ae9e49cb 100644 --- a/spec/lib/phony/national_splitters/fixed_spec.rb +++ b/spec/lib/phony/national_splitters/fixed_spec.rb @@ -1,18 +1,20 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::NationalSplitters::Fixed do describe 'instance_for' do it 'caches' do - expect(Phony::NationalSplitters::Fixed.instance_for(3)).to eq Phony::NationalSplitters::Fixed.instance_for(3) + expect(described_class.instance_for(3)).to eq described_class.instance_for(3) end it 'caches correctly' do - expect(Phony::NationalSplitters::Fixed.instance_for(1)).to_not eq Phony::NationalSplitters::Fixed.instance_for(2) + expect(described_class.instance_for(1)).not_to eq described_class.instance_for(2) end end describe 'split' do - let(:splitter) { Phony::NationalSplitters::Fixed.new(2) } + let(:splitter) { described_class.new(2) } it 'splits correctly' do expect(splitter.split('443643532')).to eq [nil, '44', '3643532'] @@ -32,7 +34,7 @@ end describe 'split' do - let(:splitter) { Phony::NationalSplitters::Fixed.new(nil) } + let(:splitter) { described_class.new(nil) } it 'splits correctly' do expect(splitter.split('443643532')).to eq [nil, '443643532'] diff --git a/spec/lib/phony/national_splitters/none_spec.rb b/spec/lib/phony/national_splitters/none_spec.rb index 1934c627..6765ddf1 100644 --- a/spec/lib/phony/national_splitters/none_spec.rb +++ b/spec/lib/phony/national_splitters/none_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::NationalSplitters::None do diff --git a/spec/lib/phony/national_splitters/regex_spec.rb b/spec/lib/phony/national_splitters/regex_spec.rb index e51667e5..bbf67ab5 100644 --- a/spec/lib/phony/national_splitters/regex_spec.rb +++ b/spec/lib/phony/national_splitters/regex_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::NationalSplitters::Regex do diff --git a/spec/lib/phony/national_splitters/variable_spec.rb b/spec/lib/phony/national_splitters/variable_spec.rb index dc80a032..bb780eb8 100644 --- a/spec/lib/phony/national_splitters/variable_spec.rb +++ b/spec/lib/phony/national_splitters/variable_spec.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::NationalSplitters::Variable do describe 'split' do context 'when normal' do - let(:splitter) { Phony::NationalSplitters::Variable.new 4, %w[1 316 67 68 669 711] } + let(:splitter) { described_class.new 4, %w[1 316 67 68 669 711] } it 'handles Vienna' do expect(splitter.split('198110')).to eq [nil, '1', '98110'] @@ -27,7 +29,7 @@ end context 'with special handling for using the variable size splitter for Swiss service numbers' do - let(:splitter) { Phony::NationalSplitters::Variable.new 2, ['800'] } + let(:splitter) { described_class.new 2, ['800'] } it 'handles swiss service numbers' do expect(splitter.split('800223344')).to eq [nil, '800', '223344'] diff --git a/spec/lib/phony/trunk_code_spec.rb b/spec/lib/phony/trunk_code_spec.rb index 3ab37980..57a56e47 100644 --- a/spec/lib/phony/trunk_code_spec.rb +++ b/spec/lib/phony/trunk_code_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::TrunkCode do diff --git a/spec/lib/phony/vanity_spec.rb b/spec/lib/phony/vanity_spec.rb index 80892db0..2d881f47 100644 --- a/spec/lib/phony/vanity_spec.rb +++ b/spec/lib/phony/vanity_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::Vanity do diff --git a/spec/lib/phony_spec.rb b/spec/lib/phony_spec.rb index 0d7430c2..0f4c43d8 100644 --- a/spec/lib/phony_spec.rb +++ b/spec/lib/phony_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'spec_helper' describe Phony::NormalizationError do it 'is correctly raised on normalize' do expect do Phony.normalize('000') - end.to raise_error(Phony::NormalizationError) + end.to raise_error(described_class) end it 'is correctly raised on normalize' do @@ -16,7 +18,7 @@ it 'is correctly raised on normalize!' do expect do Phony.normalize!('000') - end.to raise_error(Phony::NormalizationError) + end.to raise_error(described_class) end it 'is correctly raised on normalize!' do @@ -30,7 +32,7 @@ it 'is correctly raised on split' do expect do Phony.split('000') - end.to raise_error(Phony::SplittingError) + end.to raise_error(described_class) end it 'is correctly raised on split' do @@ -42,7 +44,7 @@ it 'is correctly raised on split!' do expect do Phony.split!('000') - end.to raise_error(Phony::SplittingError) + end.to raise_error(described_class) end it 'is correctly raised on split!' do @@ -56,7 +58,7 @@ it 'is correctly raised on format' do expect do Phony.format('000') - end.to raise_error(Phony::FormattingError) + end.to raise_error(described_class) end it 'is correctly raised on format' do @@ -68,7 +70,7 @@ it 'is correctly raised on format!' do expect do Phony.format!('000') - end.to raise_error(Phony::FormattingError) + end.to raise_error(described_class) end it 'is correctly raised on format!' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fc94f4c0..7b57705c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Warning[:deprecated] = true begin diff --git a/spec/spec_helper_extensions.rb b/spec/spec_helper_extensions.rb index 14b5b908..3a395d5a 100644 --- a/spec/spec_helper_extensions.rb +++ b/spec/spec_helper_extensions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SpecHelperExtensions # performance_of { do something here }.should < 0.0001 # @@ -15,9 +17,9 @@ module SpecHelperExtensions # Ignore speed tests by default. Phony::PERFORMANCE_RATIO = 0 unless Phony.constants.include?(:PERFORMANCE_RATIO) end - def performance_of(&block) + def performance_of(&) GC.disable - result = Benchmark.realtime(&block) + result = Benchmark.realtime(&) GC.enable result * Phony::PERFORMANCE_RATIO end From a1bfba20e616c0706bf4a0e5b013144ce44122fb Mon Sep 17 00:00:00 2001 From: Simone Carletti <5387+weppos@users.noreply.github.com> Date: Mon, 15 Dec 2025 11:19:01 -0500 Subject: [PATCH 2/2] Update config exclusion Remove Rails -specific configurations. --- .rubocop.yml | 56 +++++------------ .rubocop_todo.yml | 157 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+), 42 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 80bb91ab..1dfb5b9e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,22 @@ +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 @@ -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: @@ -88,15 +86,6 @@ Metrics/ClassLength: - array - hash - heredoc - Exclude: - - 'db/**/*' - -Metrics/ParameterLists: - Max: 7 - MaxOptionalParameters: 5 - Exclude: - - "spec/components/**/*.rb" - - "app/components/**/*.rb" Naming/InclusiveLanguage: Enabled: false @@ -104,12 +93,6 @@ Naming/InclusiveLanguage: RSpec/MultipleExpectations: Enabled: false -RSpec/DescribeClass: - Exclude: - - 'spec/routing/**/*' - - 'spec/system/**/*' - - 'spec/views/**/*' - RSpec/DescribedClass: SkipBlocks: true @@ -119,10 +102,6 @@ RSpec/EmptyExampleGroup: RSpec/ExampleLength: Enabled: false -RSpec/InstanceVariable: - Exclude: - - 'spec/views/**/*' - RSpec/NestedGroups: Max: 6 @@ -143,10 +122,3 @@ RSpec/AnyInstance: RSpec/VerifiedDoubles: Enabled: false - -AllCops: - NewCops: enable - TargetRubyVersion: 3.2 - Exclude: - - 'bin/**/*' - - 'tmp/**/*' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..bff5881c --- /dev/null +++ b/.rubocop_todo.yml @@ -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'