fix rubocop Style/SpaceAroundOperators cop

This commit is contained in:
Pavel.Lobashov 2015-03-22 20:03:50 +03:00
parent 5ea5710b18
commit 8d6f23ba9a
21 changed files with 53 additions and 58 deletions

View File

@ -267,11 +267,6 @@ Style/Semicolon:
Style/SignalException:
Enabled: false
# Offense count: 53
# Cop supports --auto-correct.
Style/SpaceAroundOperators:
Enabled: false
# Offense count: 30
# Cop supports --auto-correct.
Style/SpecialGlobalVars:

View File

@ -6,7 +6,7 @@ module Zip
LOCAL_ENTRY_SIGNATURE = 0x04034b50
LOCAL_ENTRY_STATIC_HEADER_LENGTH = 30
LOCAL_ENTRY_TRAILING_DESCRIPTOR_LENGTH = 4+4+4
LOCAL_ENTRY_TRAILING_DESCRIPTOR_LENGTH = 4 + 4 + 4
VERSION_MADE_BY = 52 # this library's version
VERSION_NEEDED_TO_EXTRACT = 20
VERSION_NEEDED_TO_EXTRACT_ZIP64 = 45

View File

@ -3,7 +3,7 @@ module Zip
CHUNK_SIZE = 32768
def initialize(input_stream)
super()
@input_stream=input_stream
@input_stream = input_stream
end
end
end

View File

@ -13,7 +13,7 @@ module Zip
# bits 9-15 year (four digit year minus 1980)
def to_binary_dos_time
(sec/2) +
(sec / 2) +
(min << 5) +
(hour << 11)
end
@ -26,7 +26,7 @@ module Zip
# Dos time is only stored with two seconds accuracy
def dos_equals(other)
to_i/2 == other.to_i/2
to_i / 2 == other.to_i / 2
end
def self.parse_binary_dos_format(binaryDosDate, binaryDosTime)

View File

@ -514,7 +514,7 @@ module Zip
when 'file'
if name_is_directory?
raise ArgumentError,
"entry name '#{newEntry}' indicates directory entry, but "+
"entry name '#{newEntry}' indicates directory entry, but " +
"'#{src_path}' is not a directory"
end
:file
@ -524,7 +524,7 @@ module Zip
when 'link'
if name_is_directory?
raise ArgumentError,
"entry name '#{newEntry}' indicates directory entry, but "+
"entry name '#{newEntry}' indicates directory entry, but " +
"'#{src_path}' is not a directory"
end
:symlink
@ -550,7 +550,7 @@ module Zip
def parent_as_string
entry_name = name.chomp('/')
slash_index = entry_name.rindex('/')
slash_index ? entry_name.slice(0, slash_index+1) : nil
slash_index ? entry_name.slice(0, slash_index + 1) : nil
end
def get_raw_input_stream(&block)
@ -597,7 +597,7 @@ module Zip
::FileUtils.rm_f dest_path
else
raise ::Zip::DestinationFileExistsError,
"Cannot create directory '#{dest_path}'. "+
"Cannot create directory '#{dest_path}'. " +
'A file already exists with that name'
end
end
@ -622,12 +622,12 @@ module Zip
return
else
raise ::Zip::DestinationFileExistsError,
"Cannot create symlink '#{dest_path}'. "+
"Cannot create symlink '#{dest_path}'. " +
'A symlink already exists with that name'
end
else
raise ::Zip::DestinationFileExistsError,
"Cannot create symlink '#{dest_path}'. "+
"Cannot create symlink '#{dest_path}'. " +
'A file already exists with that name'
end
end

View File

@ -61,7 +61,7 @@ module Zip
@entry_set[to_key(entry.parent_as_string)]
end
def glob(pattern, flags = ::File::FNM_PATHNAME|::File::FNM_DOTMATCH)
def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH)
entries.map do |entry|
next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
yield(entry) if block_given?

View File

@ -180,7 +180,7 @@ module Zip
def save_splited_part(zip_file, partial_zip_file_name, zip_file_size, szip_file_index, segment_size, segment_count)
ssegment_size = zip_file_size - zip_file.pos
ssegment_size = segment_size if ssegment_size > segment_size
szip_file_name = "#{partial_zip_file_name}.#{'%03d'%(szip_file_index)}"
szip_file_name = "#{partial_zip_file_name}.#{'%03d' % (szip_file_index)}"
::File.open(szip_file_name, 'wb') do |szip_file|
if szip_file_index == 1
ssegment_size = put_split_signature(szip_file, segment_size)
@ -379,7 +379,7 @@ module Zip
srcPathIsDirectory = ::File.directory?(srcPath)
if newEntry.is_directory && !srcPathIsDirectory
raise ArgumentError,
"entry name '#{newEntry}' indicates directory entry, but "+
"entry name '#{newEntry}' indicates directory entry, but " +
"'#{srcPath}' is not a directory"
elsif !newEntry.is_directory && srcPathIsDirectory
newEntry.name += '/'

View File

@ -534,7 +534,7 @@ module Zip
def read
raise IOError, 'closed directory' if @fileNames == nil
@fileNames[(@index+=1)-1]
@fileNames[(@index += 1) - 1]
end
def rewind
@ -602,7 +602,7 @@ module Zip
# and removes trailing slash on directories
def each
@zipFile.each do |e|
yield('/'+e.to_s.chomp('/'))
yield('/' + e.to_s.chomp('/'))
end
end

View File

@ -72,7 +72,7 @@ puts "Zip file splitted in #{part_zips_count} parts"
# Track splitting an archive
Zip::File.split('large_zip_file.zip', 1048576, true, 'part_zip_file') do
|part_count, part_index, chunk_bytes, segment_bytes|
puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f/segment_bytes.to_f * 100).to_i}%"
puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f / segment_bytes.to_f * 100).to_i}%"
end
# For other examples, look at zip.rb and ziptest.rb

View File

@ -37,7 +37,7 @@ class ZipFileGenerator
puts 'Deflating ' + diskFilePath
if File.directory?(diskFilePath)
io.mkdir(zipFilePath)
subdir =Dir.entries(diskFilePath); subdir.delete('.'); subdir.delete('..')
subdir = Dir.entries(diskFilePath); subdir.delete('.'); subdir.delete('..')
writeEntries(subdir, zipFilePath, io)
else
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, 'rb').read()) }

View File

@ -72,7 +72,7 @@ class MainApp < Gtk::Window
@zipfile.each do |entry|
@clist.append([entry.name,
entry.size.to_s,
(100.0*entry.compressedSize/entry.size).to_s+'%'])
(100.0 * entry.compressedSize / entry.size).to_s + '%'])
end
end
end

View File

@ -1,6 +1,6 @@
#!/usr/bin/env ruby
$VERBOSE=true
$VERBOSE = true
$: << '../lib'

View File

@ -5,7 +5,7 @@ class BasicZipFileTest < MiniTest::Test
def setup
@zip_file = ::Zip::File.new(TestZipFile::TEST_ZIP2.zip_name)
@testEntryNameIndex=0
@testEntryNameIndex = 0
end
def test_entries

View File

@ -58,7 +58,7 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test
end
def test_ReadEntryFromTruncatedZipFile
fragment=''
fragment = ''
File.open('test/data/testDirectory.bin') { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
fragment.extend(IOizeString)
entry = ::Zip::Entry.new

View File

@ -27,7 +27,7 @@ class ZipCentralDirectoryTest < MiniTest::Test
end
def test_ReadFromTruncatedZipFile
fragment=''
fragment = ''
File.open('test/data/testDirectory.bin', 'rb') { |f| fragment = f.read }
fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete
fragment.extend(IOizeString)

View File

@ -154,7 +154,7 @@ class ZipEntryTest < MiniTest::Test
end
zipfile.close
f= File.open('/tmp/no_compress.zip', 'rb')
f = File.open('/tmp/no_compress.zip', 'rb')
first_100_bytes = f.read(100)
f.close

View File

@ -47,20 +47,20 @@ class ZipFileTest < MiniTest::Test
zf.get_output_stream('newEntry.txt') do |os|
os.write 'Putting stuff in newEntry.txt'
end
assert_equal(entryCount+1, zf.size)
assert_equal(entryCount + 1, zf.size)
assert_equal('Putting stuff in newEntry.txt', zf.read('newEntry.txt'))
zf.get_output_stream(zf.get_entry('test/data/generated/empty.txt')) do |os|
os.write 'Putting stuff in data/generated/empty.txt'
end
assert_equal(entryCount+1, zf.size)
assert_equal(entryCount + 1, zf.size)
assert_equal('Putting stuff in data/generated/empty.txt', zf.read('test/data/generated/empty.txt'))
custom_entry_args = [ZipEntryTest::TEST_COMMENT, ZipEntryTest::TEST_EXTRA, ZipEntryTest::TEST_COMPRESSED_SIZE, ZipEntryTest::TEST_CRC, ::Zip::Entry::STORED, ZipEntryTest::TEST_SIZE, ZipEntryTest::TEST_TIME]
zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) do |os|
os.write 'Some data'
end
assert_equal(entryCount+2, zf.size)
assert_equal(entryCount + 2, zf.size)
entry = zf.get_entry('entry_with_custom_args.txt')
assert_equal(custom_entry_args[0], entry.comment)
assert_equal(custom_entry_args[2], entry.compressed_size)
@ -75,7 +75,7 @@ class ZipFileTest < MiniTest::Test
end
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
assert_equal(entryCount+3, zf.size)
assert_equal(entryCount + 3, zf.size)
assert_equal('Putting stuff in newEntry.txt', zf.read('newEntry.txt'))
assert_equal('Putting stuff in data/generated/empty.txt', zf.read('test/data/generated/empty.txt'))
assert_equal(File.open('test/data/generated/5entry.zip', 'rb').read, zf.read('entry.bin'))
@ -151,7 +151,7 @@ class ZipFileTest < MiniTest::Test
zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR)
end
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
dirEntry = zf.entries.detect { |e| e.name == TestFiles::EMPTY_TEST_DIR+'/' }
dirEntry = zf.entries.detect { |e| e.name == TestFiles::EMPTY_TEST_DIR + '/' }
assert(dirEntry.directory?)
end
end

View File

@ -21,11 +21,11 @@ class TestFiles
Dir.mkdir 'test/data/generated' unless Dir.exist?('test/data/generated')
ASCII_TEST_FILES.each_with_index do |filename, index|
create_random_ascii(filename, 1E4 * (index+1))
create_random_ascii(filename, 1E4 * (index + 1))
end
BINARY_TEST_FILES.each_with_index do |filename, index|
create_random_binary(filename, 1E4 * (index+1))
create_random_binary(filename, 1E4 * (index + 1))
end
ensure_dir(EMPTY_TEST_DIR)
@ -61,8 +61,8 @@ class TestZipFile
attr_accessor :zip_name, :entry_names, :comment
def initialize(zip_name, entry_names, comment = '')
@zip_name=zip_name
@entry_names=entry_names
@zip_name = zip_name
@entry_names = entry_names
@comment = comment
end
@ -75,14 +75,14 @@ class TestZipFile
::File.chmod(0640, 'test/data/generated/empty_chmod640.txt')
File.open('test/data/generated/short.txt', 'w') { |file| file << 'ABCDEF' }
ziptestTxt=''
File.open('test/data/file2.txt') { |file| ziptestTxt=file.read }
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
end
testBinaryPattern=''
File.open('test/data/generated/empty.zip') { |file| testBinaryPattern=file.read }
testBinaryPattern = ''
File.open('test/data/generated/empty.zip') { |file| testBinaryPattern = file.read }
testBinaryPattern *= 4
File.open('test/data/generated/longBinary.bin', 'wb') do |file|

View File

@ -18,8 +18,8 @@ class AbstractInputStreamTest < MiniTest::Test
end
def sysread(charsToRead, _buf = nil)
retVal=@contents[@readPointer, charsToRead]
@readPointer+=charsToRead
retVal = @contents[@readPointer, charsToRead]
@readPointer += charsToRead
retVal
end
@ -54,8 +54,8 @@ class AbstractInputStreamTest < MiniTest::Test
end
LONG_LINES = [
'x'*48 + "\r\n",
'y'*49 + "\r\n",
'x' * 48 + "\r\n",
'y' * 49 + "\r\n",
'rest'
]
@ -69,7 +69,7 @@ class AbstractInputStreamTest < MiniTest::Test
def test_getsWithSepAndIndex
io = TestAbstractInputStream.new(LONG_LINES.join)
assert_equal('x', io.gets("\r\n", 1))
assert_equal('x'*47 + "\r", io.gets("\r\n", 48))
assert_equal('x' * 47 + "\r", io.gets("\r\n", 48))
assert_equal("\n", io.gets(nil, 1))
assert_equal('yy', io.gets(nil, 2))
end
@ -80,10 +80,10 @@ class AbstractInputStreamTest < MiniTest::Test
end
def test_each_line
lineNumber=0
lineNumber = 0
@io.each_line do |line|
assert_equal(TEST_LINES[lineNumber], line)
lineNumber+=1
lineNumber += 1
end
end

View File

@ -43,7 +43,7 @@ class ZipLocalEntryTest < MiniTest::Test
end
def test_read_local_entryFromTruncatedZipFile
zipFragment=''
zipFragment = ''
::File.open(TestZipFile::TEST_ZIP2.zip_name) { |f| zipFragment = f.read(12) } # local header is at least 30 bytes
zipFragment.extend(IOizeString).reset
entry = ::Zip::Entry.new

View File

@ -39,7 +39,7 @@ module IOizeString
if newPos < 0 || newPos >= size
raise Errno::EINVAL
else
@tell=newPos
@tell = newPos
end
end
@ -80,7 +80,7 @@ module DecompressorTests
assert(!@decompressor.input_finished?)
buf = @decompressor.produce_input
assert_equal(@refText[100...(100+buf.length)], buf)
assert_equal(@refText[100...(100 + buf.length)], buf)
end
end
@ -100,7 +100,7 @@ module AssertEntry
actual = zis.read
if (expected != actual)
if (expected && actual) && (expected.length > 400 || actual.length > 400)
zipEntryFilename=entryName+'.zipEntry'
zipEntryFilename = entryName + '.zipEntry'
File.open(zipEntryFilename, 'wb') { |entryfile| entryfile << actual }
fail("File '#{filename}' is different from '#{zipEntryFilename}'")
else