Skip to content

Commit

Permalink
Fix Naming/BlockParameterName cop.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Feb 17, 2020
1 parent 8d91d00 commit 846e704
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 51 deletions.
13 changes: 0 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ Naming/AccessorMethodName:
- 'lib/zip/streamable_stream.rb'
- 'test/file_permissions_test.rb'

# Offense count: 18
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
Naming/BlockParameterName:
Exclude:
- 'lib/zip/file.rb'
- 'lib/zip/filesystem.rb'
- 'samples/zipfind.rb'
- 'test/central_directory_test.rb'
- 'test/file_extract_directory_test.rb'
- 'test/file_extract_test.rb'
- 'test/output_stream_test.rb'
- 'test/test_helper.rb'

# Offense count: 140
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at, ip, db, os
Expand Down
4 changes: 2 additions & 2 deletions lib/zip/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def open_buffer(io, options = {})
# local entry headers (which contain the same information as the
# central directory).
def foreach(aZipFileName, &block)
::Zip::File.open(aZipFileName) do |zipFile|
zipFile.each(&block)
::Zip::File.open(aZipFileName) do |zip_file|
zip_file.each(&block)
end
end

Expand Down
24 changes: 12 additions & 12 deletions lib/zip/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def size?(fileName)
end

def chown(ownerInt, groupInt, *filenames)
filenames.each do |fileName|
e = get_entry(fileName)
filenames.each do |filename|
e = get_entry(filename)
e.extra.create('IUnix') unless e.extra.member?('IUnix')
e.extra['IUnix'].uid = ownerInt
e.extra['IUnix'].gid = groupInt
Expand All @@ -275,8 +275,8 @@ def chown(ownerInt, groupInt, *filenames)
end

def chmod(modeInt, *filenames)
filenames.each do |fileName|
e = get_entry(fileName)
filenames.each do |filename|
e = get_entry(filename)
e.fstype = 3 # force convertion filesystem type to unix
e.unix_perms = modeInt
e.external_file_attributes = modeInt << 16
Expand Down Expand Up @@ -314,8 +314,8 @@ def join(*fragments)
end

def utime(modifiedTime, *fileNames)
fileNames.each do |fileName|
get_entry(fileName).time = modifiedTime
fileNames.each do |filename|
get_entry(filename).time = modifiedTime
end
end

Expand Down Expand Up @@ -406,12 +406,12 @@ def foreach(fileName, aSep = $INPUT_RECORD_SEPARATOR, &aProc)
end

def delete(*args)
args.each do |fileName|
if directory?(fileName)
raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
args.each do |filename|
if directory?(filename)
raise Errno::EISDIR, "Is a directory - \"#{filename}\""
end

@mappedZip.remove(fileName)
@mappedZip.remove(filename)
end
end

Expand Down Expand Up @@ -488,8 +488,8 @@ def foreach(aDirectoryName)
path << '/' unless path.end_with?('/')
path = Regexp.escape(path)
subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
@mappedZip.each do |fileName|
match = subDirEntriesRegex.match(fileName)
@mappedZip.each do |filename|
match = subDirEntriesRegex.match(filename)
yield(match[1]) unless match.nil?
end
end
Expand Down
18 changes: 9 additions & 9 deletions samples/zipfind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
module Zip
module ZipFind
def self.find(path, zipFilePattern = /\.zip$/i)
Find.find(path) do |fileName|
yield(fileName)
next unless zipFilePattern.match(fileName) && File.file?(fileName)
Find.find(path) do |filename|
yield(filename)
next unless zipFilePattern.match(filename) && File.file?(filename)

begin
Zip::File.foreach(fileName) do |zipEntry|
yield(fileName + File::SEPARATOR + zipEntry.to_s)
Zip::File.foreach(filename) do |entry|
yield(filename + File::SEPARATOR + entry.to_s)
end
rescue Errno::EACCES => e
puts e
Expand All @@ -25,8 +25,8 @@ def self.find(path, zipFilePattern = /\.zip$/i)
end

def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
find(path, zipFilePattern) do |fileName|
yield(fileName) if fileNamePattern.match(fileName)
find(path, zipFilePattern) do |filename|
yield(filename) if fileNamePattern.match(filename)
end
end
end
Expand All @@ -42,8 +42,8 @@ def self.run(args)
check_args(args)
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
args[FILENAME_PATTERN_ARG_INDEX],
args[ZIPFILE_PATTERN_ARG_INDEX]) do |fileName|
report_entry_found fileName
args[ZIPFILE_PATTERN_ARG_INDEX]) do |filename|
report_entry_found filename
end
end

Expand Down
12 changes: 6 additions & 6 deletions test/central_directory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ def teardown
end

def test_read_from_stream
::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |zipFile|
cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |zip_file|
cdir = ::Zip::CentralDirectory.read_from_stream(zip_file)

assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdirEntry, testEntryName|
cdirEntry.name == testEntryName
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdir_entry, test_entry_name|
cdir_entry.name == test_entry_name
end)
assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
end
end

def test_read_from_invalid_stream
File.open('test/data/file2.txt', 'rb') do |zipFile|
File.open('test/data/file2.txt', 'rb') do |zip_file|
cdir = ::Zip::CentralDirectory.new
cdir.read_from_stream(zipFile)
cdir.read_from_stream(zip_file)
end
raise 'ZipError expected!'
rescue ::Zip::Error
Expand Down
4 changes: 2 additions & 2 deletions test/file_extract_directory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def test_extract_directory_exists_as_file
def test_extract_directory_exists_as_file_overwrite
File.open(TEST_OUT_NAME, 'w') { |f| f.puts 'something' }
gotCalled = false
extract_test_dir do |entry, destPath|
extract_test_dir do |entry, dest_path|
gotCalled = true
assert_equal(TEST_OUT_NAME, destPath)
assert_equal(TEST_OUT_NAME, dest_path)
assert(entry.directory?)
true
end
Expand Down
4 changes: 2 additions & 2 deletions test/file_extract_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def test_extract_exists_overwrite

gotCalledCorrectly = false
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
zf.extract(zf.entries.first, EXTRACTED_FILENAME) do |entry, extractLoc|
zf.extract(zf.entries.first, EXTRACTED_FILENAME) do |entry, extract_loc|
gotCalledCorrectly = zf.entries.first == entry &&
extractLoc == EXTRACTED_FILENAME
extract_loc == EXTRACTED_FILENAME
true
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/output_stream_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def assert_i_o_error_in_closed_stream
end

def write_test_zip(zos)
TEST_ZIP.entry_names.each do |entryName|
zos.put_next_entry(entryName)
File.open(entryName, 'rb') { |f| zos.write(f.read) }
TEST_ZIP.entry_names.each do |entry_name|
zos.put_next_entry(entry_name)
File.open(entry_name, 'rb') { |f| zos.write(f.read) }
end
end
end
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def self.assert_contents(filename, aString)

def assert_stream_contents(zis, testZipFile)
assert(!zis.nil?)
testZipFile.entry_names.each do |entryName|
assert_next_entry(entryName, zis)
testZipFile.entry_names.each do |entry_name|
assert_next_entry(entry_name, zis)
end
assert_nil(zis.get_next_entry)
end
Expand Down

0 comments on commit 846e704

Please sign in to comment.