Configure and fix Style/ClassCheck cop.

This commit is contained in:
Robert Haines 2019-09-30 19:32:25 +01:00
parent c97d560b69
commit 5ce4e13ddd
7 changed files with 14 additions and 24 deletions

View File

@ -41,6 +41,10 @@ Naming/MemoizedInstanceVariableName:
- 'lib/zip/extra_field/old_unix.rb'
- 'lib/zip/extra_field/unix.rb'
# Set a consistent way of checking types.
Style/ClassCheck:
EnforcedStyle: kind_of?
# Allow this multi-line block chain as it actually reads better
# than the alternatives.
Style/MultilineBlockChain:

View File

@ -96,20 +96,6 @@ Style/ClassAndModuleChildren:
- 'lib/zip/extra_field/zip64.rb'
- 'lib/zip/extra_field/zip64_placeholder.rb'
# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: is_a?, kind_of?
Style/ClassCheck:
Exclude:
- 'lib/zip/central_directory.rb'
- 'lib/zip/entry_set.rb'
- 'lib/zip/file.rb'
- 'lib/zip/output_stream.rb'
- 'test/filesystem/file_nonmutating_test.rb'
- 'test/ioextras/fake_io_test.rb'
- 'test/output_stream_test.rb'
# Offense count: 26
Style/Documentation:
Enabled: false

View File

@ -70,7 +70,7 @@ module Zip
@time = args[8] || ::Zip::DOSTime.now
@ftype = name_is_directory? ? :directory : :file
@extra = ::Zip::ExtraField.new(@extra.to_s) unless @extra.is_a?(::Zip::ExtraField)
@extra = ::Zip::ExtraField.new(@extra.to_s) unless @extra.kind_of?(::Zip::ExtraField)
end
def encrypted?
@ -271,7 +271,7 @@ module Zip
raise ::Zip::Error, 'Truncated local zip entry header'
end
if @extra.is_a?(::Zip::ExtraField)
if @extra.kind_of?(::Zip::ExtraField)
@extra.merge(extra) if extra
else
@extra = ::Zip::ExtraField.new(extra)
@ -380,7 +380,7 @@ module Zip
end
def read_c_dir_extra_field(io)
if @extra.is_a?(::Zip::ExtraField)
if @extra.kind_of?(::Zip::ExtraField)
@extra.merge(io.read(@extra_length))
else
@extra = ::Zip::ExtraField.new(io.read(@extra_length))

View File

@ -141,11 +141,11 @@ module Zip
# (This can be used to extract data from a
# downloaded zip archive without first saving it to disk.)
def open_buffer(io, options = {})
unless IO_METHODS.map { |method| io.respond_to?(method) }.all? || io.is_a?(String)
unless IO_METHODS.map { |method| io.respond_to?(method) }.all? || io.kind_of?(String)
raise "Zip::File.open_buffer expects a String or IO-like argument (responds to #{IO_METHODS.join(', ')}). Found: #{io.class}"
end
io = ::StringIO.new(io) if io.is_a?(::String)
io = ::StringIO.new(io) if io.kind_of?(::String)
# https://github.com/rubyzip/rubyzip/issues/119
io.binmode if io.respond_to?(:binmode)
@ -344,7 +344,7 @@ module Zip
# Commits changes that has been made since the previous commit to
# the zip archive.
def commit
return if name.is_a?(StringIO) || !commit_required?
return if name.kind_of?(StringIO) || !commit_required?
on_success_replace do |tmp_file|
::Zip::OutputStream.open(tmp_file) do |zos|

View File

@ -122,7 +122,7 @@ module Zip
def open_entry
@current_entry = ::Zip::Entry.read_local_entry(@archive_io)
if @current_entry && @current_entry.encrypted? && @decrypter.is_a?(NullEncrypter)
if @current_entry && @current_entry.encrypted? && @decrypter.kind_of?(NullEncrypter)
raise Error, 'password required to decode zip file'
end

View File

@ -98,7 +98,7 @@ module Zip
end
new_entry.comment = comment unless comment.nil?
unless extra.nil?
new_entry.extra = extra.is_a?(ExtraField) ? extra : ExtraField.new(extra.to_s)
new_entry.extra = extra.kind_of?(ExtraField) ? extra : ExtraField.new(extra.to_s)
end
new_entry.compression_method = compression_method unless compression_method.nil?
init_next_entry(new_entry, level)
@ -108,7 +108,7 @@ module Zip
def copy_raw_entry(entry)
entry = entry.dup
raise Error, 'zip stream is closed' if @closed
raise Error, 'entry is not a ZipEntry' unless entry.is_a?(Entry)
raise Error, 'entry is not a ZipEntry' unless entry.kind_of?(Entry)
finalize_current_entry
@entry_set << entry

View File

@ -441,7 +441,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
'*/foo/**/*.txt' => ['globTest/foo/bar/baz/foo.txt']
}.each do |spec, expected_results|
results = zf.glob(spec)
assert(results.all? { |entry| entry.is_a? ::Zip::Entry })
assert(results.all? { |entry| entry.kind_of? ::Zip::Entry })
result_strings = results.map(&:to_s)
missing_matches = expected_results - result_strings