fix rubocop Style/GuardClause cop

This commit is contained in:
Pavel Lobashov 2015-03-24 19:16:03 +03:00
parent 63b3ee3465
commit b920a1eb49
5 changed files with 42 additions and 55 deletions

View File

@ -139,11 +139,6 @@ Style/FileName:
Style/FormatString:
Enabled: false
# Offense count: 10
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
Style/InfiniteLoop:

View File

@ -45,10 +45,9 @@ module Zip
end
def check_name(name)
if name.start_with?('/')
return unless name.start_with?('/')
raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
end
end
def initialize(*args)
name = args[1] || ''
@ -332,22 +331,19 @@ module Zip
end
def check_c_dir_entry_static_header_length(buf)
unless buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH
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
end
def check_c_dir_entry_signature
unless header_signature == ::Zip::CENTRAL_DIRECTORY_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
end
def check_c_dir_entry_comment_size
unless @comment && @comment.bytesize == @comment_length
return if @comment && @comment.bytesize == @comment_length
raise ::Zip::Error, 'Truncated cdir zip entry header'
end
end
def read_c_dir_extra_field(io)
if @extra.is_a?(::Zip::ExtraField)
@ -380,13 +376,12 @@ module Zip
end
def get_extra_attributes_from_path(path) # :nodoc:
unless Zip::RUNNING_ON_WINDOWS
return if Zip::RUNNING_ON_WINDOWS
stat = file_stat(path)
@unix_uid = stat.uid
@unix_gid = stat.gid
@unix_perms = stat.mode & 07777
end
end
def set_unix_permissions_on_path(dest_path)
# BUG: does not update timestamps into account

View File

@ -26,13 +26,12 @@ module Zip
tags = parse_tags(content)
tag1 = tags[1]
if tag1
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)
ntfs_ctime && @ctime ||= from_ntfs_time(ntfs_ctime)
end
end
def ==(other)
@mtime == other.mtime &&

View File

@ -385,7 +385,7 @@ module Zip
def check_entry_exists(entryName, continue_on_exists_proc, procedureName)
continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
if @entry_set.include?(entryName)
return unless @entry_set.include?(entryName)
if continue_on_exists_proc.call
remove get_entry(entryName)
else
@ -393,7 +393,6 @@ module Zip
procedureName + " failed. Entry #{entryName} already exists"
end
end
end
def check_file(path)
raise Errno::ENOENT, path unless ::File.readable?(path)

View File

@ -27,7 +27,7 @@ class ZipFileSplitTest < MiniTest::Test
def test_split
result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false)
unless result.nil?
return if result.nil?
Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index|
File.open(zip_file_name, 'rb') do |zip_file|
zip_file.read([::Zip::File::SPLIT_SIGNATURE].pack('V').size) if index == 0
@ -55,4 +55,3 @@ class ZipFileSplitTest < MiniTest::Test
end
end
end
end