Skip to content

Commit

Permalink
Configure and fix Style/ClassCheck cop.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Sep 30, 2019
1 parent 2338a1a commit 48de62a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 0 additions & 14 deletions .rubocop_rubyzip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,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: 24
Style/Documentation:
Enabled: false
Expand Down
6 changes: 3 additions & 3 deletions lib/zip/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def initialize(*args)
@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 time
Expand Down Expand Up @@ -263,7 +263,7 @@ def read_local_entry(io) #:nodoc:all
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)
Expand Down Expand Up @@ -372,7 +372,7 @@ def check_c_dir_entry_comment_size
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))
Expand Down
6 changes: 3 additions & 3 deletions lib/zip/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ def add_buffer
# (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)
Expand Down Expand Up @@ -334,7 +334,7 @@ def extract(entry, dest_path, &block)
# 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|
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/input_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_io(io_or_file, offset = 0)

def open_entry
@current_entry = ::Zip::Entry.read_local_entry(@archive_io)
if @current_entry && @current_entry.gp_flags & 1 == 1 && @decrypter.is_a?(NullEncrypter)
if @current_entry && @current_entry.gp_flags & 1 == 1 && @decrypter.kind_of?(NullEncrypter)
raise Error, 'password required to decode zip file'
end

Expand Down
4 changes: 2 additions & 2 deletions lib/zip/output_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def put_next_entry(entry_name, comment = nil, extra = nil, compression_method =
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)
Expand All @@ -108,7 +108,7 @@ def put_next_entry(entry_name, comment = nil, extra = nil, compression_method =
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
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/streamable_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Zip
class StreamableStream < DelegateClass(Entry) #:nodoc:all
def initialize(entry)
super(entry)
dirname = if zipfile.is_a?(::String)
dirname = if zipfile.kind_of?(::String)
::File.dirname(zipfile)
end
@temp_file = Tempfile.new(::File.basename(name), dirname)
Expand Down
2 changes: 1 addition & 1 deletion test/filesystem/file_nonmutating_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def test_glob
'*/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
Expand Down

0 comments on commit 48de62a

Please sign in to comment.