From f5d091c59f95dbfbf470cad6d868949ec7b05ef8 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 19:13:38 +0000 Subject: [PATCH 01/14] Update Changelog version 1.0.0 date. --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 9447446..07b9675 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,4 @@ -# X.X.X (Next) +# 1.0.0 (2025-02-07) * Fix automatic require * Fix the Libbz2::finalizer method. From fd228c6f5e7a4c1cd94ca840a6f5a74f3422a9f9 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 19:16:03 +0000 Subject: [PATCH 02/14] Bump version number for RubyZip v3.0 support. --- Changelog.md | 2 ++ lib/zip/bzip2/version.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 07b9675..c81da15 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,5 @@ +# 2.0.0 (Next) + # 1.0.0 (2025-02-07) * Fix automatic require diff --git a/lib/zip/bzip2/version.rb b/lib/zip/bzip2/version.rb index eefc9fe..ec1f7b1 100644 --- a/lib/zip/bzip2/version.rb +++ b/lib/zip/bzip2/version.rb @@ -2,6 +2,6 @@ module Zip module Bzip2 - VERSION = '1.0.0' + VERSION = '2.0.0' end end From 0244e258324828b4f788b55f2d8b813ac108c1bd Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 19:28:30 +0000 Subject: [PATCH 03/14] Update to use RubyZip 3.0.0.rc2. --- rubyzip-bzip2.gemspec | 4 ++-- test/integration/zip_input_stream_bzip2_support_test.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rubyzip-bzip2.gemspec b/rubyzip-bzip2.gemspec index 87eaa69..62c9f57 100644 --- a/rubyzip-bzip2.gemspec +++ b/rubyzip-bzip2.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.license = 'BSD 2-Clause' spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 2.4' + spec.required_ruby_version = '>= 3.0' spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) @@ -35,7 +35,7 @@ Gem::Specification.new do |spec| } spec.add_dependency 'ffi', '~> 1.0' - spec.add_dependency 'rubyzip', '~> 2.4', '< 3.0' + spec.add_dependency 'rubyzip', '~> 3.0.0.rc2' spec.add_development_dependency 'minitest', '~> 5.15' spec.add_development_dependency 'rake', '~> 13.2' diff --git a/test/integration/zip_input_stream_bzip2_support_test.rb b/test/integration/zip_input_stream_bzip2_support_test.rb index a2d4aa9..fb92b9f 100644 --- a/test/integration/zip_input_stream_bzip2_support_test.rb +++ b/test/integration/zip_input_stream_bzip2_support_test.rb @@ -20,7 +20,9 @@ def test_input_stream_read end def test_input_stream_encrypted_read - Zip::InputStream.open(BZIP2_ZIP_FILE_ENCRYPTED, 0, Zip::TraditionalDecrypter.new(PASSWORD)) do |zis| + decrypter = Zip::TraditionalDecrypter.new(PASSWORD) + + Zip::InputStream.open(BZIP2_ZIP_FILE_ENCRYPTED, decrypter: decrypter) do |zis| zis.get_next_entry assert_equal file1_text, zis.read From 973e5558df869b6a7e4f16cbd609da509ab5e24e Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 20:30:37 +0000 Subject: [PATCH 04/14] Enable branch coverage analysis. --- .simplecov | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.simplecov b/.simplecov index 611a952..91415df 100644 --- a/.simplecov +++ b/.simplecov @@ -17,6 +17,6 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new( ) SimpleCov.start do - # enable_coverage :branch <-- Re-enable this when we move to ruby ~> 2.5. + enable_coverage :branch add_filter ['/test/', '/samples/'] end From 52ca630faac8877903de429efb4630af2e3cc675 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 20:31:19 +0000 Subject: [PATCH 05/14] Update Rubocop and add extensions. * Added rubocop-performance and rubocop-rake to match RubyZip. * Added Rubocop to the Rakefile. --- .rubocop.yml | 12 +++++++- .rubocop_todo.yml | 68 +++++++++++++++++++++++++++++++++++++++++++ Rakefile | 5 +++- rubyzip-bzip2.gemspec | 4 ++- 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 2db80d2..c5133c3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,15 @@ +require: + - rubocop-performance + - rubocop-rake + +inherit_from: .rubocop_todo.yml + +# Set this to the minimum supported ruby in the gemspec. Otherwise +# we get errors if our ruby version doesn't match. AllCops: - TargetRubyVersion: 2.4 + SuggestExtensions: false + TargetRubyVersion: 3.0 + NewCops: enable Layout/LineLength: Max: 120 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..840e922 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,68 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2025-02-08 19:37:20 UTC using RuboCop version 1.61.0. + +# Offense count: 7 +# Configuration parameters: EnforcedStyle, AllowedGems, Include. +# SupportedStyles: Gemfile, gems.rb, gemspec +# Include: **/*.gemspec, **/Gemfile, **/gems.rb +Gemspec/DevelopmentDependencies: + Exclude: + - 'rubyzip-bzip2.gemspec' + +# Offense count: 11 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. +Layout/LeadingCommentSpace: + Exclude: + - 'lib/zip/bzip2/decompress.rb' + - 'lib/zip/bzip2/decompressor.rb' + - 'lib/zip/bzip2/errors.rb' + - 'lib/zip/bzip2/ffi/libbz2.rb' + - 'lib/zip/bzip2/libbz2.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space +Layout/LineContinuationSpacing: + Exclude: + - 'lib/zip/bzip2/errors.rb' + - 'rubyzip-bzip2.gemspec' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +Performance/UnfreezeString: + Exclude: + - 'lib/zip/bzip2/decompress.rb' + - 'lib/zip/bzip2/decompressor.rb' + +# Offense count: 9 +# This cop supports safe autocorrection (--autocorrect). +Style/FileRead: + Exclude: + - 'test/integration/zip_file_bzip2_support_test.rb' + - 'test/integration/zip_input_stream_bzip2_support_test.rb' + - 'test/models/zip/bzip2/decompress_test.rb' + - 'test/models/zip/bzip2/decompressor_test.rb' + - 'test/models/zip/bzip2/libbz2_test.rb' + +# Offense count: 1 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'lib/zip/bzip2/libbz2.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantConstantBase: + Exclude: + - 'rubyzip-bzip2.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/zip/bzip2/decompressor.rb' diff --git a/Rakefile b/Rakefile index 4caa98e..8bd2b55 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,9 @@ require 'bundler/gem_tasks' require 'rake/testtask' +require 'rubocop/rake_task' + +task default: :test Rake::TestTask.new(:test) do |t| t.libs << 'test' @@ -9,4 +12,4 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList['test/**/*_test.rb'] end -task default: :test +RuboCop::RakeTask.new diff --git a/rubyzip-bzip2.gemspec b/rubyzip-bzip2.gemspec index 62c9f57..4e6919c 100644 --- a/rubyzip-bzip2.gemspec +++ b/rubyzip-bzip2.gemspec @@ -39,7 +39,9 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'minitest', '~> 5.15' spec.add_development_dependency 'rake', '~> 13.2' - spec.add_development_dependency 'rubocop', '~> 0.79.0' + spec.add_development_dependency 'rubocop', '~> 1.61.0' + spec.add_development_dependency 'rubocop-performance', '~> 1.20.0' + spec.add_development_dependency 'rubocop-rake', '~> 0.6.0' spec.add_development_dependency 'simplecov', '~> 0.18.0' spec.add_development_dependency 'simplecov-lcov', '~> 0.8' end From 247d46325d1010f07621a5c3f4a9ea5aedaa9f48 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 20:51:11 +0000 Subject: [PATCH 06/14] Prefer `require_relative` where appropriate. --- lib/zip/bzip2.rb | 4 ++-- lib/zip/bzip2/decompress.rb | 2 +- lib/zip/bzip2/decompressor.rb | 3 +-- lib/zip/bzip2/libbz2.rb | 5 ++--- rubyzip-bzip2.gemspec | 4 +--- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/zip/bzip2.rb b/lib/zip/bzip2.rb index ed697bd..69afc08 100644 --- a/lib/zip/bzip2.rb +++ b/lib/zip/bzip2.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true require 'zip' -require 'zip/bzip2/version' -require 'zip/bzip2/decompressor' +require_relative 'bzip2/version' +require_relative 'bzip2/decompressor' module Zip # The Zip::Bzip2 module extends Rubyzip with support for the bzip2 compression method. diff --git a/lib/zip/bzip2/decompress.rb b/lib/zip/bzip2/decompress.rb index 278091c..cbda3ad 100644 --- a/lib/zip/bzip2/decompress.rb +++ b/lib/zip/bzip2/decompress.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'zip/bzip2/libbz2' +require_relative 'libbz2' module Zip module Bzip2 diff --git a/lib/zip/bzip2/decompressor.rb b/lib/zip/bzip2/decompressor.rb index 0e19e68..06877f3 100644 --- a/lib/zip/bzip2/decompressor.rb +++ b/lib/zip/bzip2/decompressor.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require 'zip' -require 'zip/bzip2/decompress' +require_relative 'decompress' module Zip #:nodoc: module Bzip2 diff --git a/lib/zip/bzip2/libbz2.rb b/lib/zip/bzip2/libbz2.rb index 42ad397..3939053 100644 --- a/lib/zip/bzip2/libbz2.rb +++ b/lib/zip/bzip2/libbz2.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true -require 'ffi' -require 'zip/bzip2/errors' -require 'zip/bzip2/ffi/libbz2' +require_relative 'errors' +require_relative 'ffi/libbz2' module Zip module Bzip2 diff --git a/rubyzip-bzip2.gemspec b/rubyzip-bzip2.gemspec index 4e6919c..7b9f52a 100644 --- a/rubyzip-bzip2.gemspec +++ b/rubyzip-bzip2.gemspec @@ -1,8 +1,6 @@ # frozen_string_literal: true -lib = File.expand_path('lib', __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'zip/bzip2/version' +require_relative 'lib/zip/bzip2/version' Gem::Specification.new do |spec| spec.name = 'rubyzip-bzip2' From 556f2c3ebd088d42548f6ed6ddf3fc69349c4f63 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 20:57:00 +0000 Subject: [PATCH 07/14] Deal with Rubocop offences in gemspec. Allow development dependencies in the gemspec for now. --- .rubocop.yml | 3 +++ .rubocop_todo.yml | 15 --------------- rubyzip-bzip2.gemspec | 4 ++-- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c5133c3..b642ae0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,6 +11,9 @@ AllCops: TargetRubyVersion: 3.0 NewCops: enable +Gemspec/DevelopmentDependencies: + EnforcedStyle: gemspec + Layout/LineLength: Max: 120 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 840e922..5dda253 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -2,14 +2,6 @@ # `rubocop --auto-gen-config` # on 2025-02-08 19:37:20 UTC using RuboCop version 1.61.0. -# Offense count: 7 -# Configuration parameters: EnforcedStyle, AllowedGems, Include. -# SupportedStyles: Gemfile, gems.rb, gemspec -# Include: **/*.gemspec, **/Gemfile, **/gems.rb -Gemspec/DevelopmentDependencies: - Exclude: - - 'rubyzip-bzip2.gemspec' - # Offense count: 11 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. @@ -28,7 +20,6 @@ Layout/LeadingCommentSpace: Layout/LineContinuationSpacing: Exclude: - 'lib/zip/bzip2/errors.rb' - - 'rubyzip-bzip2.gemspec' # Offense count: 3 # This cop supports unsafe autocorrection (--autocorrect-all). @@ -54,12 +45,6 @@ Style/OptionalBooleanParameter: Exclude: - 'lib/zip/bzip2/libbz2.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantConstantBase: - Exclude: - - 'rubyzip-bzip2.gemspec' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowMultipleReturnValues. diff --git a/rubyzip-bzip2.gemspec b/rubyzip-bzip2.gemspec index 7b9f52a..9f0eea3 100644 --- a/rubyzip-bzip2.gemspec +++ b/rubyzip-bzip2.gemspec @@ -4,14 +4,14 @@ require_relative 'lib/zip/bzip2/version' Gem::Specification.new do |spec| spec.name = 'rubyzip-bzip2' - spec.version = ::Zip::Bzip2::VERSION + spec.version = Zip::Bzip2::VERSION spec.authors = [ 'Jan-Joost Spanjers', 'Robert Haines' ] spec.summary = 'Extension of rubyzip to read bzip2 compressed files' spec.description = - 'The rubyzip-bzip2 gem provides an extension of the rubyzip gem '\ + 'The rubyzip-bzip2 gem provides an extension of the rubyzip gem ' \ 'for reading zip files compressed with bzip2 compression' spec.homepage = 'http://github.com/rubyzip/rubyzip-bzip2' spec.license = 'BSD 2-Clause' From a592504e4fa1e0164649e30ba4ecd33b4ffdd0a9 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 21:00:16 +0000 Subject: [PATCH 08/14] Fix Style/RedundantReturn Rubocop offences. --- .rubocop_todo.yml | 7 ------- lib/zip/bzip2/decompressor.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5dda253..011c46d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -44,10 +44,3 @@ Style/FileRead: Style/OptionalBooleanParameter: Exclude: - 'lib/zip/bzip2/libbz2.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/zip/bzip2/decompressor.rb' diff --git a/lib/zip/bzip2/decompressor.rb b/lib/zip/bzip2/decompressor.rb index 06877f3..cdae642 100644 --- a/lib/zip/bzip2/decompressor.rb +++ b/lib/zip/bzip2/decompressor.rb @@ -29,7 +29,7 @@ def eof private def return_value_on_eof(length) - return '' if length.nil? || length.zero? + '' if length.nil? || length.zero? end def fill_buffer(min_length) From 41e213b7b10c38f6b4d59d6711776901e81b7f3a Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 21:03:05 +0000 Subject: [PATCH 09/14] Fix Style/OptionalBooleanParameter Rubocop offences. --- .rubocop_todo.yml | 7 ------- lib/zip/bzip2/decompress.rb | 2 +- lib/zip/bzip2/libbz2.rb | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 011c46d..8a0c636 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,10 +37,3 @@ Style/FileRead: - 'test/models/zip/bzip2/decompress_test.rb' - 'test/models/zip/bzip2/decompressor_test.rb' - 'test/models/zip/bzip2/libbz2_test.rb' - -# Offense count: 1 -# Configuration parameters: AllowedMethods. -# AllowedMethods: respond_to_missing? -Style/OptionalBooleanParameter: - Exclude: - - 'lib/zip/bzip2/libbz2.rb' diff --git a/lib/zip/bzip2/decompress.rb b/lib/zip/bzip2/decompress.rb index cbda3ad..ed32d4d 100644 --- a/lib/zip/bzip2/decompress.rb +++ b/lib/zip/bzip2/decompress.rb @@ -11,7 +11,7 @@ def initialize(options = {}) small = options[:small] @libbz2 = Libbz2.new.tap do |libbz2| - libbz2.decompress_init!(small) + libbz2.decompress_init!(small: small) end @finished = false diff --git a/lib/zip/bzip2/libbz2.rb b/lib/zip/bzip2/libbz2.rb index 3939053..af29ffe 100644 --- a/lib/zip/bzip2/libbz2.rb +++ b/lib/zip/bzip2/libbz2.rb @@ -27,7 +27,7 @@ def initialize @stream = FFI::Libbz2::BzStream.new end - def decompress_init!(small = false) + def decompress_init!(small: false) result = FFI::Libbz2::BZ2_bzDecompressInit(@stream, 0, small ? 1 : 0) check_error(result) From 3dffe609492f38d2b60d3b4aa172e0cb01908d7e Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 21:06:17 +0000 Subject: [PATCH 10/14] Fix Performance/UnfreezeString Rubocop offences. --- .rubocop_todo.yml | 7 ------- lib/zip/bzip2/decompress.rb | 2 +- lib/zip/bzip2/decompressor.rb | 4 ++-- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8a0c636..f567c45 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -21,13 +21,6 @@ Layout/LineContinuationSpacing: Exclude: - 'lib/zip/bzip2/errors.rb' -# Offense count: 3 -# This cop supports unsafe autocorrection (--autocorrect-all). -Performance/UnfreezeString: - Exclude: - - 'lib/zip/bzip2/decompress.rb' - - 'lib/zip/bzip2/decompressor.rb' - # Offense count: 9 # This cop supports safe autocorrection (--autocorrect). Style/FileRead: diff --git a/lib/zip/bzip2/decompress.rb b/lib/zip/bzip2/decompress.rb index ed32d4d..d6a2568 100644 --- a/lib/zip/bzip2/decompress.rb +++ b/lib/zip/bzip2/decompress.rb @@ -18,7 +18,7 @@ def initialize(options = {}) end def decompress(data) - result = ''.dup + result = +'' with_input_buffer(data) do |input_buffer| @libbz2.input_buffer = input_buffer diff --git a/lib/zip/bzip2/decompressor.rb b/lib/zip/bzip2/decompressor.rb index cdae642..bc35569 100644 --- a/lib/zip/bzip2/decompressor.rb +++ b/lib/zip/bzip2/decompressor.rb @@ -8,11 +8,11 @@ class Decompressor < ::Zip::Decompressor #:nodoc: def initialize(*args) super - @buffer = ''.dup + @buffer = +'' @bzip2_ffi_decompressor = ::Zip::Bzip2::Decompress.new end - def read(length = nil, outbuf = ''.dup) + def read(length = nil, outbuf = +'') return return_value_on_eof(length) if eof fill_buffer(length) From 1113149797a342aaa1132dff9bb287f4d2bce4ab Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 21:07:48 +0000 Subject: [PATCH 11/14] Fix Layout/LineContinuationSpacing Rubocop offences. --- .rubocop_todo.yml | 8 -------- lib/zip/bzip2/errors.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f567c45..98acbd6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,14 +13,6 @@ Layout/LeadingCommentSpace: - 'lib/zip/bzip2/ffi/libbz2.rb' - 'lib/zip/bzip2/libbz2.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, no_space -Layout/LineContinuationSpacing: - Exclude: - - 'lib/zip/bzip2/errors.rb' - # Offense count: 9 # This cop supports safe autocorrection (--autocorrect). Style/FileRead: diff --git a/lib/zip/bzip2/errors.rb b/lib/zip/bzip2/errors.rb index 6e11c52..1d80295 100644 --- a/lib/zip/bzip2/errors.rb +++ b/lib/zip/bzip2/errors.rb @@ -26,7 +26,7 @@ class DataError < Error def initialize(message = nil) #:nodoc: super( message || - 'Data integrity error detected (mismatch between stored and computed CRCs, '\ + 'Data integrity error detected (mismatch between stored and computed CRCs, ' \ 'or other anomaly in the compressed data)', ) end From ccfe744a97cf65e4ad94e7f0939dd0f00602952a Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 21:55:25 +0000 Subject: [PATCH 12/14] Fix Style/FileRead Rubocop offences. --- .rubocop_todo.yml | 10 ---------- test/integration/zip_file_bzip2_support_test.rb | 4 ++-- .../integration/zip_input_stream_bzip2_support_test.rb | 4 ++-- test/models/zip/bzip2/decompress_test.rb | 4 ++-- test/models/zip/bzip2/decompressor_test.rb | 2 +- test/models/zip/bzip2/libbz2_test.rb | 4 ++-- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 98acbd6..d630c89 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -12,13 +12,3 @@ Layout/LeadingCommentSpace: - 'lib/zip/bzip2/errors.rb' - 'lib/zip/bzip2/ffi/libbz2.rb' - 'lib/zip/bzip2/libbz2.rb' - -# Offense count: 9 -# This cop supports safe autocorrection (--autocorrect). -Style/FileRead: - Exclude: - - 'test/integration/zip_file_bzip2_support_test.rb' - - 'test/integration/zip_input_stream_bzip2_support_test.rb' - - 'test/models/zip/bzip2/decompress_test.rb' - - 'test/models/zip/bzip2/decompressor_test.rb' - - 'test/models/zip/bzip2/libbz2_test.rb' diff --git a/test/integration/zip_file_bzip2_support_test.rb b/test/integration/zip_file_bzip2_support_test.rb index 568eb45..3ae2f24 100644 --- a/test/integration/zip_file_bzip2_support_test.rb +++ b/test/integration/zip_file_bzip2_support_test.rb @@ -17,10 +17,10 @@ def test_file_read private def file1_text - @file1_text ||= File.open(FILE1, 'r').read + @file1_text ||= File.read(FILE1) end def file2_text - @file2_text ||= File.open(FILE2, 'r').read + @file2_text ||= File.read(FILE2) end end diff --git a/test/integration/zip_input_stream_bzip2_support_test.rb b/test/integration/zip_input_stream_bzip2_support_test.rb index fb92b9f..71941bd 100644 --- a/test/integration/zip_input_stream_bzip2_support_test.rb +++ b/test/integration/zip_input_stream_bzip2_support_test.rb @@ -34,10 +34,10 @@ def test_input_stream_encrypted_read private def file1_text - @file1_text ||= File.open(FILE1, 'r').read + @file1_text ||= File.read(FILE1) end def file2_text - @file2_text ||= File.open(FILE2, 'r').read + @file2_text ||= File.read(FILE2) end end diff --git a/test/models/zip/bzip2/decompress_test.rb b/test/models/zip/bzip2/decompress_test.rb index e3ca4a7..c6b425c 100644 --- a/test/models/zip/bzip2/decompress_test.rb +++ b/test/models/zip/bzip2/decompress_test.rb @@ -43,10 +43,10 @@ def test_decompress_with_corrupted_input private def file_text - @file_text ||= File.open(FILE, &:read) + @file_text ||= File.read(FILE) end def compressed_data - @compressed_data ||= File.open(BZIP2_FILE, 'rb', &:read) + @compressed_data ||= File.binread(BZIP2_FILE) end end diff --git a/test/models/zip/bzip2/decompressor_test.rb b/test/models/zip/bzip2/decompressor_test.rb index c015427..92f6a05 100644 --- a/test/models/zip/bzip2/decompressor_test.rb +++ b/test/models/zip/bzip2/decompressor_test.rb @@ -39,6 +39,6 @@ def test_data_error private def test_text - @test_text ||= File.open(FILE1, &:read) + @test_text ||= File.read(FILE1) end end diff --git a/test/models/zip/bzip2/libbz2_test.rb b/test/models/zip/bzip2/libbz2_test.rb index 30aecff..85dfed6 100644 --- a/test/models/zip/bzip2/libbz2_test.rb +++ b/test/models/zip/bzip2/libbz2_test.rb @@ -74,10 +74,10 @@ def decompress(data) end def file_text - @file_text ||= File.open(FILE, &:read) + @file_text ||= File.read(FILE) end def compressed_data - @compressed_data ||= File.open(BZIP2_FILE, 'rb', &:read) + @compressed_data ||= File.binread(BZIP2_FILE) end end From 8a04a440f4128b91365341c32634fbdac88e2e88 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 21:59:37 +0000 Subject: [PATCH 13/14] Fix Layout/LeadingCommentSpace Rubocop offences. --- .rubocop.yml | 2 -- .rubocop_todo.yml | 14 -------------- lib/zip/bzip2/decompress.rb | 2 +- lib/zip/bzip2/decompressor.rb | 4 ++-- lib/zip/bzip2/errors.rb | 10 +++++----- lib/zip/bzip2/ffi/libbz2.rb | 4 ++-- lib/zip/bzip2/libbz2.rb | 2 +- 7 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index b642ae0..b3efced 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,8 +2,6 @@ require: - rubocop-performance - rubocop-rake -inherit_from: .rubocop_todo.yml - # Set this to the minimum supported ruby in the gemspec. Otherwise # we get errors if our ruby version doesn't match. AllCops: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index d630c89..0000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,14 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2025-02-08 19:37:20 UTC using RuboCop version 1.61.0. - -# Offense count: 11 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. -Layout/LeadingCommentSpace: - Exclude: - - 'lib/zip/bzip2/decompress.rb' - - 'lib/zip/bzip2/decompressor.rb' - - 'lib/zip/bzip2/errors.rb' - - 'lib/zip/bzip2/ffi/libbz2.rb' - - 'lib/zip/bzip2/libbz2.rb' diff --git a/lib/zip/bzip2/decompress.rb b/lib/zip/bzip2/decompress.rb index d6a2568..9833a56 100644 --- a/lib/zip/bzip2/decompress.rb +++ b/lib/zip/bzip2/decompress.rb @@ -4,7 +4,7 @@ module Zip module Bzip2 - class Decompress #:nodoc: + class Decompress # :nodoc: OUTPUT_BUFFER_SIZE = 4096 def initialize(options = {}) diff --git a/lib/zip/bzip2/decompressor.rb b/lib/zip/bzip2/decompressor.rb index bc35569..a64ba30 100644 --- a/lib/zip/bzip2/decompressor.rb +++ b/lib/zip/bzip2/decompressor.rb @@ -2,9 +2,9 @@ require_relative 'decompress' -module Zip #:nodoc: +module Zip # :nodoc: module Bzip2 - class Decompressor < ::Zip::Decompressor #:nodoc: + class Decompressor < ::Zip::Decompressor # :nodoc: def initialize(*args) super diff --git a/lib/zip/bzip2/errors.rb b/lib/zip/bzip2/errors.rb index 1d80295..8c15c77 100644 --- a/lib/zip/bzip2/errors.rb +++ b/lib/zip/bzip2/errors.rb @@ -11,7 +11,7 @@ class MemError < Error # Initializes a new instance of MemError. # # @private - def initialize #:nodoc: + def initialize # :nodoc: super('Could not allocate enough memory to perform this request') end end @@ -23,7 +23,7 @@ class DataError < Error # # @param message [String] Exception message (overrides the default). # @private - def initialize(message = nil) #:nodoc: + def initialize(message = nil) # :nodoc: super( message || 'Data integrity error detected (mismatch between stored and computed CRCs, ' \ @@ -38,7 +38,7 @@ class MagicDataError < DataError # Initializes a new instance of MagicDataError. # # @private - def initialize #:nodoc: + def initialize # :nodoc: super('Compressed data does not start with the correct magic bytes (\'BZh\')') end end @@ -48,7 +48,7 @@ class ConfigError < DataError # Initializes a new instance of ConfigError. # # @private - def initialize #:nodoc: + def initialize # :nodoc: super('libbz2 has been improperly compiled on your platform') end end @@ -59,7 +59,7 @@ class UnexpectedError < Error # # @param error_code [Integer] The error_code reported by libbz2. # @private - def initialize(error_code) #:nodoc: + def initialize(error_code) # :nodoc: super("An unexpected error was detected (error code: #{error_code})") end end diff --git a/lib/zip/bzip2/ffi/libbz2.rb b/lib/zip/bzip2/ffi/libbz2.rb index 0352201..04d69ba 100644 --- a/lib/zip/bzip2/ffi/libbz2.rb +++ b/lib/zip/bzip2/ffi/libbz2.rb @@ -34,7 +34,7 @@ module FFI # See bzlib.h and http://bzip.org/docs.html. # # @private - module Libbz2 #:nodoc: + module Libbz2 # :nodoc: extend ::FFI::Library ffi_lib ['bz2', 'libbz2.so.1', 'libbz2.dll'] @@ -62,7 +62,7 @@ module Libbz2 #:nodoc: callback :bzfree, %i[pointer pointer], :void # typedef struct { ... } bz_stream; - class BzStream < ::FFI::Struct #:nodoc: + class BzStream < ::FFI::Struct # :nodoc: layout :next_in, :pointer, :avail_in, :uint, :total_in_lo32, :uint, diff --git a/lib/zip/bzip2/libbz2.rb b/lib/zip/bzip2/libbz2.rb index af29ffe..9762368 100644 --- a/lib/zip/bzip2/libbz2.rb +++ b/lib/zip/bzip2/libbz2.rb @@ -5,7 +5,7 @@ module Zip module Bzip2 - class Libbz2 #:nodoc: + class Libbz2 # :nodoc: def self.finalizer(stream) lambda do |_id| FFI::Libbz2::BZ2_bzDecompressEnd(stream) From e55fff45cb172070050cdb302dec10a0d006186a Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2025 22:04:34 +0000 Subject: [PATCH 14/14] Update GitHub Actions to use rubies >= 3.0. --- .github/workflows/lint.yml | 2 +- .github/workflows/tests.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b8533ad..0de9158 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,7 +12,7 @@ jobs: - name: Install and set up ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.4 + ruby-version: '3.0' bundler-cache: true - name: Rubocop diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 45a98af..2b6b635 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,12 +8,12 @@ jobs: fail-fast: false matrix: os: [ubuntu] - ruby: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head, jruby, jruby-head, truffleruby, truffleruby-head] + ruby: ['3.0', '3.1', '3.2', '3.3', '3.4', head, jruby, jruby-head, truffleruby, truffleruby-head] include: - os: macos - ruby: '2.6' + ruby: '3.0' - os: windows - ruby: '2.4.10' + ruby: '3.0' runs-on: ${{ matrix.os }}-latest continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.os == 'windows' }} steps: