From 06e5a9352dcffd07ae3d582ba95b17d4bc1be2df Mon Sep 17 00:00:00 2001 From: "Pavel.Lobashov" Date: Sun, 22 Mar 2015 19:25:35 +0300 Subject: [PATCH] fix rubocop Style/ParenthesesAroundCondition cop --- .rubocop_rubyzip.yml | 6 ------ lib/zip/entry.rb | 2 +- lib/zip/extra_field/old_unix.rb | 2 +- lib/zip/extra_field/unix.rb | 2 +- lib/zip/inflater.rb | 2 +- lib/zip/streamable_directory.rb | 4 ++-- samples/qtzip.rb | 4 ++-- test/gentestfiles.rb | 8 ++++---- test/test_helper.rb | 6 +++--- 9 files changed, 15 insertions(+), 21 deletions(-) diff --git a/.rubocop_rubyzip.yml b/.rubocop_rubyzip.yml index 1e601ad..0ea8d3d 100644 --- a/.rubocop_rubyzip.yml +++ b/.rubocop_rubyzip.yml @@ -239,12 +239,6 @@ Style/Not: Style/NumericLiterals: MinDigits: 12 -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: AllowSafeAssignment. -Style/ParenthesesAroundCondition: - Enabled: false - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 601eee1..9ef5ac6 100755 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -399,7 +399,7 @@ module Zip end def set_extra_attributes_on_path(dest_path) # :nodoc: - return unless (file? || directory?) + return unless file? || directory? case @fstype when ::Zip::FSTYPE_UNIX diff --git a/lib/zip/extra_field/old_unix.rb b/lib/zip/extra_field/old_unix.rb index 3b988d4..b3dbe5c 100644 --- a/lib/zip/extra_field/old_unix.rb +++ b/lib/zip/extra_field/old_unix.rb @@ -18,7 +18,7 @@ module Zip return if binstr.empty? size, content = initial_parse(binstr) # size: 0 for central directory. 4 for local header - return if (!size || size == 0) + return if !size || size == 0 atime, mtime, uid, gid = content.unpack('VVvv') @uid ||= uid @gid ||= gid diff --git a/lib/zip/extra_field/unix.rb b/lib/zip/extra_field/unix.rb index 9111f60..7e44a0e 100644 --- a/lib/zip/extra_field/unix.rb +++ b/lib/zip/extra_field/unix.rb @@ -16,7 +16,7 @@ module Zip return if binstr.empty? size, content = initial_parse(binstr) # size: 0 for central directory. 4 for local header - return if (!size || size == 0) + return if !size || size == 0 uid, gid = content.unpack('vv') @uid ||= uid @gid ||= gid diff --git a/lib/zip/inflater.rb b/lib/zip/inflater.rb index e1cbeb2..0e2b97e 100755 --- a/lib/zip/inflater.rb +++ b/lib/zip/inflater.rb @@ -20,7 +20,7 @@ module Zip end def produce_input - if (@output_buffer.empty?) + if @output_buffer.empty? internal_produce_input else @output_buffer.slice!(0...(@output_buffer.length)) diff --git a/lib/zip/streamable_directory.rb b/lib/zip/streamable_directory.rb index 1b8e345..4560663 100755 --- a/lib/zip/streamable_directory.rb +++ b/lib/zip/streamable_directory.rb @@ -4,8 +4,8 @@ module Zip super(zipfile, entry) @ftype = :directory - entry.get_extra_attributes_from_path(srcPath) if (srcPath) - @unix_perms = permissionInt if (permissionInt) + entry.get_extra_attributes_from_path(srcPath) if srcPath + @unix_perms = permissionInt if permissionInt end end end diff --git a/samples/qtzip.rb b/samples/qtzip.rb index b1f4359..27c4ab5 100755 --- a/samples/qtzip.rb +++ b/samples/qtzip.rb @@ -55,7 +55,7 @@ class ZipDialog < ZipDialogUI selected_items = [] unselected_items = [] lv_item = entry_list_view.first_child - while (lv_item) + while lv_item if entry_list_view.is_selected(lv_item) selected_items << lv_item.text(0) else @@ -69,7 +69,7 @@ class ZipDialog < ZipDialogUI puts "items.size = #{items.size}" d = Qt::FileDialog.get_existing_directory(nil, self) - if (!d) + if !d puts 'No directory chosen' else zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } } diff --git a/test/gentestfiles.rb b/test/gentestfiles.rb index c06b67b..0f5c81f 100755 --- a/test/gentestfiles.rb +++ b/test/gentestfiles.rb @@ -35,13 +35,13 @@ class TestFiles def create_random_ascii(filename, size) File.open(filename, 'wb') do |file| - file << rand while (file.tell < size) + file << rand while file.tell < size end end def create_random_binary(filename, size) File.open(filename, 'wb') do |file| - file << [rand].pack('V') while (file.tell < size) + file << [rand].pack('V') while file.tell < size end end @@ -78,7 +78,7 @@ class TestZipFile ziptestTxt='' File.open('test/data/file2.txt') { |file| ziptestTxt=file.read } File.open('test/data/generated/longAscii.txt', 'w') do |file| - file << ziptestTxt while (file.tell < 1E5) + file << ziptestTxt while file.tell < 1E5 end testBinaryPattern='' @@ -86,7 +86,7 @@ class TestZipFile testBinaryPattern *= 4 File.open('test/data/generated/longBinary.bin', 'wb') do |file| - file << testBinaryPattern << rand << "\0" while (file.tell < 6E5) + file << testBinaryPattern << rand << "\0" while file.tell < 6E5 end raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}") diff --git a/test/test_helper.rb b/test/test_helper.rb index 57c478a..c80e2b4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -36,7 +36,7 @@ module IOizeString else raise 'Error in test method IOizeString::seek' end - if (newPos < 0 || newPos >= size) + if newPos < 0 || newPos >= size raise Errno::EINVAL else @tell=newPos @@ -99,7 +99,7 @@ module AssertEntry expected = file.read actual = zis.read if (expected != actual) - if ((expected && actual) && (expected.length > 400 || actual.length > 400)) + if (expected && actual) && (expected.length > 400 || actual.length > 400) zipEntryFilename=entryName+'.zipEntry' File.open(zipEntryFilename, 'wb') { |entryfile| entryfile << actual } fail("File '#{filename}' is different from '#{zipEntryFilename}'") @@ -114,7 +114,7 @@ module AssertEntry fileContents = '' File.open(filename, 'rb') { |f| fileContents = f.read } if (fileContents != aString) - if (fileContents.length > 400 || aString.length > 400) + if fileContents.length > 400 || aString.length > 400 stringFile = filename + '.other' File.open(stringFile, 'wb') { |f| f << aString } fail("File '#{filename}' is different from contents of string stored in '#{stringFile}'")