Fix Style/GuardClause cop.

This commit is contained in:
Robert Haines 2020-02-09 15:50:00 +00:00
parent bce841639e
commit 45f4c2dc29
5 changed files with 28 additions and 44 deletions

View File

@ -163,15 +163,6 @@ Style/FormatStringToken:
Style/FrozenStringLiteralComment:
Enabled: false
# Offense count: 8
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/zip/entry.rb'
- 'lib/zip/extra_field/generic.rb'
- 'samples/zipfind.rb'
- 'test/test_helper.rb'
# Offense count: 17
# Cop supports --auto-correct.
Style/IfUnlessModifier:

View File

@ -182,12 +182,9 @@ module Zip
dest_path ||= @name
block ||= proc { ::Zip.on_exists_proc }
if directory? || file? || symlink?
__send__("create_#{@ftype}", dest_path, &block)
else
raise "unknown file type #{inspect}"
end
raise "unknown file type #{inspect}" unless directory? || file? || symlink?
__send__("create_#{@ftype}", dest_path, &block)
self
end
@ -630,12 +627,10 @@ module Zip
bytes_written += buf.bytesize
if bytes_written > size && !warned
message = "entry '#{name}' should be #{size}B, but is larger when inflated."
if ::Zip.validate_entry_sizes
raise ::Zip::EntrySizeError, message
else
warn "WARNING: #{message}"
warned = true
end
raise ::Zip::EntrySizeError, message if ::Zip.validate_entry_sizes
warn "WARNING: #{message}"
warned = true
end
end
end

View File

@ -1,9 +1,9 @@
module Zip
class ExtraField::Generic
def self.register_map
if const_defined?(:HEADER_ID)
::Zip::ExtraField::ID_MAP[const_get(:HEADER_ID)] = self
end
return unless const_defined?(:HEADER_ID)
::Zip::ExtraField::ID_MAP[const_get(:HEADER_ID)] = self
end
def self.name
@ -12,10 +12,9 @@ module Zip
# return field [size, content] or false
def initial_parse(binstr)
if !binstr
# If nil, start with empty.
return false
elsif binstr[0, 2] != self.class.const_get(:HEADER_ID)
return false unless binstr
if binstr[0, 2] != self.class.const_get(:HEADER_ID)
warn 'WARNING: weird extra field header ID. Skip parsing it.'
return false
end

View File

@ -48,10 +48,10 @@ if $0 == __FILE__
end
def self.check_args(args)
if args.size != 3
usage
exit
end
return if args.size == 3
usage
exit
end
def self.usage

View File

@ -42,11 +42,10 @@ module IOizeString
else
raise 'Error in test method IOizeString::seek'
end
if newPos < 0 || newPos >= size
raise Errno::EINVAL
else
@tell = newPos
end
raise Errno::EINVAL if newPos < 0 || newPos >= size
@tell = newPos
end
def reset
@ -107,14 +106,14 @@ module AssertEntry
def self.assert_contents(filename, aString)
fileContents = ''
File.open(filename, 'rb') { |f| fileContents = f.read }
if fileContents != aString
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}'")
else
assert_equal(fileContents, aString)
end
return unless fileContents != aString
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}'")
else
assert_equal(fileContents, aString)
end
end