8000 Rubocop 0.79 by hainesr · Pull Request #437 · rubyzip/rubyzip · GitHub
[go: up one dir, main page]

Skip to content

Rubocop 0.79 #437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 56 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
c8bfd14
Update rubocop version and the config files.
hainesr Sep 14, 2019
a3245ac
Add Rubocop tasks to the Rakefile.
hainesr Sep 15, 2019
aa40035
Fix Gemspec/OrderedDependencies cop.
hainesr Feb 8, 2020
73e405a
Fix Security/Open cop errors.
hainesr Sep 14, 2019
f1154c2
Fix Style/OrAssignment cop.
hainesr Feb 9, 2020
3a3ac6f
Fix Style/Semicolon cop.
hainesr Sep 14, 2019
e7275da
Fix Style/BlockDelimiters cop errors.
hainesr Sep 14, 2019
98c6969
8000 Fix Layout/SpaceAroundOperators cop.
hainesr Feb 9, 2020
20743a5
Fix Lint/AmbiguousBlockAssociation cop.
hainesr Feb 9, 2020
b528cae
Fix Lint/LiteralAsCondition cop.
hainesr Feb 9, 2020
cd065d0
Fix Lint/UnusedBlockArgument cop.
hainesr Feb 9, 2020
e361a47
Configure Lint/UselessComparison cop.
hainesr Feb 9, 2020
23ba1af
Fix Lint/RescueException cop.
hainesr Feb 9, 2020
0d49421
Fix Lint/UselessAccessModifier cop.
hainesr Feb 9, 2020
fff2c41
Configure Lint/SuppressedException cop.
hainesr Feb 9, 2020
cfe4972
Fix Layout/EmptyLineAfterGuardClause cop.
hainesr Feb 9, 2020
61c83b2
Configure Layout/HashAlignment cop.
hainesr Feb 9, 2020
68259ed
Fix Style/Encoding cop.
hainesr Feb 9, 2020
70d036b
Fix Style/ExpandPathArguments cop.
hainesr Sep 15, 2019
6544563
Configure Style/ZeroLengthPredicate so it doesn't misfire.
hainesr Feb 9, 2020
19aa7e8
Fix Style/RescueStandardError cop.
hainesr Sep 15, 2019
5a1baf4
Fix Style/RedundantReturn cop.
hainesr Sep 15, 2019
b3c4c37
Fix Style/NonNilCheck cop.
hainesr Sep 15, 2019
b3f2413
Fix Style/CommentedKeyword cop.
hainesr Feb 9, 2020
468a80c
Fix Style/IfInsideElse cop.
hainesr Sep 21, 2019
3121ad0
Fix Style/Alias cop.
hainesr Feb 9, 2020
1b8f1a6
Fix Naming/RescuedExceptionsVariableName cop.
hainesr Sep 21, 2019
bce8416
Fix Style/MixinUsage cop.
hainesr Sep 21, 2019
45f4c2d
Fix Style/GuardClause cop.
hainesr Feb 9, 2020
2e11a88
Fix Style/StringLiterals cop.
hainesr Feb 9, 2020
cc0e372
Configure Style/SymbolArray cop.
hainesr Feb 9, 2020
4e1b679
Fix Style/TrailingCommaInArrayLiteral cop.
hainesr Sep 22, 2019
2dfe092
Fix Style/UnpackFirst cop.
hainesr Sep 22, 2019
41f2359
Configure Style/RegexpLiteral cop.
hainesr Feb 9, 2020
5e32204
Configure Style/MultilineBlockChain cop.
hainesr Feb 9, 2020
172ab4b
Fix Style/FloatDivision cop.
hainesr Sep 22, 2019
d42c66c
Fix Style/MultilineWhenThen cop.
hainesr Sep 22, 2019
2dc9b49
Fix Style/EvalWithLocation cop.
hainesr Sep 22, 2019
835843d
Fix Naming/HeredocDelimiterCase cop.
hainesr Sep 22, 2019
7978abb
Configure Naming/MemoizedInstanceVariableName cop.
hainesr Sep 22, 2019
2f99322
Fix Style/Next cop.
hainesr Sep 25, 2019
2cbdbf1
Fix Style/SignalException cop.
hainesr Sep 26, 2019
bb3b447
Fix Style/SpecialGlobalVars cop.
hainesr Sep 26, 2019
0df6cb3
Fix Style/SymbolProc cop.
hainesr Sep 26, 2019
6cab592
Configure and fix Metrics/LineLength cop.
hainesr Sep 26, 2019
0e25e63
Turn off Metrics/BlockLength for the tests.
hainesr Sep 29, 2019
c97d560
Configure Metrics/AbcSize and turn off for the tests.
hainesr Sep 29, 2019
5ce4e13
Configure and fix Style/ClassCheck cop.
hainesr Sep 30, 2019
a9adfa2
Configure Metrics/ClassLength and turn off for the tests.
hainesr Feb 9, 2020
a187ec0
Configure Metrics/MethodLength and turn off for the tests.
hainesr Feb 9, 2020
4b8f740
Fix Layout/EmptyLinesAroundClassBody cop.
hainesr Feb 9, 2020
fae95e3
Fix Style/NumericLiteralPrefix cop.
hainesr Feb 9, 2020
d07b36b
Fix Style/TernaryParentheses cop.
hainesr Feb 9, 2020
989a565
Fix Style/TrailingCommaInHashLiteral cop.
hainesr Feb 9, 2020
c31ab81
Fix Style/NumericLiterals cop.
hainesr Feb 9, 2020
87a63e0
Set TargetRubyVersion to match that in the gemspec.
hainesr Feb 15, 2020
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
Prev Previous commit
Next Next commit
Fix Layout/EmptyLineAfterGuardClause cop.
  • Loading branch information
hainesr committed Feb 15, 2020
commit cfe4972e712b36d351b6fb7eb189d28e59902ef2
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
8000
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 76
# Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand Down
4 changes: 4 additions & 0 deletions lib/zip/central_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def read_from_stream(io) #:nodoc:
def get_e_o_c_d(buf) #:nodoc:
sig_index = buf.rindex([END_OF_CDS].pack('V'))
raise Error, 'Zip end of central directory signature not found' unless sig_index

buf = buf.slice!((sig_index + 4)..(buf.bytesize))

def buf.read(count)
Expand All @@ -166,8 +167,10 @@ def start_buf(io)
def get_64_e_o_c_d(buf) #:nodoc:
zip_64_start = buf.rindex([ZIP64_END_OF_CDS].pack('V'))
raise Error, 'Zip64 end of central directory signature not found' unless zip_64_start

zip_64_locator = buf.rindex([ZIP64_EOCD_LOCATOR].pack('V'))
raise Error, 'Zip64 end of central directory signature locator not found' unless zip_64_locator

buf = buf.slice!((zip_64_start + 4)..zip_64_locator)

def buf.read(count)
Expand Down Expand Up @@ -198,6 +201,7 @@ def self.read_from_stream(io) #:nodoc:

def ==(other) #:nodoc:
return false unless other.kind_of?(CentralDirectory)

@entry_set.entries.sort == other.entries.sort && comment == other.comment
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/zip/crypto/decrypted_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def read(length = nil, outbuf = +'')

while length.nil? || (buffer.bytesize < length)
break if input_finished?

buffer << produce_input
end

Expand Down
14 changes: 14 additions & 0 deletions lib/zip/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def set_default_vars_values

def check_name(name)
return unless name.start_with?('/')

raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
end

Expand Down Expand Up @@ -104,6 +105,7 @@ def time=(value)

def file_type_is?(type)
raise InternalError, "current filetype is unknown: #{inspect}" unless @ftype

@ftype == type
end

Expand All @@ -124,6 +126,7 @@ def name_is_directory? #:nodoc:all
def name_safe?
cleanpath = Pathname.new(@name).cleanpath
return false unless cleanpath.relative?

root = ::File::SEPARATOR
naive_expanded_path = ::File.join(root, cleanpath.to_s)
::File.absolute_path(cleanpath.to_s, root) == naive_expanded_path
Expand Down Expand Up @@ -153,6 +156,7 @@ def calculate_local_header_siz 8000 e #:nodoc:all
# that we didn't change the header size (and thus clobber file data or something)
def verify_local_header_size!
return if @local_header_size.nil?

new_size = calculate_local_header_size
raise Error, "local header size changed (#{@local_header_size} -> #{new_size})" if @local_header_size != new_size
end
Expand Down Expand Up @@ -255,6 +259,7 @@ def read_local_entry(io) #:nodoc:all
unless @header_signature == ::Zip::LOCAL_ENTRY_SIGNATURE
raise ::Zip::Error, "Zip local header magic not found at location '#{local_header_offset}'"
end

set_time(@last_mod_date, @last_mod_time)

@name = io.read(@name_length)
Expand All @@ -274,6 +279,7 @@ def read_local_entry(io) #:nodoc:all
@extra = ::Zip::ExtraField.new(extra)
end
end

parse_zip64_extra(true)
@local_header_size = calculate_local_header_size
end
Expand Down Expand Up @@ -360,16 +366,19 @@ def set_ftype_from_c_dir_entry

def check_c_dir_entry_static_header_length(buf)
return if buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH

raise Error, 'Premature end of file. Not enough data for zip cdir entry header'
end

def check_c_dir_entry_signature
return if header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE

raise Error, "Zip local header magic not found at location '#{local_header_offset}'"
end

def check_c_dir_entry_comment_size
return if @comment && @comment.bytesize == @comment_length

raise ::Zip::Error, 'Truncated cdir zip entry header'
end

Expand Down Expand Up @@ -408,6 +417,7 @@ def file_stat(path) # :nodoc:

def get_extra_attributes_from_path(path) # :nodoc:
return if Zip::RUNNING_ON_WINDOWS

stat = file_stat(path)
@unix_uid = stat.uid
@unix_gid = stat.gid
Expand Down Expand Up @@ -494,6 +504,7 @@ def write_c_dir_entry(io) #:nodoc:all

def ==(other)
return false unless other.class == self.class

# Compares contents of local entry and exposed fields
keys_equal = %w[compression_method crc compressed_size size name extra filepath].all? do |k|
other.__send__(k.to_sym) == __send__(k.to_sym)
Expand Down Expand Up @@ -635,6 +646,7 @@ def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exi

def create_directory(dest_path)
return if ::File.directory?(dest_path)

if ::File.exist?(dest_path)
if block_given? && yield(self, dest_path)
::FileUtils.rm_f dest_path
Expand All @@ -659,6 +671,7 @@ def create_symlink(dest_path)
# (required when file sizes exceed 2**32, but can be used for all files)
def parse_zip64_extra(for_local_header) #:nodoc:all
return if @extra['Zip64'].nil?

if for_loca 8000 l_header
@size, @compressed_size = @extra['Zip64'].parse(@size, @compressed_size)
else
Expand All @@ -673,6 +686,7 @@ def data_descriptor_size
# create a zip64 extra information field if we need one
def prep_zip64_extra(for_local_header) #:nodoc:all
return unless ::Zip.write_zip64_support

need_zip64 = @size >= 0xFFFFFFFF || @compressed_size >= 0xFFFFFFFF
need_zip64 ||= @local_header_offset >= 0xFFFFFFFF unless for_local_header
if need_zip64
Expand Down
2 changes: 2 additions & 0 deletions lib/zip/entry_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def dup

def ==(other)
return false unless other.kind_of?(EntrySet)

@entry_set.values == other.entry_set.values
end

Expand All @@ -60,6 +61,7 @@ def parent(entry)
def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB)
entries.map do |entry|
next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)

yield(entry) if block_given?
entry
end.compact
Expand Down
2 changes: 2 additions & 0 deletions lib/zip/extra_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class << s

def merge(binstr)
return if binstr.empty?

i = 0
while i < binstr.bytesize
id = binstr[i, 2]
Expand All @@ -54,6 +55,7 @@ def create(name)
unless (field_class = ID_MAP.values.find { |k| k.name == name })
raise Error, "Unknown extra field '#{name}'"
end

self[name] = field_class.new
end

Expand Down
2 changes: 2 additions & 0 deletions lib/zip/extra_field/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ def initial_parse(binstr)
warn 'WARNING: weird extra field header ID. Skip parsing it.'
return false
end

[binstr[2, 2].unpack('v')[0], binstr[4..-1]]
end

def ==(other)
return false if self.class != other.class

each do |k, v|
return false if v != other[k]
end
Expand Down
4 changes: 4 additions & 0 deletions lib/zip/extra_field/ntfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(binstr = nil)

def merge(binstr)
return if binstr.empty?

size, content = initial_parse(binstr)
(size && content) || return

Expand All @@ -27,6 +28,7 @@ def merge(binstr)

tag1 = tags[1]
return unless tag1

ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q<Q<Q<')
ntfs_mtime && @mtime ||= from_ntfs_time(ntfs_mtime)
ntfs_atime && @atime ||= from_ntfs_time(ntfs_atime)
Expand Down Expand Up @@ -65,12 +67,14 @@ def pack_for_c_dir

def parse_tags(content)
return {} if content.nil?

tags = {}
i = 0
while i < content.bytesize
tag, size = content[i, 4].unpack('vv')
i += 4
break unless tag && size

value = content[i, size]
i += size
tags[tag] = value
Expand Down
2 changes: 2 additions & 0 deletions lib/zip/extra_field/old_unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ def initialize(binstr = nil)

def merge(binstr)
return if binstr.empty?

size, content = initial_parse(binstr)
# size: 0 for central directory. 4 for local header
return if !size || size == 0

atime, mtime, uid, gid = content.unpack('VVvv')
@uid ||= uid
@gid ||= gid
Expand Down
3 changes: 3 additions & 0 deletions lib/zip/extra_field/universal_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ def merge(binstr)

# Parse the timestamps, in order, based on which flags are set.
return if times[0].nil?

@mtime ||= ::Zip::DOSTime.at(times.shift) unless @flag & MTIME_MASK == 0
return if times[0].nil?

@atime ||= ::Zip::DOSTime.at(times.shift) unless @flag & ATIME_MASK == 0
return if times[0].nil?

@ctime ||= ::Zip::DOSTime.at(times.shift) unless @flag & CTIME_MASK == 0
end

Expand Down
2 changes: 2 additions & 0 deletions lib/zip/extra_field/unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def initialize(binstr = nil)

def merge(binstr)
return if binstr.empty?

size, content = initial_parse(binstr)
# size: 0 for central directory. 4 for local header
return if !size || size == 0

uid, gid = content.unpack('vv')
@uid ||= uid
@gid ||= gid
Expand Down
2 changes: 2 additions & 0 deletions lib/zip/extra_field/zip64.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def ==(other)

def merge(binstr)
return if binstr.empty?

_, @content = initial_parse(binstr)
end

Expand All @@ -52,6 +53,7 @@ def extract(size, format)
def pack_for_local
10000 # local header entries must contain original size and compressed size; other fields do not apply
return '' unless @original_size && @compressed_size

[@original_size, @compressed_size].pack('Q<Q<')
end

Expand Down
7 changes: 7 additions & 0 deletions lib/zip/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class << self
def open(file_name, create = false, options = {})
zf = ::Zip::File.new(file_name, create, false, options)
return zf unless block_given?

begin
yield zf
ensure
Expand Down Expand Up @@ -151,6 +152,7 @@ def open_buffer(io, options = {})

zf = ::Zip::File.new(io, true, true, options)
return zf unless block_given?

yield zf

begin
Expand Down Expand Up @@ -229,9 +231,11 @@ def save_splited_part(zip_file, partial_zip_file_name, zip_file_size, szip_file_
def split(zip_file_name, segment_size = MAX_SEGMENT_SIZE, delete_zip_file = true, partial_zip_file_name = nil)
raise Error, "File #{zip_file_name} not found" unless ::File.exist?(zip_file_name)
raise Errno::ENOENT, zip_file_name unless ::File.readable?(zip_file_name)

zip_file_size = ::File.size(zip_file_name)
segment_size = get_segment_size_for_split(segment_size)
return if zip_file_size <= segment_size

segment_count = get_segment_count_for_split(zip_file_size, segment_size)
# Checking for correct zip structure
::Zip::File.open(zip_file_name) {}
Expand Down Expand Up @@ -337,6 +341,7 @@ def extract(entry, dest_path, &block)
# the zip archive.
def commit
return if name.is_a?(StringIO) || !commit_required?

on_success_replace do |tmp_file|
::Zip::OutputStream.open(tmp_file) do |zos|
@entry_set.each do |e|
Expand Down Expand Up @@ -402,6 +407,7 @@ def get_entry(entry)
# Creates a directory
def mkdir(entryName, permissionInt = 0o755)
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)

entryName = entryName.dup.to_s
entryName << '/' unless entryName.end_with?('/')
@entry_set << ::Zip::StreamableDirectory.new(@name, entryName, nil, permissionInt)
Expand All @@ -424,6 +430,7 @@ def directory?(newEntry, srcPath)
def check_entry_exists(entryName, continue_on_exists_proc, procedureName)
continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
return unless @entry_set.include?(entryName)

if continue_on_exists_proc.call
remove get_entry(entryName)
else
Expand Down
Loading
0