From b9aefaffb5ab0524ac5e8c1e46f99de5eb636338 Mon Sep 17 00:00:00 2001 From: Pavel Lobashov Date: Tue, 24 Mar 2015 19:09:22 +0300 Subject: [PATCH] fix rubocop Style/IfUnlessModifier cop --- .rubocop_rubyzip.yml | 5 ----- lib/zip/entry.rb | 5 +---- lib/zip/extra_field/ntfs.rb | 4 +--- lib/zip/file.rb | 16 ++++------------ lib/zip/filesystem.rb | 8 ++------ lib/zip/ioextras/abstract_input_stream.rb | 4 +--- test/file_test.rb | 8 ++------ 7 files changed, 11 insertions(+), 39 deletions(-) diff --git a/.rubocop_rubyzip.yml b/.rubocop_rubyzip.yml index ccb2f0b3..89f490f7 100644 --- a/.rubocop_rubyzip.yml +++ b/.rubocop_rubyzip.yml @@ -150,11 +150,6 @@ Style/GuardClause: Style/HashSyntax: EnforcedStyle: hash_rockets -# Offense count: 10 -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Enabled: false - # Offense count: 1 # Cop supports --auto-correct. Style/InfiniteLoop: diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 4936ae62..13e22285 100755 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -654,10 +654,7 @@ def data_descriptor_size def prep_zip64_extra(for_local_header) #:nodoc:all return unless ::Zip.write_zip64_support need_zip64 = @size >= 0xFFFFFFFF || @compressed_size >= 0xFFFFFFFF - unless for_local_header - need_zip64 ||= @local_header_offset >= 0xFFFFFFFF - end - + need_zip64 ||= @local_header_offset >= 0xFFFFFFFF unless for_local_header if need_zip64 @version_needed_to_extract = VERSION_NEEDED_TO_EXTRACT_ZIP64 @extra.delete('Zip64Placeholder') diff --git a/lib/zip/extra_field/ntfs.rb b/lib/zip/extra_field/ntfs.rb index 1de6b2b2..ad30813b 100644 --- a/lib/zip/extra_field/ntfs.rb +++ b/lib/zip/extra_field/ntfs.rb @@ -55,9 +55,7 @@ def pack_for_c_dir tag1 << [to_ntfs_time(@mtime)].pack('Q<') if @atime tag1 << [to_ntfs_time(@atime)].pack('Q<') - if @ctime - tag1 << [to_ntfs_time(@ctime)].pack('Q<') - end + tag1 << [to_ntfs_time(@ctime)].pack('Q<') if @ctime end end s << [tag1.bytesize].pack('v') << tag1 diff --git a/lib/zip/file.rb b/lib/zip/file.rb index b9e766b3..14d57f88 100755 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -354,9 +354,7 @@ def glob(*args, &block) # if no entry is found. def get_entry(entry) selected_entry = find_entry(entry) - unless selected_entry - raise Errno::ENOENT, entry - end + raise Errno::ENOENT, entry unless selected_entry selected_entry.restore_ownership = @restore_ownership selected_entry.restore_permissions = @restore_permissions selected_entry.restore_times = @restore_times @@ -365,9 +363,7 @@ def get_entry(entry) # Creates a directory def mkdir(entryName, permissionInt = 0755) - if find_entry(entryName) - raise Errno::EEXIST, "File exists - #{entryName}" - end + 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) @@ -400,9 +396,7 @@ def check_entry_exists(entryName, continue_on_exists_proc, procedureName) end def check_file(path) - unless ::File.readable?(path) - raise Errno::ENOENT, path - end + raise Errno::ENOENT, path unless ::File.readable?(path) end def on_success_replace @@ -412,9 +406,7 @@ def on_success_replace tmpfile.close if yield tmp_filename ::File.rename(tmp_filename, name) - if defined?(@exist_file_perms) - ::File.chmod(@exist_file_perms, name) - end + ::File.chmod(@exist_file_perms, name) if defined?(@exist_file_perms) end ensure tmpfile.unlink if tmpfile diff --git a/lib/zip/filesystem.rb b/lib/zip/filesystem.rb index 3855754b..bbd6fc0d 100755 --- a/lib/zip/filesystem.rb +++ b/lib/zip/filesystem.rb @@ -266,9 +266,7 @@ def size?(fileName) def chown(ownerInt, groupInt, *filenames) filenames.each do |fileName| e = get_entry(fileName) - unless e.extra.member?('IUnix') - e.extra.create('IUnix') - end + e.extra.create('IUnix') unless e.extra.member?('IUnix') e.extra['IUnix'].uid = ownerInt e.extra['IUnix'].gid = groupInt end @@ -387,9 +385,7 @@ def pipe end def stat(fileName) - unless exists?(fileName) - raise Errno::ENOENT, fileName - end + raise Errno::ENOENT, fileName unless exists?(fileName) ZipFsStat.new(self, fileName) end diff --git a/lib/zip/ioextras/abstract_input_stream.rb b/lib/zip/ioextras/abstract_input_stream.rb index 45502473..fdee46a8 100644 --- a/lib/zip/ioextras/abstract_input_stream.rb +++ b/lib/zip/ioextras/abstract_input_stream.rb @@ -75,9 +75,7 @@ def gets(a_sep_string = $/, number_of_bytes = nil) over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes) while (match_index = @output_buffer.index(a_sep_string, buffer_index)).nil? && !over_limit buffer_index = [buffer_index, @output_buffer.bytesize - a_sep_string.bytesize].max - if input_finished? - return @output_buffer.empty? ? nil : flush - end + return @output_buffer.empty? ? nil : flush if input_finished? @output_buffer << produce_input over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes) end diff --git a/test/file_test.rb b/test/file_test.rb index 049fd2be..05e4f7a1 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -199,9 +199,7 @@ def test_rename def test_rename_with_each zf_name = 'test_rename_zip.zip' - if ::File.exist?(zf_name) - ::File.unlink(zf_name) - end + ::File.unlink(zf_name) if ::File.exist?(zf_name) arr = [] arr_renamed = [] ::Zip::File.open(zf_name, ::Zip::File::CREATE) do |zf| @@ -225,9 +223,7 @@ def test_rename_with_each zf = ::Zip::File.open(zf_name) assert_equal(zf.entries.map(&:name), arr_renamed) zf.close - if ::File.exist?(zf_name) - ::File.unlink(zf_name) - end + ::File.unlink(zf_name) if ::File.exist?(zf_name) end def test_rename_to_existing_entry