From b920a1eb49542531f7e37fd47480ed948d58c038 Mon Sep 17 00:00:00 2001 From: Pavel Lobashov Date: Tue, 24 Mar 2015 19:16:03 +0300 Subject: [PATCH] fix rubocop Style/GuardClause cop --- .rubocop_rubyzip.yml | 5 ----- lib/zip/entry.rb | 31 +++++++++++++------------------ lib/zip/extra_field/ntfs.rb | 11 +++++------ lib/zip/file.rb | 13 ++++++------- test/file_split_test.rb | 37 ++++++++++++++++++------------------- 5 files changed, 42 insertions(+), 55 deletions(-) diff --git a/.rubocop_rubyzip.yml b/.rubocop_rubyzip.yml index ad495ea..33fa619 100644 --- a/.rubocop_rubyzip.yml +++ b/.rubocop_rubyzip.yml @@ -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: diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 13e2228..cd4bc5d 100755 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -45,9 +45,8 @@ module Zip end def check_name(name) - if name.start_with?('/') - raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /" - end + return unless name.start_with?('/') + raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /" end def initialize(*args) @@ -332,21 +331,18 @@ module Zip end def check_c_dir_entry_static_header_length(buf) - unless buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH - raise Error, 'Premature end of file. Not enough data for zip cdir entry header' - end + 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 - unless header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE - raise Error, "Zip local header magic not found at location '#{local_header_offset}'" - end + 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 - unless @comment && @comment.bytesize == @comment_length - raise ::Zip::Error, 'Truncated cdir zip entry header' - end + return if @comment && @comment.bytesize == @comment_length + raise ::Zip::Error, 'Truncated cdir zip entry header' end def read_c_dir_extra_field(io) @@ -380,12 +376,11 @@ module Zip end def get_extra_attributes_from_path(path) # :nodoc: - unless Zip::RUNNING_ON_WINDOWS - stat = file_stat(path) - @unix_uid = stat.uid - @unix_gid = stat.gid - @unix_perms = stat.mode & 07777 - end + return if Zip::RUNNING_ON_WINDOWS + stat = file_stat(path) + @unix_uid = stat.uid + @unix_gid = stat.gid + @unix_perms = stat.mode & 07777 end def set_unix_permissions_on_path(dest_path) diff --git a/lib/zip/extra_field/ntfs.rb b/lib/zip/extra_field/ntfs.rb index ad30813..687704d 100644 --- a/lib/zip/extra_field/ntfs.rb +++ b/lib/zip/extra_field/ntfs.rb @@ -26,12 +26,11 @@ module Zip tags = parse_tags(content) tag1 = tags[1] - if tag1 - ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q