Remove trailing whitespace from (non-generated) source files.

Add a .editorconfig file to enforce.
This commit is contained in:
Phil Ross 2018-12-24 20:37:31 +00:00
parent b6069526cb
commit 4262d6934b
12 changed files with 449 additions and 413 deletions

36
.editorconfig Normal file
View File

@ -0,0 +1,36 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# Copied from the IANA Time Zone Database.
[data/*]
charset = unset
indent_style = unset
indent_size = unset
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
# Generated files.
[lib/tzinfo/data/definitions/**/*]
charset = unset
indent_style = unset
indent_size = unset
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
# Generated files.
[lib/tzinfo/data/indexes/*]
charset = unset
indent_style = unset
indent_size = unset
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset

24
LICENSE
View File

@ -1,19 +1,19 @@
Copyright (c) 2005-2018 Philip Ross
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -25,7 +25,7 @@ License
TZInfo::Data is released under the MIT license, see LICENSE for details.
Timezone data is based on the public domain
Timezone data is based on the public domain
[IANA Time Zone Database](http://www.iana.org/time-zones).
@ -38,5 +38,5 @@ Source code for TZInfo::Data is available on [GitHub](https://github.com/tzinfo/
Issue Tracker
-------------
Please post any bugs, issues, feature requests or questions to the
Please post any bugs, issues, feature requests or questions to the
[GitHub issue tracker](https://github.com/tzinfo/tzinfo-data/issues).

View File

@ -30,9 +30,9 @@ class TZInfoPackageTask < Gem::PackageTask
elsif cmd.first =~ /\A__tar_with_owner__ -?([zjcvf]+)(.*)\z/
opts = $1
args = $2
cmd[0] = "tar c --owner 0 --group 0 -#{opts.gsub('c', '')}#{args}"
cmd[0] = "tar c --owner 0 --group 0 -#{opts.gsub('c', '')}#{args}"
end
orig_sh(*cmd, &block)
end
end
@ -40,7 +40,7 @@ end
def add_signing_key(spec)
# Attempt to find the private key and add options to sign the gem if found.
private_key_path = File.expand_path(File.join(BASE_DIR, '..', 'key', 'gem-private_key.pem'))
if File.exist?(private_key_path)
spec = spec.clone
spec.signing_key = private_key_path
@ -48,7 +48,7 @@ def add_signing_key(spec)
else
puts 'WARNING: Private key not found. Not signing gem file.'
end
spec
end
@ -63,8 +63,8 @@ if defined?(RDoc) && defined?(RDoc::Task)
RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.options.concat spec.rdoc_options
rdoc.rdoc_files.include(spec.extra_rdoc_files)
rdoc.rdoc_files.include('lib')
rdoc.rdoc_files.include(spec.extra_rdoc_files)
rdoc.rdoc_files.include('lib')
end
end
@ -78,9 +78,9 @@ end
def recurse_chmod(dir)
File.chmod(0755, dir)
Dir.entries(dir).each do |entry|
if entry != '.' && entry != '..'
if entry != '.' && entry != '..'
path = File.join(dir, entry)
if File.directory?(path)
recurse_chmod(path)
@ -93,9 +93,9 @@ end
Rake::TestTask.new(:test) do |t|
require 'tzinfo'
t.libs = ['lib']
$:.each do |dir|
if File.exist?(File.join(dir, 'tzinfo.rb'))
t.libs << File.expand_path(dir)
@ -106,17 +106,17 @@ Rake::TestTask.new(:test) do |t|
t.warning = true
end
desc 'Read the TZ database files in the data directory and produce TZInfo::Data Ruby modules'
desc 'Read the TZ database files in the data directory and produce TZInfo::Data Ruby modules'
task :build_tz_modules do
require File.join(LIB_DIR, 'tzinfo', 'data', 'tzdataparser')
FileUtils.mkdir_p(BUILD_TZ_MODULES_DIR)
begin
begin
p = TZInfo::Data::TZDataParser.new(DATA_DIR, BUILD_TZ_MODULES_DIR)
p.execute
scm = Scm.create(BASE_DIR)
['indexes', 'definitions'].each do |dir|
scm.sync(File.join(BUILD_TZ_MODULES_DIR, dir), File.join(DATA_OUTPUT_DIR, dir))
end
@ -149,11 +149,11 @@ class Scm
def exec_scm(params)
puts "#{command} #{params}"
`#{command} #{params}`
raise "#{command} exited with status #$?" if $? != 0
raise "#{command} exited with status #$?" if $? != 0
end
private
def sync_dirs(source_dir, target_dir)
# Assumes a directory will never turn into a file and vice-versa
# (files will all end in .rb, directories won't).
@ -161,34 +161,34 @@ class Scm
source_entries, target_entries = [source_dir, target_dir].collect do |dir|
Dir.entries(dir).delete_if {|entry| entry =~ /\A\./}.sort
end
until source_entries.empty? || target_entries.empty?
until source_entries.empty? || target_entries.empty?
last_source = source_entries.last
last_target = target_entries.last
if last_source == last_target
source_file = File.join(source_dir, last_source)
target_file = File.join(target_dir, last_target)
if File.directory?(source_file)
sync_dirs(source_file, target_file)
else
FileUtils.cp(source_file, target_file)
end
end
source_entries.pop
target_entries.pop
elsif source_entries.last < target_entries.last
sync_only_in_target(target_dir, target_entries)
else
else
sync_only_in_source(source_dir, target_dir, source_entries)
end
end
end
until target_entries.empty?
sync_only_in_target(target_dir, target_entries)
end
until source_entries.empty?
sync_only_in_source(source_dir, target_dir, source_entries)
end
@ -203,7 +203,7 @@ class Scm
def sync_only_in_source(source_dir, target_dir, source_entries)
source_file = File.join(source_dir, source_entries.last)
target_file = File.join(target_dir, source_entries.last)
if File.directory?(source_file)
Dir.mkdir(target_file)
add(target_file)
@ -212,7 +212,7 @@ class Scm
FileUtils.cp(source_file, target_file)
add(target_file)
end
source_entries.pop
end
end
@ -221,10 +221,10 @@ class NullScm < Scm
def command
nil
end
def add(file)
end
def delete(file)
puts "rm -rf \"#{file}\""
FileUtils.rm_rf(file)
@ -235,13 +235,13 @@ class GitScm < Scm
def command
'git'
end
def add(file)
unless File.directory?(file)
exec_scm "add \"#{file}\""
end
end
def delete(file)
exec_scm "rm -rf \"#{file}\""
end
@ -251,11 +251,11 @@ class SvnScm < Scm
def command
'svn'
end
def add(file)
exec_scm "add \"#{file}\""
end
def delete(file)
exec_scm "delete --force \"#{file}\""
end

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ module TZInfo
module Data
# TZInfo::Data version number.
VERSION = '1.2018.7'
# TZInfo::Data version information.
module Version
# The format of the Ruby modules. The only format currently supported by
@ -11,7 +11,7 @@ module TZInfo
# TZInfo::Data version number.
STRING = VERSION
# The version of the {IANA Time Zone Database}[http://www.iana.org/time-zones]
# used to generate this version of TZInfo::Data.
TZDATA = '2018g'

View File

@ -11,10 +11,10 @@ class TCCountryIndex < Minitest::Test
open_file(File.join(DATA_DIR, 'zone1970.tab'), 'r', :external_encoding => 'UTF-8', :internal_encoding => 'UTF-8') do |file|
file.each_line do |line|
line.chomp!
if line =~ /\A([A-Z]{2}(?:,[A-Z]{2})*)\t(?:([+\-])(\d{2})(\d{2})([+\-])(\d{3})(\d{2})|([+\-])(\d{2})(\d{2})(\d{2})([+\-])(\d{3})(\d{2})(\d{2}))\t([^\t]+)(?:\t([^\t]+))?\z/
codes = $1
if $2
latitude = dms_to_rational($2, $3, $4)
longitude = dms_to_rational($5, $6, $7)
@ -22,7 +22,7 @@ class TCCountryIndex < Minitest::Test
latitude = dms_to_rational($8, $9, $10, $11)
longitude = dms_to_rational($12, $13, $14, $15)
end
zone_identifier = $16
description = $17
@ -43,7 +43,7 @@ class TCCountryIndex < Minitest::Test
open_file(File.join(DATA_DIR, 'iso3166.tab'), 'r', :external_encoding => 'UTF-8', :internal_encoding => 'UTF-8') do |file|
file.each_line do |line|
line.chomp!
if line =~ /\A([A-Z]{2})\t(.+)\z/
code = $1
name = $2
@ -52,10 +52,10 @@ class TCCountryIndex < Minitest::Test
end
end
end
countries
end
def dms_to_rational(sign, degrees, minutes, seconds = nil)
result = degrees.to_i + Rational(minutes.to_i, 60)
result += Rational(seconds.to_i, 3600) if seconds
@ -68,14 +68,14 @@ class TCCountryIndex < Minitest::Test
actual = TZInfo::Data::Indexes::Countries.countries
assert_array_same_items(expected.keys.sort, actual.keys.sort)
expected.each do |code, expected_country|
actual_country = actual[code]
assert_equal(code, actual_country.code)
assert_equal(expected_country[:name], actual_country.name)
assert_equal(expected_country[:zones].length, actual_country.zones.length)
expected_country[:zones].zip(actual_country.zones).each do |expected_zone, actual_zone|
assert_equal(expected_zone[:zone_identifier], actual_zone.identifier)
assert_equal(expected_zone[:latitude], actual_zone.latitude)

View File

@ -3,25 +3,25 @@ require 'date'
require 'tmpdir'
class TCDefinitions < Minitest::Test
DATA_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data'))
def data_files
files = Dir.entries(DATA_DIR).select do |name|
name =~ /\A[^\.]+\z/ &&
files = Dir.entries(DATA_DIR).select do |name|
name =~ /\A[^\.]+\z/ &&
!%w(backzone calendars leapseconds CONTRIBUTING LICENSE Makefile NEWS README SOURCE Theory version).include?(name) &&
File.file?(File.join(DATA_DIR, name))
end
files.collect {|name| File.join(DATA_DIR, name)}
end
def compile_data(dest_dir)
unless system('zic', '-d', dest_dir, *data_files)
raise 'Could not execute zic'
end
end
def enum_timezones(base_dir, dir, exclude = [], &block)
Dir.foreach(dir ? File.join(base_dir, dir) : base_dir) do |entry|
unless entry =~ /\./ || exclude.include?(entry)
@ -36,7 +36,7 @@ class TCDefinitions < Minitest::Test
end
end
end
def resolve_ambiguity(periods, identifier, tzi_period)
# Attempt to resolve by just the identifier.
result = periods.select {|period| period.zone_identifier == identifier}
@ -49,7 +49,7 @@ class TCDefinitions < Minitest::Test
result
end
end
def check_zdump_line(zone, line)
if line =~ /\A[^\s]+\s+([A-Za-z][a-z]{2}\s[A-Za-z][a-z]{2}\s+[0-9]+\s[0-9]+:[0-9]+:[0-9]+\s[0-9]+)\s[A-Z]+\s=\s([A-Za-z][a-z]{2}\s[A-Za-z][a-z]{2}\s+[0-9]+\s[0-9]+:[0-9]+:[0-9]+\s[0-9]+)\s([A-Za-z0-9+\-]+)\sisdst=([01])/ then
assert_nothing_raised("Exception raised processing line:\n#{line}") do
@ -57,21 +57,21 @@ class TCDefinitions < Minitest::Test
local = yield $2
identifier = $3.to_sym
is_dst = $4 == '1'
if utc && local
tzi_local = zone.utc_to_local(utc)
tzi_period = zone.period_for_utc(utc)
tzi_identifier = tzi_period.zone_identifier
tzi_is_dst = tzi_period.dst?
msg_zdump = "zdump: #{zone.identifier} #{utc} UTC #{local} #{identifier} is_dst=#{is_dst ? '1' : '0'}"
msg_tzinfo = "tzinfo (u->l): #{zone.identifier} #{utc} UTC #{tzi_local} #{tzi_identifier} is_dst=#{tzi_is_dst ? '1' : '0'}"
message = "#{msg_zdump}\n#{msg_tzinfo}"
assert_equal(local, tzi_local, "Local times don't match:\n#{message}")
assert_equal(identifier, tzi_identifier, "Identifiers don't match:\n#{message}")
assert_equal(is_dst, tzi_is_dst, "DST flag doesn't match:\n#{message}")
tzi_utc = zone.local_to_utc(local, is_dst) {|periods| resolve_ambiguity(periods, identifier, tzi_period)}
tzi_local_identifier = (zone.period_for_local(local, is_dst) {|periods| resolve_ambiguity(periods, identifier, tzi_period)}).zone_identifier
@ -87,7 +87,7 @@ class TCDefinitions < Minitest::Test
assert_match(/\s=\sNULL\z/, line, "Unexpected zdump format")
end
end
def parse_zdump_timestamp(s)
if s =~ /\A(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d\d?)\s(\d\d):(\d\d):(\d\d)\s(\d+)\z/
month = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec).index($1) + 1
@ -96,12 +96,12 @@ class TCDefinitions < Minitest::Test
raise "Unexpected zdump timestamp format: #{s}"
end
end
def parse_as_datetime(s)
year, month, day, hour, minute, second = parse_zdump_timestamp(s)
DateTime.new(year, month, day, hour, minute, second)
end
def parse_as_time(s)
year, month, day, hour, minute, second = parse_zdump_timestamp(s)
begin
@ -111,7 +111,7 @@ class TCDefinitions < Minitest::Test
nil
end
end
def test_all
# 50 years of future transitions are generated. Assume that the year from
# the tzdata version is the year the TZInfo::Data modules were generated.
@ -123,13 +123,13 @@ class TCDefinitions < Minitest::Test
enum_timezones(dir, nil, ['localtime', 'posix', 'posixrules', 'right']) do |identifier|
zone = TZInfo::Timezone.get(identifier)
assert_equal(identifier, zone.identifier)
old_lang = ENV['LANG']
begin
# Use standard C locale to ensure that zdump outputs dates in a format
# Use standard C locale to ensure that zdump outputs dates in a format
# that can be understood
ENV['LANG'] = 'C'
IO.popen("zdump -c #{max_year} -v \"#{File.join(dir, identifier)}\"") do |io|
io.each_line do |line|
line.chomp!
@ -143,7 +143,7 @@ class TCDefinitions < Minitest::Test
end
end
end
def test_zone_types
data_files.each do |data_file|
File.open(data_file, 'r') do |file|

View File

@ -3,15 +3,15 @@ require 'tzinfo/data/indexes/timezones'
class TCTimezoneIndex < Minitest::Test
DATA_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data'))
def data_files
files = Dir.entries(DATA_DIR).select {|name| name =~ /\A[^\.]+\z/ && !%w(backzone leapseconds).include?(name) }
files.collect {|name| File.join(DATA_DIR, name)}
end
def get_zones(data, linked)
result = []
data_files.each do |data_file|
File.open(data_file, 'r') do |file|
file.each do |line|
@ -21,18 +21,18 @@ class TCTimezoneIndex < Minitest::Test
end
end
end
result.sort
end
def test_timezones
assert_array_same_items(get_zones(true, true), TZInfo::Data::Indexes::Timezones.timezones)
end
def test_data_timezones
assert_array_same_items(get_zones(true, false), TZInfo::Data::Indexes::Timezones.data_timezones)
end
def test_linked_timezones
assert_array_same_items(get_zones(false, true), TZInfo::Data::Indexes::Timezones.linked_timezones)
end

View File

@ -13,7 +13,7 @@ class TCVersion < Minitest::Test
def test_version_string
assert(TZInfo::Data::Version::STRING =~ /\A\d+\.\d{4}\.\d+\z/)
end
def test_version_tzdata
assert(TZInfo::Data::Version::TZDATA =~ /\A[0-9]{4}[a-z]\z/)
end

View File

@ -17,7 +17,7 @@ module Kernel
condition = (expected.size == actual.size) && (expected - actual == [])
assert(condition, full_message)
end
def assert_nothing_raised(msg = nil)
begin
yield

View File

@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.author = 'Philip Ross'
s.email = 'phil.ross@gmail.com'
s.homepage = 'http://tzinfo.github.io'
s.license = 'MIT'
s.license = 'MIT'
s.files = ['CONTRIBUTING.md', 'LICENSE', 'README.md', '.yardopts'] +
Dir['lib/**/*.rb'].delete_if {|f| f.include?('.svn')}
s.platform = Gem::Platform::RUBY