Skip to content

Commit

Permalink
fix rubocop Style/IfUnlessModifier cop
Browse files Browse the repository at this point in the history
  • Loading branch information
ShockwaveNN committed Mar 24, 2015
1 parent 2c8f6f8 commit b9aefaf
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 39 deletions.
5 changes: 0 additions & 5 deletions .rubocop_rubyzip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions lib/zip/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 1 addition & 3 deletions lib/zip/extra_field/ntfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions lib/zip/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions lib/zip/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions lib/zip/ioextras/abstract_input_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions test/file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down

0 comments on commit b9aefaf

Please sign in to comment.