From 5a4b0859b53438874a84d3d3f805af2a939796c9 Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Wed, 5 Apr 2023 10:14:09 -0700 Subject: [PATCH 1/5] Add Ruby 3.2 to CI and update Rubocop --- .github/workflows/rake.yml | 7 ++++--- .rubocop.yml | 15 +++++++++++---- lib/timezone.rb | 4 ++-- lib/timezone/loader.rb | 4 ++-- lib/timezone/lookup.rb | 4 ++-- lib/timezone/lookup/geonames.rb | 3 ++- lib/timezone/lookup/google.rb | 3 ++- lib/timezone/parser.rb | 9 +++++---- lib/timezone/version.rb | 2 +- lib/timezone/zone.rb | 3 +-- test/test_timezone.rb | 2 +- test/timezone/lookup/test_geonames.rb | 12 ++++++------ test/timezone/lookup/test_google.rb | 4 ++-- test/timezone/test_lookup.rb | 10 +++++----- timezone.gemspec | 8 +++++--- 15 files changed, 51 insertions(+), 39 deletions(-) diff --git a/.github/workflows/rake.yml b/.github/workflows/rake.yml index 72bf1748..9ff1e854 100644 --- a/.github/workflows/rake.yml +++ b/.github/workflows/rake.yml @@ -10,11 +10,12 @@ jobs: test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - ruby-version: ['2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1'] + ruby-version: ['2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: @@ -30,7 +31,7 @@ jobs: ruby-version: ['3.0'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: diff --git a/.rubocop.yml b/.rubocop.yml index 795474df..0f611196 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,15 +1,18 @@ +require: + - rubocop-performance + AllCops: TargetRubyVersion: 2.2 -Layout/AlignParameters: - EnforcedStyle: with_fixed_indentation - Layout/EmptyLineBetweenDefs: Enabled: true Layout/MultilineMethodCallIndentation: EnforcedStyle: indented +Layout/ParameterAlignment: + EnforcedStyle: with_fixed_indentation + Layout/SpaceAfterComma: Enabled: true @@ -22,6 +25,10 @@ Layout/SpaceAroundOperators: Layout/SpaceBeforeSemicolon: Enabled: true +Lint/MissingSuper: + Enabled: true + Exclude: + - lib/timezone/lookup/test.rb Lint/DuplicateMethods: Enabled: true @@ -103,7 +110,7 @@ Style/StringLiterals: Style/TrivialAccessors: Enabled: true -Style/UnneededPercentQ: +Style/RedundantPercentQ: Enabled: true Style/DateTime: diff --git a/lib/timezone.rb b/lib/timezone.rb index ed96cac4..a80bf587 100644 --- a/lib/timezone.rb +++ b/lib/timezone.rb @@ -39,14 +39,14 @@ def self.[](name) # # @raise [Timezone::Error::InvalidZone] if the timezone is not found # and a default value and block have not been provided - def self.fetch(name, default = :__block, &block) + def self.fetch(name, default = :__block) return ::Timezone::Zone.new(name) if Loader.valid?(name) if block_given? && default != :__block warn('warning: block supersedes default value argument') end - return block.call(name) if block_given? + return yield(name) if block_given? return default unless default == :__block raise ::Timezone::Error::InvalidZone diff --git a/lib/timezone/loader.rb b/lib/timezone/loader.rb index 9bda5ea9..fb69c703 100644 --- a/lib/timezone/loader.rb +++ b/lib/timezone/loader.rb @@ -2,10 +2,10 @@ require 'timezone/error' -module Timezone # rubocop:disable Style/Documentation +module Timezone # Responsible for loading and parsing timezone data from files. module Loader - ZONE_FILE_PATH = File.expand_path(File.dirname(__FILE__) + '/../../data') + ZONE_FILE_PATH = File.expand_path("#{File.dirname(__FILE__)}/../../data") SOURCE_BIT = 0 @rules = {} # cache of loaded rules diff --git a/lib/timezone/lookup.rb b/lib/timezone/lookup.rb index 29886446..07087ad6 100644 --- a/lib/timezone/lookup.rb +++ b/lib/timezone/lookup.rb @@ -9,7 +9,7 @@ module Timezone # Configure timezone lookups. module Lookup class << self - MISSING_LOOKUP = 'No lookup configured'.freeze + MISSING_LOOKUP = 'No lookup configured' private_constant :MISSING_LOOKUP # Returns the lookup object @@ -45,7 +45,7 @@ class OptionSetter test: ::Timezone::Lookup::Test }.freeze - INVALID_LOOKUP = 'Invalid lookup specified'.freeze + INVALID_LOOKUP = 'Invalid lookup specified' attr_reader :config diff --git a/lib/timezone/lookup/geonames.rb b/lib/timezone/lookup/geonames.rb index ccd6ae0e..48f7a117 100644 --- a/lib/timezone/lookup/geonames.rb +++ b/lib/timezone/lookup/geonames.rb @@ -38,7 +38,7 @@ def lookup(lat, long) return unless data['status'] - return if NO_TIMEZONE_INFORMATION == data['status']['value'] + return if data['status']['value'] == NO_TIMEZONE_INFORMATION raise(Timezone::Error::GeoNames, data['status']['message']) rescue StandardError => e @@ -55,6 +55,7 @@ def get_timezone_id(data) return unless data['gmtOffset'].is_a? Numeric return 'Etc/UTC' if data['gmtOffset'].zero? + "Etc/GMT#{format('%+d', -data['gmtOffset'])}" end diff --git a/lib/timezone/lookup/google.rb b/lib/timezone/lookup/google.rb index 56466399..f596a532 100644 --- a/lib/timezone/lookup/google.rb +++ b/lib/timezone/lookup/google.rb @@ -14,7 +14,7 @@ module Lookup class Google < ::Timezone::Lookup::Basic # Indicates that no time zone data could be found for the specified # . This can occur if the query is incomplete or ambiguous. - NO_TIMEZONE_INFORMATION = 'ZERO_RESULTS'.freeze + NO_TIMEZONE_INFORMATION = 'ZERO_RESULTS' def initialize(config) if config.api_key.nil? @@ -35,6 +35,7 @@ def lookup(lat, long) end return unless response.code =~ /^2\d\d$/ + data = JSON.parse(response.body) return if data['status'] == NO_TIMEZONE_INFORMATION diff --git a/lib/timezone/parser.rb b/lib/timezone/parser.rb index 961823ac..cbb2d64b 100644 --- a/lib/timezone/parser.rb +++ b/lib/timezone/parser.rb @@ -9,7 +9,7 @@ class Parser MIN_YEAR = -500 MAX_YEAR = 2039 - LINE = /\s*(.+)\s*=\s*(.+)\s*isdst=(\d+)\s*gmtoff=([\+\-]*\d+)/ + LINE = /\s*(.+)\s*=\s*(.+)\s*isdst=(\d+)\s*gmtoff=([+-]*\d+)/.freeze # Bookkeeping files that we do not want to parse. IGNORE = ['leapseconds', 'posixrules', 'tzdata.zi'].freeze @@ -25,6 +25,7 @@ def perform next if File.directory?(file) next if file.end_with?('.tab') next if IGNORE.include?(File.basename(file)) + parse(file) end end @@ -65,7 +66,7 @@ def to_s def parse_offset(offset) arity = offset.start_with?('-') ? -1 : 1 - match = offset.match(/^[\-\+](\d{2})$/) + match = offset.match(/^[-+](\d{2})$/) arity * match[1].to_i * 60 * 60 end end @@ -76,10 +77,10 @@ def parse_offset(offset) class Line attr_accessor :source, :name, :dst, :offset - SOURCE_FORMAT = '%a %b %e %H:%M:%S %Y %Z'.freeze + SOURCE_FORMAT = '%a %b %e %H:%M:%S %Y %Z' def initialize(match) - self.source = Time.strptime(match[1] + 'C', SOURCE_FORMAT).to_i + self.source = Time.strptime("#{match[1]}C", SOURCE_FORMAT).to_i self.name = match[2].split(' ').last self.dst = match[3].to_i self.offset = match[4].to_i diff --git a/lib/timezone/version.rb b/lib/timezone/version.rb index df113d4d..2535bb52 100644 --- a/lib/timezone/version.rb +++ b/lib/timezone/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Timezone - VERSION = '1.3.23'.freeze + VERSION = '1.3.23' end diff --git a/lib/timezone/zone.rb b/lib/timezone/zone.rb index 3d2ebd56..a5ffa263 100644 --- a/lib/timezone/zone.rb +++ b/lib/timezone/zone.rb @@ -6,7 +6,6 @@ require 'timezone/loader' require 'timezone/error' -require 'timezone/loader' module Timezone # This object represents a real-world timezone. Each instance provides @@ -187,7 +186,7 @@ def sanitize(time) # # Each rule has a SOURCE bit which is the number of seconds, since the # Epoch, up to which the rule is valid. - def match?(seconds, rule) #:nodoc: + def match?(seconds, rule) # :nodoc: seconds <= rule[SOURCE_BIT] end diff --git a/test/test_timezone.rb b/test/test_timezone.rb index d3f4579e..6c971f42 100644 --- a/test/test_timezone.rb +++ b/test/test_timezone.rb @@ -20,7 +20,7 @@ def test_get def test_fetch assert Timezone.fetch('Australia/Sydney').valid? - assert_equal 'foo', Timezone.fetch('foo/bar') { 'foo' } + assert_equal 'foo', Timezone.fetch('foo/bar', 'foo') assert_raises Timezone::Error::InvalidZone do Timezone.fetch('foo/bar') end diff --git a/test/timezone/lookup/test_geonames.rb b/test/timezone/lookup/test_geonames.rb index 6e5ebdf8..b6827963 100644 --- a/test/timezone/lookup/test_geonames.rb +++ b/test/timezone/lookup/test_geonames.rb @@ -40,7 +40,7 @@ def test_missing_username end def test_lookup - mine = lookup(File.open(mock_path + '/lat_lon_coords.txt').read) + mine = lookup(File.open("#{mock_path}/lat_lon_coords.txt").read) assert_equal 'Australia/Adelaide', mine.lookup(*coordinates) end @@ -55,7 +55,7 @@ def test_lookup_with_etc end def test_wrong_offset - body = File.open(mock_path + '/lat_lon_coords_wrong_offset.txt').read + body = File.open("#{mock_path}/lat_lon_coords_wrong_offset.txt").read mine = lookup(body) { |c| c.offset_etc_zones = true } assert_nil mine.lookup(*coordinates) @@ -80,7 +80,7 @@ def assert_exception(lookup, message) end def test_api_limit - mine = lookup(File.open(mock_path + '/api_limit_reached.json').read) + mine = lookup(File.open("#{mock_path}/api_limit_reached.json").read) assert_exception( mine, @@ -90,19 +90,19 @@ def test_api_limit end def test_invalid_latlong - mine = lookup(File.open(mock_path + '/invalid_latlong.json').read) + mine = lookup(File.open("#{mock_path}/invalid_latlong.json").read) assert_exception(mine, 'invalid lat/lng') end def test_no_result_found - mine = lookup(File.open(mock_path + '/no_result_found.json').read) + mine = lookup(File.open("#{mock_path}/no_result_found.json").read) assert_nil(mine.lookup(10, 10)) end def test_invalid_parameter - mine = lookup(File.open(mock_path + '/invalid_parameter.json').read) + mine = lookup(File.open("#{mock_path}/invalid_parameter.json").read) assert_exception(mine, 'error parsing parameter') end diff --git a/test/timezone/lookup/test_google.rb b/test/timezone/lookup/test_google.rb index b8e5db34..d045b815 100644 --- a/test/timezone/lookup/test_google.rb +++ b/test/timezone/lookup/test_google.rb @@ -33,7 +33,7 @@ def test_missing_api_key end def test_google_using_lat_long_coordinates - mine = lookup(File.open(mock_path + '/google_lat_lon_coords.txt').read) + mine = lookup(File.open("#{mock_path}/google_lat_lon_coords.txt").read) assert_equal 'Australia/Adelaide', mine.lookup(*coordinates) end @@ -76,7 +76,7 @@ def test_url_enterprise end def test_no_result_found - mine = lookup(File.open(mock_path + '/google_no_result_found.json').read) + mine = lookup(File.open("#{mock_path}/google_no_result_found.json").read) assert_nil(mine.lookup(26.188703, -78.987053)) end diff --git a/test/timezone/test_lookup.rb b/test/timezone/test_lookup.rb index 950e1801..e5548ee8 100644 --- a/test/timezone/test_lookup.rb +++ b/test/timezone/test_lookup.rb @@ -8,7 +8,7 @@ def test_test_config Timezone::Lookup.config(:test) assert_equal Timezone::Lookup::Test, - Timezone::Lookup.lookup.class + Timezone::Lookup.lookup.class end def test_geonames_config @@ -17,10 +17,10 @@ def test_geonames_config end assert_equal Timezone::Lookup::Geonames, - Timezone::Lookup.lookup.class + Timezone::Lookup.lookup.class assert_equal Timezone::NetHTTPClient, - Timezone::Lookup.lookup.config.request_handler + Timezone::Lookup.lookup.config.request_handler end def test_google_config @@ -29,10 +29,10 @@ def test_google_config end assert_equal Timezone::Lookup::Google, - Timezone::Lookup.lookup.class + Timezone::Lookup.lookup.class assert_equal Timezone::NetHTTPClient, - Timezone::Lookup.lookup.config.request_handler + Timezone::Lookup.lookup.config.request_handler end def test_custom_config diff --git a/timezone.gemspec b/timezone.gemspec index 97bcb3aa..c05d6547 100644 --- a/timezone.gemspec +++ b/timezone.gemspec @@ -1,7 +1,6 @@ # frozen_string_literal: true -# -*- encoding: utf-8 -*- -$:.push File.expand_path('../lib', __FILE__) +$:.push File.expand_path('lib', __dir__) require 'timezone/version' Gem::Specification.new do |s| @@ -25,8 +24,11 @@ Gem::Specification.new do |s| s.rdoc_options = ['--charset=UTF-8'] s.require_paths = ['lib'] + s.required_ruby_version = '>= 2.2' + s.add_development_dependency('minitest', '~> 5.8') s.add_development_dependency('rake', '~> 12') - s.add_development_dependency('rubocop', '= 0.51') + s.add_development_dependency('rubocop', '>= 0.51') + s.add_development_dependency('rubocop-performance') s.add_development_dependency('timecop', '~> 0.8') end From 707adb33227a54cc2d4571a46309a3713f18b8a0 Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Mon, 22 May 2023 08:46:35 -0400 Subject: [PATCH 2/5] Restore spec, address some cops, make sure everything still runs on 2.2 --- .rubocop.yml | 75 ++--------------------- Rakefile | 2 +- test/test_timezone.rb | 9 ++- test/timezone/lookup/test_basic.rb | 2 +- test/timezone/lookup/test_geonames.rb | 20 +++--- test/timezone/lookup/test_google.rb | 8 +-- test/timezone/lookup/test_test.rb | 2 +- test/timezone/test_deprecate.rb | 2 +- test/timezone/test_lookup.rb | 2 +- test/timezone/test_mathn_compatibility.rb | 2 +- test/timezone/test_nil_zone.rb | 2 +- test/timezone/test_zone.rb | 2 +- timezone.gemspec | 9 +-- 13 files changed, 38 insertions(+), 99 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 0f611196..cbd9c636 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,9 +3,7 @@ require: AllCops: TargetRubyVersion: 2.2 - -Layout/EmptyLineBetweenDefs: - Enabled: true + NewCops: enable Layout/MultilineMethodCallIndentation: EnforcedStyle: indented @@ -13,30 +11,10 @@ Layout/MultilineMethodCallIndentation: Layout/ParameterAlignment: EnforcedStyle: with_fixed_indentation -Layout/SpaceAfterComma: - Enabled: true - -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: true - -Layout/SpaceAroundOperators: - Enabled: true - -Layout/SpaceBeforeSemicolon: - Enabled: true - Lint/MissingSuper: - Enabled: true Exclude: - lib/timezone/lookup/test.rb -Lint/DuplicateMethods: - Enabled: true - -Lint/UnusedMethodArgument: - Enabled: true - - Metrics/AbcSize: Enabled: false @@ -46,7 +24,7 @@ Metrics/ClassLength: # Offense count: 13 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes. # URISchemes: http, https -Metrics/LineLength: +Layout/LineLength: Max: 80 Metrics/MethodLength: @@ -56,47 +34,11 @@ Metrics/MethodLength: Metrics/PerceivedComplexity: Max: 8 - -Performance/RedundantBlockCall: - Enabled: true - - -Naming/MethodName: - Enabled: true - -Naming/BinaryOperatorParameterName: - Enabled: true - - -Style/ClassVars: - Enabled: true - -Style/Documentation: - Enabled: true - -Style/DoubleNegation: - Enabled: true - -Style/EmptyLiteral: - Enabled: true - -Style/GuardClause: - Enabled: true - -Style/HashSyntax: - Enabled: true - Style/NumericLiterals: MinDigits: 5 -Style/PreferredHashMethods: - Enabled: true - -Style/RedundantReturn: - Enabled: true - -Style/RedundantSelf: - Enabled: true +Style/OpenStructUse: + Enabled: false Style/SingleLineMethods: Enabled: false @@ -104,14 +46,5 @@ Style/SingleLineMethods: Style/SpecialGlobalVars: EnforcedStyle: use_perl_names -Style/StringLiterals: - Enabled: true - -Style/TrivialAccessors: - Enabled: true - -Style/RedundantPercentQ: - Enabled: true - Style/DateTime: Enabled: false diff --git a/Rakefile b/Rakefile index 8fc44527..8d095946 100644 --- a/Rakefile +++ b/Rakefile @@ -19,7 +19,7 @@ task(:utc) { ENV['TZ'] = 'UTC' } task default: %i[utc test rubocop] task parse: :utc do - path = ENV['TZPATH'] || File.join(ENV['HOME'], 'Downloads', 'tz') + path = ENV['TZPATH'] || File.join(ENV.fetch('HOME', nil), 'Downloads', 'tz') require 'timezone/parser' diff --git a/test/test_timezone.rb b/test/test_timezone.rb index 6c971f42..82b3ca43 100644 --- a/test/test_timezone.rb +++ b/test/test_timezone.rb @@ -3,7 +3,7 @@ require 'timezone' require 'minitest/autorun' -class TestTimezone < ::Minitest::Test +class TestTimezone < Minitest::Test parallelize_me! def test_names @@ -20,7 +20,12 @@ def test_get def test_fetch assert Timezone.fetch('Australia/Sydney').valid? - assert_equal 'foo', Timezone.fetch('foo/bar', 'foo') + + # Explicitly testing block syntax, so disable Cop + # rubocop:disable Style/RedundantFetchBlock + assert_equal 'foo', Timezone.fetch('foo/bar') { 'foo' } + # rubocop:enable Style/RedundantFetchBlock + assert_raises Timezone::Error::InvalidZone do Timezone.fetch('foo/bar') end diff --git a/test/timezone/lookup/test_basic.rb b/test/timezone/lookup/test_basic.rb index a49b1706..103db4d2 100644 --- a/test/timezone/lookup/test_basic.rb +++ b/test/timezone/lookup/test_basic.rb @@ -4,7 +4,7 @@ require 'minitest/autorun' require 'ostruct' -class BasicLookupTest < ::Minitest::Test +class BasicLookupTest < Minitest::Test parallelize_me! def config diff --git a/test/timezone/lookup/test_geonames.rb b/test/timezone/lookup/test_geonames.rb index b6827963..3bdf8409 100644 --- a/test/timezone/lookup/test_geonames.rb +++ b/test/timezone/lookup/test_geonames.rb @@ -4,7 +4,7 @@ require 'minitest/autorun' require_relative '../../http_test_client' -class TestGeonames < ::Minitest::Test +class TestGeonames < Minitest::Test parallelize_me! def coordinates @@ -23,7 +23,7 @@ def lookup(body = nil, &_block) config = OpenStruct.new config.username = 'timezone' config.request_handler = HTTPTestClientFactory.new(body) - yield config if block_given? + yield config if _block Timezone::Lookup::Geonames.new(config) end @@ -40,14 +40,14 @@ def test_missing_username end def test_lookup - mine = lookup(File.open("#{mock_path}/lat_lon_coords.txt").read) + mine = lookup(File.read("#{mock_path}/lat_lon_coords.txt")) assert_equal 'Australia/Adelaide', mine.lookup(*coordinates) end def test_lookup_with_etc etc_data.each do |key, data| - body = File.open(mock_path + "/lat_lon_coords_#{key}.txt").read + body = File.read(mock_path + "/lat_lon_coords_#{key}.txt") mine = lookup(body) { |c| c.offset_etc_zones = true } assert_equal data[:name], mine.lookup(*data[:coordinates]) @@ -55,7 +55,7 @@ def test_lookup_with_etc end def test_wrong_offset - body = File.open("#{mock_path}/lat_lon_coords_wrong_offset.txt").read + body = File.read("#{mock_path}/lat_lon_coords_wrong_offset.txt") mine = lookup(body) { |c| c.offset_etc_zones = true } assert_nil mine.lookup(*coordinates) @@ -80,29 +80,29 @@ def assert_exception(lookup, message) end def test_api_limit - mine = lookup(File.open("#{mock_path}/api_limit_reached.json").read) + mine = lookup(File.read("#{mock_path}/api_limit_reached.json")) assert_exception( mine, 'the daily limit of 30000 credits for XXXXX has been exceeded. ' \ - 'Please throttle your requests or use the commercial service.' + 'Please throttle your requests or use the commercial service.' ) end def test_invalid_latlong - mine = lookup(File.open("#{mock_path}/invalid_latlong.json").read) + mine = lookup(File.read("#{mock_path}/invalid_latlong.json")) assert_exception(mine, 'invalid lat/lng') end def test_no_result_found - mine = lookup(File.open("#{mock_path}/no_result_found.json").read) + mine = lookup(File.read("#{mock_path}/no_result_found.json")) assert_nil(mine.lookup(10, 10)) end def test_invalid_parameter - mine = lookup(File.open("#{mock_path}/invalid_parameter.json").read) + mine = lookup(File.read("#{mock_path}/invalid_parameter.json")) assert_exception(mine, 'error parsing parameter') end diff --git a/test/timezone/lookup/test_google.rb b/test/timezone/lookup/test_google.rb index d045b815..1c6e9b34 100644 --- a/test/timezone/lookup/test_google.rb +++ b/test/timezone/lookup/test_google.rb @@ -5,7 +5,7 @@ require 'timecop' require_relative '../../http_test_client' -class TestGoogle < ::Minitest::Test +class TestGoogle < Minitest::Test parallelize_me! def coordinates @@ -16,7 +16,7 @@ def lookup(body = nil, &_block) config = OpenStruct.new config.api_key = 'MTIzYWJj' config.request_handler = HTTPTestClientFactory.new(body) - yield config if block_given? + yield config if _block Timezone::Lookup::Google.new(config) end @@ -33,7 +33,7 @@ def test_missing_api_key end def test_google_using_lat_long_coordinates - mine = lookup(File.open("#{mock_path}/google_lat_lon_coords.txt").read) + mine = lookup(File.read("#{mock_path}/google_lat_lon_coords.txt")) assert_equal 'Australia/Adelaide', mine.lookup(*coordinates) end @@ -76,7 +76,7 @@ def test_url_enterprise end def test_no_result_found - mine = lookup(File.open("#{mock_path}/google_no_result_found.json").read) + mine = lookup(File.read("#{mock_path}/google_no_result_found.json")) assert_nil(mine.lookup(26.188703, -78.987053)) end diff --git a/test/timezone/lookup/test_test.rb b/test/timezone/lookup/test_test.rb index 88a87dc6..e8807de3 100644 --- a/test/timezone/lookup/test_test.rb +++ b/test/timezone/lookup/test_test.rb @@ -4,7 +4,7 @@ require 'timezone' require 'minitest/autorun' -class TestTest < ::Minitest::Test +class TestTest < Minitest::Test parallelize_me! def lookup diff --git a/test/timezone/test_deprecate.rb b/test/timezone/test_deprecate.rb index 2e814ff7..140d0870 100644 --- a/test/timezone/test_deprecate.rb +++ b/test/timezone/test_deprecate.rb @@ -3,7 +3,7 @@ require 'timezone/deprecate' require 'minitest/autorun' -class TestDeprecate < ::Minitest::Test +class TestDeprecate < Minitest::Test # This test should not be parallelized because it tests the result # of a single class-level attribute. def test_callback diff --git a/test/timezone/test_lookup.rb b/test/timezone/test_lookup.rb index e5548ee8..9bd8559a 100644 --- a/test/timezone/test_lookup.rb +++ b/test/timezone/test_lookup.rb @@ -3,7 +3,7 @@ require 'timezone/lookup' require 'minitest/autorun' -class TestLookup < ::Minitest::Test +class TestLookup < Minitest::Test def test_test_config Timezone::Lookup.config(:test) diff --git a/test/timezone/test_mathn_compatibility.rb b/test/timezone/test_mathn_compatibility.rb index 0771449b..46fe0d3e 100644 --- a/test/timezone/test_mathn_compatibility.rb +++ b/test/timezone/test_mathn_compatibility.rb @@ -6,7 +6,7 @@ begin require 'mathn' - class TestTimezone < ::Minitest::Test + class TestTimezone < Minitest::Test parallelize_me! def test_lookup_mathn_compatibility diff --git a/test/timezone/test_nil_zone.rb b/test/timezone/test_nil_zone.rb index 30af847d..2cb2e601 100644 --- a/test/timezone/test_nil_zone.rb +++ b/test/timezone/test_nil_zone.rb @@ -3,7 +3,7 @@ require 'timezone/nil_zone' require 'minitest/autorun' -class TestNilZone < ::Minitest::Test +class TestNilZone < Minitest::Test parallelize_me! def setup diff --git a/test/timezone/test_zone.rb b/test/timezone/test_zone.rb index 245ddca1..dd3bb0ed 100644 --- a/test/timezone/test_zone.rb +++ b/test/timezone/test_zone.rb @@ -4,7 +4,7 @@ require 'timezone/zone' require 'minitest/autorun' -class TestZone < ::Minitest::Test +class TestZone < Minitest::Test parallelize_me! def zone(name) diff --git a/timezone.gemspec b/timezone.gemspec index c05d6547..1eff1ee4 100644 --- a/timezone.gemspec +++ b/timezone.gemspec @@ -13,10 +13,10 @@ Gem::Specification.new do |s| s.summary = "timezone-#{Timezone::VERSION}" s.license = 'MIT' s.description = 'Accurate current and historical timezones for Ruby with ' \ - 'support for Geonames and Google latitude - longitude lookups.' + 'support for Geonames and Google latitude - longitude ' \ + 'lookups.' s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*` .split("\n").map { |f| File.basename(f) } @@ -28,7 +28,8 @@ Gem::Specification.new do |s| s.add_development_dependency('minitest', '~> 5.8') s.add_development_dependency('rake', '~> 12') - s.add_development_dependency('rubocop', '>= 0.51') - s.add_development_dependency('rubocop-performance') + s.add_development_dependency('rubocop', '= 1.51.0') + s.add_development_dependency('rubocop-performance', '= 1.18.0') s.add_development_dependency('timecop', '~> 0.8') + s.metadata['rubygems_mfa_required'] = 'true' end From c4121204754d510bee7fc486d10e4511254d44dd Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Mon, 22 May 2023 08:49:18 -0400 Subject: [PATCH 3/5] See if a supremum type restriction will allow everything to run --- timezone.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/timezone.gemspec b/timezone.gemspec index 1eff1ee4..bf18ffa6 100644 --- a/timezone.gemspec +++ b/timezone.gemspec @@ -28,8 +28,8 @@ Gem::Specification.new do |s| s.add_development_dependency('minitest', '~> 5.8') s.add_development_dependency('rake', '~> 12') - s.add_development_dependency('rubocop', '= 1.51.0') - s.add_development_dependency('rubocop-performance', '= 1.18.0') + s.add_development_dependency('rubocop', '<= 1.51.0', '>= 0.5.1') + s.add_development_dependency('rubocop-performance', '<= 1.18.0') s.add_development_dependency('timecop', '~> 0.8') s.metadata['rubygems_mfa_required'] = 'true' end From b648ab61bb1de4c0fbd4d4605c9d097f70d1572a Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Mon, 22 May 2023 08:56:27 -0400 Subject: [PATCH 4/5] Fix a few more issues --- .rubocop.yml | 3 +++ Rakefile | 2 +- lib/timezone/parser.rb | 4 ++-- test/timezone/lookup/test_geonames.rb | 4 ++-- test/timezone/lookup/test_google.rb | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cbd9c636..2c3f8506 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,6 +5,9 @@ AllCops: TargetRubyVersion: 2.2 NewCops: enable +Gemspec/DevelopmentDependencies: + Enabled: false + Layout/MultilineMethodCallIndentation: EnforcedStyle: indented diff --git a/Rakefile b/Rakefile index 8d095946..b05476d3 100644 --- a/Rakefile +++ b/Rakefile @@ -19,7 +19,7 @@ task(:utc) { ENV['TZ'] = 'UTC' } task default: %i[utc test rubocop] task parse: :utc do - path = ENV['TZPATH'] || File.join(ENV.fetch('HOME', nil), 'Downloads', 'tz') + path = ENV['TZPATH'] || File.join(Dir.home, 'Downloads', 'tz') require 'timezone/parser' diff --git a/lib/timezone/parser.rb b/lib/timezone/parser.rb index cbb2d64b..f5015309 100644 --- a/lib/timezone/parser.rb +++ b/lib/timezone/parser.rb @@ -53,7 +53,7 @@ def initialize(config, file) .reject { |line| line.start_with?('TZ=') } .first - _date, _time, raw_offset, @name = first.split(' ') + _date, _time, raw_offset, @name = first.split @offset = parse_offset(raw_offset) end @@ -81,7 +81,7 @@ class Line def initialize(match) self.source = Time.strptime("#{match[1]}C", SOURCE_FORMAT).to_i - self.name = match[2].split(' ').last + self.name = match[2].split.last self.dst = match[3].to_i self.offset = match[4].to_i end diff --git a/test/timezone/lookup/test_geonames.rb b/test/timezone/lookup/test_geonames.rb index 3bdf8409..e98f8310 100644 --- a/test/timezone/lookup/test_geonames.rb +++ b/test/timezone/lookup/test_geonames.rb @@ -19,11 +19,11 @@ def etc_data } end - def lookup(body = nil, &_block) + def lookup(body = nil, &block) config = OpenStruct.new config.username = 'timezone' config.request_handler = HTTPTestClientFactory.new(body) - yield config if _block + yield config if block Timezone::Lookup::Geonames.new(config) end diff --git a/test/timezone/lookup/test_google.rb b/test/timezone/lookup/test_google.rb index 1c6e9b34..153017e3 100644 --- a/test/timezone/lookup/test_google.rb +++ b/test/timezone/lookup/test_google.rb @@ -12,11 +12,11 @@ def coordinates [-34.92771808058, 138.477041423321] end - def lookup(body = nil, &_block) + def lookup(body = nil, &block) config = OpenStruct.new config.api_key = 'MTIzYWJj' config.request_handler = HTTPTestClientFactory.new(body) - yield config if _block + yield config if block Timezone::Lookup::Google.new(config) end From 00f1ad7a111088657aeac9d4aae0df8efcea7fae Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Mon, 22 May 2023 09:12:31 -0400 Subject: [PATCH 5/5] Exclude lints required for tests --- .rubocop.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2c3f8506..99aa4d8e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,6 +8,9 @@ AllCops: Gemspec/DevelopmentDependencies: Enabled: false +Layout/LineLength: + Max: 80 + Layout/MultilineMethodCallIndentation: EnforcedStyle: indented @@ -24,12 +27,6 @@ Metrics/AbcSize: Metrics/ClassLength: Enabled: false -# Offense count: 13 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. -# URISchemes: http, https -Layout/LineLength: - Max: 80 - Metrics/MethodLength: Enabled: false @@ -43,6 +40,11 @@ Style/NumericLiterals: Style/OpenStructUse: Enabled: false +Style/RedundantInitialize: + Exclude: + - test/http_test_client.rb + - test/timezone/test_lookup.rb + Style/SingleLineMethods: Enabled: false