From c8bfd147643cf783c779ec6c770077c8394353a5 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 14 Sep 2019 15:38:27 +0100 Subject: [PATCH 01/56] Update rubocop version and the config files. Also rename .rubocop_rubyzip.yml to be consistent with Rubocop default setup. --- .rubocop.yml | 7 +- .rubocop_rubyzip.yml | 137 --------- .rubocop_todo.yml | 586 ++++++++++++++++++++++++++++++++++++ rubyzip.gemspec | 2 +- test/path_traversal_test.rb | 2 +- 5 files changed, 589 insertions(+), 145 deletions(-) delete mode 100644 .rubocop_rubyzip.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index a408fa0d..cc32da4b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1 @@ -inherit_from: - - .rubocop_rubyzip.yml -AllCops: - TargetRubyVersion: 1.9 -Style/MutableConstant: - Enabled: false # Because some existent code relies on mutable constant +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_rubyzip.yml b/.rubocop_rubyzip.yml deleted file mode 100644 index 3030f8a0..00000000 --- a/.rubocop_rubyzip.yml +++ /dev/null @@ -1,137 +0,0 @@ -# This configuration was generated by `rubocop --auto-gen-config` -# on 2015-06-08 10:22:52 +0300 using RuboCop version 0.32.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 13 -Lint/HandleExceptions: - Enabled: false - -# Offense count: 1 -Lint/LiteralInCondition: - Enabled: false - -# Offense count: 1 -Lint/RescueException: - Enabled: false - -# Offense count: 1 -Lint/UselessComparison: - Enabled: false - -# Offense count: 115 -Metrics/AbcSize: - Max: 62 - -# Offense count: 12 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 562 - -# Offense count: 21 -Metrics/CyclomaticComplexity: - Max: 14 - -# Offense count: 237 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 236 - -# Offense count: 108 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 35 - -# Offense count: 2 -# Configuration parameters: CountKeywordArgs. -Metrics/ParameterLists: - Max: 10 - -# Offense count: 15 -Metrics/PerceivedComplexity: - Max: 15 - -# Offense count: 8 -Style/AccessorMethodName: - Enabled: false - -# Offense count: 23 -# Cop supports --auto-correct. -Style/Alias: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. -Style/BlockDelimiters: - Enabled: false - -# Offense count: 7 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/ClassAndModuleChildren: - Enabled: false - -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/ClassCheck: - Enabled: false - -# Offense count: 77 -Style/Documentation: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/InfiniteLoop: - Enabled: false - -# Offense count: 1 -Style/ModuleFunction: - Enabled: false - -# Offense count: 1 -Style/MultilineBlockChain: - Enabled: false - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. -Style/RegexpLiteral: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Enabled: false - -# Offense count: 79 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SignalException: - Enabled: false - -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: MultiSpaceAllowedForOperators. -Style/SpaceAroundOperators: - Enabled: false - -# Offense count: 30 -# Cop supports --auto-correct. -Style/SpecialGlobalVars: - Enabled: false - -# Offense count: 22 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -Style/SymbolProc: - Enabled: false - -# Offense count: 151 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/VariableName: - Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..daa76c02 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,586 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2020-02-08 14:58:51 +0000 using RuboCop version 0.79.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'rubyzip.gemspec' + +# Offense count: 76 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Exclude: + - 'test/extra_field_ut_test.rb' + +# Offense count: 26 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'lib/zip/constants.rb' + - 'lib/zip/file.rb' + - 'rubyzip.gemspec' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'lib/zip/entry.rb' + - 'lib/zip/extra_field/zip64.rb' + - 'lib/zip/file.rb' + - 'lib/zip/filesystem.rb' + - 'lib/zip/input_stream.rb' + +# Offense count: 1 +Lint/AmbiguousBlockAssociation: + Exclude: + - 'test/filesystem/file_nonmutating_test.rb' + +# Offense count: 1 +Lint/LiteralAsCondition: + Exclude: + - 'lib/zip/ioextras/abstract_input_stream.rb' + +# Offense count: 1 +Lint/RescueException: + Exclude: + - 'test/output_stream_test.rb' + +# Offense count: 12 +# Configuration parameters: AllowComments. +Lint/SuppressedException: + Exclude: + - 'lib/zip/ioextras/abstract_input_stream.rb' + - 'test/central_directory_entry_test.rb' + - 'test/central_directory_test.rb' + - 'test/errors_test.rb' + - 'test/ioextras/abstract_input_stream_test.rb' + - 'test/local_entry_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'test/file_test.rb' + +# Offense count: 1 +# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. +Lint/UselessAccessModifier: + Exclude: + - 'lib/zip/entry.rb' + +# Offense count: 1 +Lint/UselessComparison: + Exclude: + - 'test/entry_test.rb' + +# Offense count: 120 +Metrics/AbcSize: + Max: 60 + +# Offense count: 3 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 43 + +# Offense count: 15 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 579 + +# Offense count: 26 +Metrics/CyclomaticComplexity: + Max: 14 + +# Offense count: 120 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 45 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 10 + +# Offense count: 21 +Metrics/PerceivedComplexity: + Max: 15 + +# Offense count: 9 +Naming/AccessorMethodName: + Exclude: + - 'lib/zip/entry.rb' + - 'lib/zip/filesystem.rb' + - 'lib/zip/input_stream.rb' + - '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: 2 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: lowercase, uppercase +Naming/HeredocDelimiterCase: + Exclude: + - 'lib/zip/filesystem.rb' + - 'test/test_helper.rb' + +# Offense count: 2 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'lib/zip/extra_field/old_unix.rb' + - 'lib/zip/extra_field/unix.rb' + +# Offense count: 140 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to, by, on, in, at, ip, db, os +Naming/MethodParameterName: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: + Exclude: + - 'samples/zipfind.rb' + +# Offense count: 721 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: snake_case, camelCase +Naming/VariableName: + Enabled: false + +# Offense count: 13 +Security/Open: + Exclude: + - 'lib/zip/file.rb' + - 'lib/zip/filesystem.rb' + - 'lib/zip/input_stream.rb' + - 'test/encryption_test.rb' + - 'test/stored_support_test.rb' + +# Offense count: 7 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: inline, group +Style/AccessModifierDeclarations: + Exclude: + - 'lib/zip/central_directory.rb' + - 'lib/zip/extra_field/zip64.rb' + - 'lib/zip/filesystem.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'lib/zip/inflater.rb' + - 'lib/zip/ioextras/abstract_input_stream.rb' + - 'lib/zip/pass_thru_decompressor.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'test/case_sensitivity_test.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'lib/zip/extra_field/generic.rb' + - 'lib/zip/extra_field/ntfs.rb' + - 'lib/zip/extra_field/old_unix.rb' + - 'lib/zip/extra_field/universal_time.rb' + - 'lib/zip/extra_field/unix.rb' + - '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: 2 +Style/CommentedKeyword: + Exclude: + - 'lib/zip/ioextras.rb' + - 'lib/zip/streamable_stream.rb' + +# Offense count: 26 +Style/Documentation: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +Style/Encoding: + Exclude: + - 'rubyzip.gemspec' + - 'test/errors_test.rb' + - 'test/unicode_file_names_and_comments_test.rb' + +# Offense count: 2 +Style/EvalWithLocation: + Exclude: + - 'test/test_helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Exclude: + - 'rubyzip.gemspec' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: left_coerce, right_coerce, single_coerce, fdiv +Style/FloatDivision: + Exclude: + - 'samples/example.rb' + +# Offense count: 3 +# Configuration parameters: . +# SupportedStyles: annotated, template, unannotated +Style/FormatStringToken: + EnforcedStyle: unannotated + +# Offense count: 95 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, never +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: 1 +# Configuration parameters: AllowIfModifier. +Style/IfInsideElse: + Exclude: + - 'lib/zip/entry.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'lib/zip/entry.rb' + - 'lib/zip/extra_field/generic.rb' + - 'lib/zip/file.rb' + - 'lib/zip/filesystem.rb' + - 'lib/zip/input_stream.rb' + - 'lib/zip/pass_thru_decompressor.rb' + - 'lib/zip/streamable_stream.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/InfiniteLoop: + Exclude: + - 'lib/zip/ioextras/abstract_input_stream.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'samples/write_simple.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, Autocorrect. +# SupportedStyles: module_function, extend_self +Style/ModuleFunction: + Exclude: + - 'lib/zip.rb' + +# Offense count: 1 +Style/MultilineBlockChain: + Exclude: + - 'lib/zip/crypto/traditional_encryption.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/MultilineWhenThen: + Exclude: + - 'lib/zip/output_stream.rb' + +# Offense count: 56 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinBodyLength. +# SupportedStyles: skip_modifier_ifs, always +Style/Next: + Exclude: + - 'lib/zip/entry.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: IncludeSemanticChanges. +Style/NonNilCheck: + Exclude: + - 'test/case_sensitivity_test.rb' + - 'test/file_test.rb' + - 'test/settings_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedOctalStyle. +# SupportedOctalStyles: zero_with_o, zero_only +Style/NumericLiteralPrefix: + Exclude: + - 'test/file_options_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: Strict. +Style/NumericLiterals: + MinDigits: 6 + +# Offense count: 23 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/zip/entry.rb' + - 'lib/zip/extra_field/old_unix.rb' + - 'lib/zip/extra_field/universal_time.rb' + - 'lib/zip/extra_field/unix.rb' + - 'lib/zip/file.rb' + - 'lib/zip/filesystem.rb' + - 'lib/zip/input_stream.rb' + - 'lib/zip/ioextras.rb' + - 'lib/zip/ioextras/abstract_input_stream.rb' + - 'test/file_split_test.rb' + - 'test/test_helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/OrAssignment: + Exclude: + - 'test/test_helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/zip/central_directory.rb' + +# Offense count: 12 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'lib/zip/filesystem.rb' + - 'test/entry_test.rb' + - 'test/path_traversal_test.rb' + - 'test/settings_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'test/gentestfiles.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/zip/entry.rb' + - 'lib/zip/input_stream.rb' + - 'lib/zip/output_stream.rb' + - 'test/file_extract_test.rb' + - 'test/filesystem/file_nonmutating_test.rb' + - 'test/filesystem/file_stat_test.rb' + - 'test/test_helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowAsExpressionSeparator. +Style/Semicolon: + Exclude: + - 'test/file_test.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: only_raise, only_fail, semantic +Style/SignalException: + Exclude: + - 'test/central_directory_entry_test.rb' + - 'test/central_directory_test.rb' + - 'test/filesystem/file_nonmutating_test.rb' + - 'test/ioextras/abstract_input_stream_test.rb' + - 'test/local_entry_test.rb' + - 'test/test_helper.rb' + +# Offense count: 30 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: use_perl_names, use_english_names +Style/SpecialGlobalVars: + Exclude: + - 'lib/zip/filesystem.rb' + - 'lib/zip/ioextras/abstract_input_stream.rb' + - 'lib/zip/ioextras/abstract_output_stream.rb' + - 'samples/example.rb' + - 'samples/example_filesystem.rb' + - 'samples/gtk_ruby_zip.rb' + - 'samples/qtzip.rb' + - 'samples/write_simple.rb' + - 'samples/zipfind.rb' + - 'test/gentestfiles.rb' + - 'test/ioextras/abstract_input_stream_test.rb' + - 'test/ioextras/abstract_output_stream_test.rb' + - 'test/output_stream_test.rb' + - 'test/test_helper.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'lib/zip/crypto/decrypted_io.rb' + - 'lib/zip/inflater.rb' + - 'lib/zip/pass_thru_decompressor.rb' + - 'test/file_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: MinSize. +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets + +# Offense count: 42 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'lib/zip/file.rb' + - 'lib/zip/filesystem.rb' + - 'test/basic_zip_file_test.rb' + - 'test/case_sensitivity_test.rb' + - 'test/deflater_test.rb' + - 'test/file_extract_test.rb' + - 'test/file_split_test.rb' + - 'test/file_test.rb' + - 'test/filesystem/file_nonmutating_test.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowSafeAssignment. +# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex +Style/TernaryParentheses: + Exclude: + - 'lib/zip/crypto/decrypted_io.rb' + - 'lib/zip/inflater.rb' + - 'lib/zip/pass_thru_decompressor.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'lib/zip/central_directory.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'lib/zip/constants.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Style/UnpackFirst: + Exclude: + - 'lib/zip/entry.rb' + - 'lib/zip/extra_field.rb' + - 'lib/zip/extra_field/generic.rb' + - 'lib/zip/extra_field/zip64.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/ZeroLengthPredicate: + Exclude: + - 'lib/zip/file.rb' + - 'lib/zip/input_stream.rb' + +# Offense count: 247 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 236 diff --git a/rubyzip.gemspec b/rubyzip.gemspec index f8c59a18..30dd2998 100644 --- a/rubyzip.gemspec +++ b/rubyzip.gemspec @@ -27,5 +27,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'pry', '~> 0.10' s.add_development_dependency 'minitest', '~> 5.4' s.add_development_dependency 'coveralls', '~> 0.7' - s.add_development_dependency 'rubocop', '~> 0.49.1' + s.add_development_dependency 'rubocop', '~> 0.79' end diff --git a/test/path_traversal_test.rb b/test/path_traversal_test.rb index 8b6f67d5..6950fbcb 100644 --- a/test/path_traversal_test.rb +++ b/test/path_traversal_test.rb @@ -64,7 +64,7 @@ def test_non_leading_dot_dot_with_existing_folder entries = { 'tmp/' => '', 'tmp/../../moo' => /WARNING: skipped \'tmp\/\.\.\/\.\.\/moo\'/ - } + } in_tmpdir do extract_paths('relative1.zip', entries) assert Dir.exist?('tmp') From a3245ac241e9a33bacdffbe1e45f79344b46f23e Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 15 Sep 2019 16:44:51 +0100 Subject: [PATCH 02/56] Add Rubocop tasks to the Rakefile. --- Rakefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Rakefile b/Rakefile index 44a9b287..717c6b73 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ require 'bundler/gem_tasks' require 'rake/testtask' +require 'rubocop/rake_task' task default: :test @@ -10,6 +11,8 @@ Rake::TestTask.new(:test) do |test| test.verbose = true end +RuboCop::RakeTask.new + # Rake::TestTask.new(:zip64_full_test) do |test| # test.libs << File.join(File.dirname(__FILE__), 'lib') # test.libs << File.join(File.dirname(__FILE__), 'test') From aa400355252ceb23d11ad24589184b6fa60d9d24 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 8 Feb 2020 15:12:43 +0000 Subject: [PATCH 03/56] Fix Gemspec/OrderedDependencies cop. --- .rubocop_todo.yml | 8 -------- rubyzip.gemspec | 6 +++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index daa76c02..b4d47815 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: TreatCommentsAsGroupSeparators, Include. -# Include: **/*.gemspec -Gemspec/OrderedDependencies: - Exclude: - - 'rubyzip.gemspec' - # Offense count: 76 # Cop supports --auto-correct. Layout/EmptyLineAfterGuardClause: diff --git a/rubyzip.gemspec b/rubyzip.gemspec index 30dd2998..5b08a597 100644 --- a/rubyzip.gemspec +++ b/rubyzip.gemspec @@ -23,9 +23,9 @@ Gem::Specification.new do |s| 'wiki_uri' => 'https://github.com/rubyzip/rubyzip/wiki' } s.required_ruby_version = '>= 2.4' - s.add_development_dependency 'rake', '~> 10.3' - s.add_development_dependency 'pry', '~> 0.10' - s.add_development_dependency 'minitest', '~> 5.4' s.add_development_dependency 'coveralls', '~> 0.7' + s.add_development_dependency 'minitest', '~> 5.4' + s.add_development_dependency 'pry', '~> 0.10' + s.add_development_dependency 'rake', '~> 10.3' s.add_development_dependency 'rubocop', '~> 0.79' end From 73e405acef6a00e5c927c2126e8a33ec091b73df Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 14 Sep 2019 15:56:02 +0100 Subject: [PATCH 04/56] Fix Security/Open cop errors. --- .rubocop_todo.yml | 9 --------- lib/zip/file.rb | 4 ++-- lib/zip/filesystem.rb | 6 +++--- lib/zip/input_stream.rb | 2 +- test/encryption_test.rb | 6 +++--- test/stored_support_test.rb | 8 ++++---- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b4d47815..5820055d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -177,15 +177,6 @@ Naming/RescuedExceptionsVariableName: Naming/VariableName: Enabled: false -# Offense count: 13 -Security/Open: - Exclude: - - 'lib/zip/file.rb' - - 'lib/zip/filesystem.rb' - - 'lib/zip/input_stream.rb' - - 'test/encryption_test.rb' - - 'test/stored_support_test.rb' - # Offense count: 7 # Configuration parameters: EnforcedStyle. # SupportedStyles: inline, group diff --git a/lib/zip/file.rb b/lib/zip/file.rb index 45017822..3b8c3338 100644 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -167,7 +167,7 @@ def open_buffer(io, options = {}) # local entry headers (which contain the same information as the # central directory). def foreach(aZipFileName, &block) - open(aZipFileName) do |zipFile| + ::Zip::File.open(aZipFileName) do |zipFile| zipFile.each(&block) end end @@ -234,7 +234,7 @@ def split(zip_file_name, segment_size = MAX_SEGMENT_SIZE, delete_zip_file = true return if zip_file_size <= segment_size segment_count = get_segment_count_for_split(zip_file_size, segment_size) # Checking for correct zip structure - open(zip_file_name) {} + ::Zip::File.open(zip_file_name) {} partial_zip_file_name = get_partial_zip_file_name(zip_file_name, partial_zip_file_name) szip_file_index = 0 ::File.open(zip_file_name, 'rb') do |zip_file| diff --git a/lib/zip/filesystem.rb b/lib/zip/filesystem.rb index 81ad1a18..158e7f6f 100644 --- a/lib/zip/filesystem.rb +++ b/lib/zip/filesystem.rb @@ -250,7 +250,7 @@ def open(fileName, openMode = 'r', permissionInt = 0o644, &block) end def new(fileName, openMode = 'r') - open(fileName, openMode) + self.open(fileName, openMode) end def size(fileName) @@ -388,7 +388,7 @@ def stat(fileName) alias lstat stat def readlines(fileName) - open(fileName) { |is| is.readlines } + self.open(fileName) { |is| is.readlines } end def read(fileName) @@ -400,7 +400,7 @@ def popen(*args, &aProc) end def foreach(fileName, aSep = $/, &aProc) - open(fileName) { |is| is.each_line(aSep, &aProc) } + self.open(fileName) { |is| is.each_line(aSep, &aProc) } end def delete(*args) diff --git a/lib/zip/input_stream.rb b/lib/zip/input_stream.rb index b4c502f5..b0b7103d 100644 --- a/lib/zip/input_stream.rb +++ b/lib/zip/input_stream.rb @@ -100,7 +100,7 @@ def open(filename_or_io, offset = 0, decrypter = nil) def open_buffer(filename_or_io, offset = 0) warn 'open_buffer is deprecated!!! Use open instead!' - open(filename_or_io, offset) + ::Zip::InputStream.open(filename_or_io, offset) end end diff --git a/test/encryption_test.rb b/test/encryption_test.rb index 46770a17..d3ed5ffb 100644 --- a/test/encryption_test.rb +++ b/test/encryption_test.rb @@ -14,14 +14,14 @@ def teardown end def test_encrypt - test_file = open(ENCRYPT_ZIP_TEST_FILE, 'rb').read + test_file = ::File.open(ENCRYPT_ZIP_TEST_FILE, 'rb').read @rand = [250, 143, 107, 13, 143, 22, 155, 75, 228, 150, 12] @output = ::Zip::DOSTime.stub(:now, ::Zip::DOSTime.new(2014, 12, 17, 15, 56, 24)) do Random.stub(:rand, ->(_range) { @rand.shift }) do Zip::OutputStream.write_buffer(::StringIO.new(''), Zip::TraditionalEncrypter.new('password')) do |zos| zos.put_next_entry('file1.txt') - zos.write open(INPUT_FILE1).read + zos.write ::File.open(INPUT_FILE1).read end.string end end @@ -36,7 +36,7 @@ def test_decrypt entry = zis.get_next_entry assert_equal 'file1.txt', entry.name assert_equal 1327, entry.size - assert_equal open(INPUT_FILE1, 'r').read, zis.read + assert_equal ::File.open(INPUT_FILE1, 'r').read, zis.read end end end diff --git a/test/stored_support_test.rb b/test/stored_support_test.rb index 8260e4a9..e0d3ae0e 100644 --- a/test/stored_support_test.rb +++ b/test/stored_support_test.rb @@ -11,11 +11,11 @@ def test_read entry = zis.get_next_entry assert_equal 'file1.txt', entry.name assert_equal 1327, entry.size - assert_equal open(INPUT_FILE1, 'r').read, zis.read + assert_equal ::File.open(INPUT_FILE1, 'r').read, zis.read entry = zis.get_next_entry assert_equal 'file2.txt', entry.name assert_equal 41234, entry.size - assert_equal open(INPUT_FILE2, 'r').read, zis.read + assert_equal ::File.open(INPUT_FILE2, 'r').read, zis.read end end @@ -24,11 +24,11 @@ def test_encrypted_read entry = zis.get_next_entry assert_equal 'file1.txt', entry.name assert_equal 1327, entry.size - assert_equal open(INPUT_FILE1, 'r').read, zis.read + assert_equal ::File.open(INPUT_FILE1, 'r').read, zis.read entry = zis.get_next_entry assert_equal 'file2.txt', entry.name assert_equal 41234, entry.size - assert_equal open(INPUT_FILE2, 'r').read, zis.read + assert_equal ::File.open(INPUT_FILE2, 'r').read, zis.read end end end From f1154c2ecab5f22a6dfd6daead062e7f2345efe0 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 10:39:04 +0000 Subject: [PATCH 05/56] Fix Style/OrAssignment cop. --- .rubocop_todo.yml | 6 ------ test/test_helper.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5820055d..db48ac8d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -398,12 +398,6 @@ Style/NumericPredicate: - 'test/file_split_test.rb' - 'test/test_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/OrAssignment: - Exclude: - - 'test/test_helper.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: AllowMultipleReturnValues. diff --git a/test/test_helper.rb b/test/test_helper.rb index 224a1eb2..7a0edfc9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,7 +24,7 @@ module IOizeString def read(count = nil) @tell ||= 0 - count = size unless count + count ||= size retVal = slice(@tell, count) @tell += count retVal From 3a3ac6feb7f72a835a4285825f2e01c11b5325a1 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 14 Sep 2019 16:03:43 +0100 Subject: [PATCH 06/56] Fix Style/Semicolon cop. --- .rubocop_todo.yml | 7 ------- test/file_test.rb | 10 ++++++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index db48ac8d..698aa814 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -438,13 +438,6 @@ Style/SafeNavigation: - 'test/filesystem/file_stat_test.rb' - 'test/test_helper.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Exclude: - - 'test/file_test.rb' - # Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/test/file_test.rb b/test/file_test.rb index d7f5cb8e..90841bfb 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -250,7 +250,10 @@ def test_add_existing_entry_name_replace replacedEntry = nil ::Zip::File.open(TEST_ZIP.zip_name) do |zf| replacedEntry = zf.entries.first.name - zf.add(replacedEntry, 'test/data/file2.txt') { gotCalled = true; true } + zf.add(replacedEntry, 'test/data/file2.txt') do + gotCalled = true + true + end end assert(gotCalled) ::Zip::File.open(TEST_ZIP.zip_name) do |zf| @@ -361,7 +364,10 @@ def test_rename_to_existing_entry_overwrite renamedEntryName = nil ::Zip::File.open(TEST_ZIP.zip_name) do |zf| renamedEntryName = zf.entries[0].name - zf.rename(zf.entries[0], zf.entries[1].name) { gotCalled = true; true } + zf.rename(zf.entries[0], zf.entries[1].name) do + gotCalled = true + true + end end assert(gotCalled) From e7275dad935355b1dacfcf95e18d9b1be7493ec1 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 14 Sep 2019 16:05:23 +0100 Subject: [PATCH 07/56] Fix Style/BlockDelimiters cop errors. --- .rubocop_todo.yml | 11 ----------- test/case_sensitivity_test.rb | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 698aa814..27220d16 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -196,17 +196,6 @@ Style/Alias: - 'lib/zip/ioextras/abstract_input_stream.rb' - 'lib/zip/pass_thru_decompressor.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners. -# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'test/case_sensitivity_test.rb' - # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. diff --git a/test/case_sensitivity_test.rb b/test/case_sensitivity_test.rb index 4aab1667..6ed07069 100644 --- a/test/case_sensitivity_test.rb +++ b/test/case_sensitivity_test.rb @@ -22,11 +22,11 @@ def test_add_case_sensitive zfRead = ::Zip::File.new(EMPTY_FILENAME) assert_equal(SRC_FILES.size, zfRead.entries.length) - SRC_FILES.each_with_index { |a, i| + SRC_FILES.each_with_index do |a, i| assert_equal(a.last, zfRead.entries[i].name) AssertEntry.assert_contents(a.first, zfRead.get_input_stream(a.last) { |zis| zis.read }) - } + end end # Ensure that names are treated case insensitively when adding files and +case_insensitive_match = false+ From 98c6969c18b27995febc504a09403fd2b9f57fd7 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 10:52:06 +0000 Subject: [PATCH 08/56] Fix Layout/SpaceAroundOperators cop. --- .rubocop_todo.yml | 12 ------------ lib/zip/entry.rb | 2 +- lib/zip/extra_field/zip64.rb | 2 +- lib/zip/file.rb | 2 +- lib/zip/filesystem.rb | 6 +++--- lib/zip/input_stream.rb | 2 +- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 27220d16..0e012f16 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -31,18 +31,6 @@ Layout/HashAlignment: - 'lib/zip/file.rb' - 'rubyzip.gemspec' -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. -# SupportedStylesForExponentOperator: space, no_space -Layout/SpaceAroundOperators: - Exclude: - - 'lib/zip/entry.rb' - - 'lib/zip/extra_field/zip64.rb' - - 'lib/zip/file.rb' - - 'lib/zip/filesystem.rb' - - 'lib/zip/input_stream.rb' - # Offense count: 1 Lint/AmbiguousBlockAssociation: Exclude: diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index a24fb791..d936943f 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -99,7 +99,7 @@ def time=(value) @extra.create('UniversalTime') end (@extra['UniversalTime'] || @extra['NTFS']).mtime = value - @time = value + @time = value end def file_type_is?(type) diff --git a/lib/zip/extra_field/zip64.rb b/lib/zip/extra_field/zip64.rb index 962038d8..49fa0813 100644 --- a/lib/zip/extra_field/zip64.rb +++ b/lib/zip/extra_field/zip64.rb @@ -9,7 +9,7 @@ def initialize(binstr = nil) # unparsed binary; we don't actually know what this contains # without looking for FFs in the associated file header # call parse after initializing with a binary string - @content = nil + @content = nil @original_size = nil @compressed_size = nil @relative_header_offset = nil diff --git a/lib/zip/file.rb b/lib/zip/file.rb index 3b8c3338..c609210d 100644 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -75,7 +75,7 @@ class File < CentralDirectory # a new archive if it doesn't exist already. def initialize(path_or_io, create = false, buffer = false, options = {}) super() - options = DEFAULT_OPTIONS.merge(options) + options = DEFAULT_OPTIONS.merge(options) @name = path_or_io.respond_to?(:path) ? path_or_io.path : path_or_io @comment = '' @create = create ? true : false # allow any truthy value to mean true diff --git a/lib/zip/filesystem.rb b/lib/zip/filesystem.rb index 158e7f6f..ef9f76b9 100644 --- a/lib/zip/filesystem.rb +++ b/lib/zip/filesystem.rb @@ -35,9 +35,9 @@ module Zip module FileSystem def initialize # :nodoc: - mappedZip = ZipFileNameMapper.new(self) - @zipFsDir = ZipFsDir.new(mappedZip) - @zipFsFile = ZipFsFile.new(mappedZip) + mappedZip = ZipFileNameMapper.new(self) + @zipFsDir = ZipFsDir.new(mappedZip) + @zipFsFile = ZipFsFile.new(mappedZip) @zipFsDir.file = @zipFsFile @zipFsFile.dir = @zipFsDir end diff --git a/lib/zip/input_stream.rb b/lib/zip/input_stream.rb index b0b7103d..0bf24854 100644 --- a/lib/zip/input_stream.rb +++ b/lib/zip/input_stream.rb @@ -51,7 +51,7 @@ class InputStream # @param offset [Integer] offset in the IO/StringIO def initialize(context, offset = 0, decrypter = nil) super() - @archive_io = get_io(context, offset) + @archive_io = get_io(context, offset) @decompressor = ::Zip::NullDecompressor @decrypter = decrypter || ::Zip::NullDecrypter.new @current_entry = nil From 20743a53b22d04dbd33149329a8d8819a4097bad Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 10:55:41 +0000 Subject: [PATCH 09/56] Fix Lint/AmbiguousBlockAssociation cop. --- .rubocop_todo.yml | 5 ----- test/filesystem/file_nonmutating_test.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0e012f16..5bdd4fcc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -31,11 +31,6 @@ Layout/HashAlignment: - 'lib/zip/file.rb' - 'rubyzip.gemspec' -# Offense count: 1 -Lint/AmbiguousBlockAssociation: - Exclude: - - 'test/filesystem/file_nonmutating_test.rb' - # Offense count: 1 Lint/LiteralAsCondition: Exclude: diff --git a/test/filesystem/file_nonmutating_test.rb b/test/filesystem/file_nonmutating_test.rb index 62486666..e416eec1 100644 --- a/test/filesystem/file_nonmutating_test.rb +++ b/test/filesystem/file_nonmutating_test.rb @@ -439,7 +439,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.is_a? ::Zip::Entry }) result_strings = results.map(&:to_s) missing_matches = expected_results - result_strings From b528cae0849be758ea8b45f978422b99633b5fc6 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 11:01:57 +0000 Subject: [PATCH 10/56] Fix Lint/LiteralAsCondition cop. This fixes Style/InfiniteLoop as a side-effect. --- .rubocop_todo.yml | 11 ----------- lib/zip/ioextras/abstract_input_stream.rb | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5bdd4fcc..d3567a00 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -31,11 +31,6 @@ Layout/HashAlignment: - 'lib/zip/file.rb' - 'rubyzip.gemspec' -# Offense count: 1 -Lint/LiteralAsCondition: - Exclude: - - 'lib/zip/ioextras/abstract_input_stream.rb' - # Offense count: 1 Lint/RescueException: Exclude: @@ -283,12 +278,6 @@ Style/IfUnlessModifier: - 'lib/zip/pass_thru_decompressor.rb' - 'lib/zip/streamable_stream.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/InfiniteLoop: - Exclude: - - 'lib/zip/ioextras/abstract_input_stream.rb' - # Offense count: 1 Style/MixinUsage: Exclude: diff --git a/lib/zip/ioextras/abstract_input_stream.rb b/lib/zip/ioextras/abstract_input_stream.rb index 58678a3f..60743b23 100644 --- a/lib/zip/ioextras/abstract_input_stream.rb +++ b/lib/zip/ioextras/abstract_input_stream.rb @@ -101,7 +101,7 @@ def readline(a_sep_string = $/) end def each_line(a_sep_string = $/) - yield readline(a_sep_string) while true + loop { yield readline(a_sep_string) } rescue EOFError end From cd065d01861d983a6c154559886da46fee00f17e Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 11:08:43 +0000 Subject: [PATCH 11/56] Fix Lint/UnusedBlockArgument cop. --- .rubocop_todo.yml | 7 ------- test/file_test.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d3567a00..72946258 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -47,13 +47,6 @@ Lint/SuppressedException: - 'test/ioextras/abstract_input_stream_test.rb' - 'test/local_entry_test.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. -Lint/UnusedBlockArgument: - Exclude: - - 'test/file_test.rb' - # Offense count: 1 # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. Lint/UselessAccessModifier: diff --git a/test/file_test.rb b/test/file_test.rb index 90841bfb..c08bbdb6 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -131,7 +131,7 @@ def test_open_buffer_no_op_does_not_change_file # Note: this may change the file if it is opened with r+b instead of rb. # The 'extra fields' in this particular zip file get reordered. File.open(test_zip, 'rb') do |file| - Zip::File.open_buffer(file) do |zf| + Zip::File.open_buffer(file) do nil # do nothing end end From e361a47c8e70e3dd51a7d6e5e7b1a4f0f9f84650 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 11:12:16 +0000 Subject: [PATCH 12/56] Configure Lint/UselessComparison cop. Allow this in entry_test.rb so we can test <=>. --- .rubocop.yml | 5 +++++ .rubocop_todo.yml | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cc32da4b..70495c52 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1 +1,6 @@ inherit_from: .rubocop_todo.yml + +# Allow this "useless" test, as we are testing <=> here. +Lint/UselessComparison: + Exclude: + - 'test/entry_test.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 72946258..3c403446 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -53,11 +53,6 @@ Lint/UselessAccessModifier: Exclude: - 'lib/zip/entry.rb' -# Offense count: 1 -Lint/UselessComparison: - Exclude: - - 'test/entry_test.rb' - # Offense count: 120 Metrics/AbcSize: Max: 60 From 23ba1af4fb42b91d22f2ed78f4cfe2d3321d407d Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 11:15:17 +0000 Subject: [PATCH 13/56] Fix Lint/RescueException cop. --- .rubocop_todo.yml | 5 ----- test/output_stream_test.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3c403446..dbdbffdb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -31,11 +31,6 @@ Layout/HashAlignment: - 'lib/zip/file.rb' - 'rubyzip.gemspec' -# Offense count: 1 -Lint/RescueException: - Exclude: - - 'test/output_stream_test.rb' - # Offense count: 12 # Configuration parameters: AllowComments. Lint/SuppressedException: diff --git a/test/output_stream_test.rb b/test/output_stream_test.rb index a7725e22..f3875266 100644 --- a/test/output_stream_test.rb +++ b/test/output_stream_test.rb @@ -57,7 +57,7 @@ def test_cannot_open_file name = TestFiles::EMPTY_TEST_DIR begin ::Zip::OutputStream.open(name) - rescue Exception + rescue SystemCallError assert($!.kind_of?(Errno::EISDIR) || # Linux $!.kind_of?(Errno::EEXIST) || # Windows/cygwin $!.kind_of?(Errno::EACCES), # Windows From 0d4942171127d70c34898ad445db81153e755969 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 11:17:05 +0000 Subject: [PATCH 14/56] Fix Lint/UselessAccessModifier cop. --- .rubocop_todo.yml | 6 ------ lib/zip/entry.rb | 2 -- 2 files changed, 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dbdbffdb..70ca6576 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -42,12 +42,6 @@ Lint/SuppressedException: - 'test/ioextras/abstract_input_stream_test.rb' - 'test/local_entry_test.rb' -# Offense count: 1 -# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. -Lint/UselessAccessModifier: - Exclude: - - 'lib/zip/entry.rb' - # Offense count: 120 Metrics/AbcSize: Max: 60 diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index d936943f..155b136e 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -226,8 +226,6 @@ def read_local_entry(io) end end - public - def unpack_local_entry(buf) @header_signature, @version, From fff2c41d68e92d6be15449f9604280d30426ce3c Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 11:27:11 +0000 Subject: [PATCH 15/56] Configure Lint/SuppressedException cop. In the tests we can say "anything goes", but in the main body of the code we should at least comment if we're not handling an exception fully. --- .rubocop.yml | 7 +++++++ .rubocop_todo.yml | 11 ----------- lib/zip/ioextras/abstract_input_stream.rb | 1 + 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 70495c52..111c7549 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,12 @@ inherit_from: .rubocop_todo.yml +# In some cases we just need to catch an exception, rather than +# actually handle it. Allow the tests to make use of this shortcut. +Lint/SuppressedException: + AllowComments: true + Exclude: + - 'test/**/*.rb' + # Allow this "useless" test, as we are testing <=> here. Lint/UselessComparison: Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 70ca6576..f6e1112a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -31,17 +31,6 @@ Layout/HashAlignment: - 'lib/zip/file.rb' - 'rubyzip.gemspec' -# Offense count: 12 -# Configuration parameters: AllowComments. -Lint/SuppressedException: - Exclude: - - 'lib/zip/ioextras/abstract_input_stream.rb' - - 'test/central_directory_entry_test.rb' - - 'test/central_directory_test.rb' - - 'test/errors_test.rb' - - 'test/ioextras/abstract_input_stream_test.rb' - - 'test/local_entry_test.rb' - # Offense count: 120 Metrics/AbcSize: Max: 60 diff --git a/lib/zip/ioextras/abstract_input_stream.rb b/lib/zip/ioextras/abstract_input_stream.rb index 60743b23..d2c0db38 100644 --- a/lib/zip/ioextras/abstract_input_stream.rb +++ b/lib/zip/ioextras/abstract_input_stream.rb @@ -103,6 +103,7 @@ def readline(a_sep_string = $/) def each_line(a_sep_string = $/) loop { yield readline(a_sep_string) } rescue EOFError + # We just need to catch this; we don't need to handle it. end alias_method :each, :each_line From cfe4972e712b36d351b6fb7eb189d28e59902ef2 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 13:13:21 +0000 Subject: [PATCH 16/56] Fix Layout/EmptyLineAfterGuardClause cop. --- .rubocop_todo.yml | 5 ----- lib/zip/central_directory.rb | 4 ++++ lib/zip/crypto/decrypted_io.rb | 1 + lib/zip/entry.rb | 14 ++++++++++++++ lib/zip/entry_set.rb | 2 ++ lib/zip/extra_field.rb | 2 ++ lib/zip/extra_field/generic.rb | 2 ++ lib/zip/extra_field/ntfs.rb | 4 ++++ lib/zip/extra_field/old_unix.rb | 2 ++ lib/zip/extra_field/universal_time.rb | 3 +++ lib/zip/extra_field/unix.rb | 2 ++ lib/zip/extra_field/zip64.rb | 2 ++ lib/zip/file.rb | 7 +++++++ lib/zip/filesystem.rb | 11 +++++++++++ lib/zip/inflater.rb | 2 ++ lib/zip/input_stream.rb | 3 +++ lib/zip/ioextras/abstract_input_stream.rb | 4 ++++ lib/zip/output_stream.rb | 6 ++++++ lib/zip/streamable_stream.rb | 1 + samples/zipfind.rb | 1 + test/file_split_test.rb | 1 + test/file_test.rb | 1 + test/gentestfiles.rb | 1 + 23 files changed, 76 insertions(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f6e1112a..8ecc67db 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,11 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 76 -# Cop supports --auto-correct. -Layout/EmptyLineAfterGuardClause: - Enabled: false - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/lib/zip/central_directory.rb b/lib/zip/central_directory.rb index 0b6874ef..54ada42e 100644 --- a/lib/zip/central_directory.rb +++ b/lib/zip/central_directory.rb @@ -141,6 +141,7 @@ def read_from_stream(io) #:nodoc: def get_e_o_c_d(buf) #:nodoc: sig_index = buf.rindex([END_OF_CDS].pack('V')) raise Error, 'Zip end of central directory signature not found' unless sig_index + buf = buf.slice!((sig_index + 4)..(buf.bytesize)) def buf.read(count) @@ -166,8 +167,10 @@ def start_buf(io) def get_64_e_o_c_d(buf) #:nodoc: zip_64_start = buf.rindex([ZIP64_END_OF_CDS].pack('V')) raise Error, 'Zip64 end of central directory signature not found' unless zip_64_start + zip_64_locator = buf.rindex([ZIP64_EOCD_LOCATOR].pack('V')) raise Error, 'Zip64 end of central directory signature locator not found' unless zip_64_locator + buf = buf.slice!((zip_64_start + 4)..zip_64_locator) def buf.read(count) @@ -198,6 +201,7 @@ def self.read_from_stream(io) #:nodoc: def ==(other) #:nodoc: return false unless other.kind_of?(CentralDirectory) + @entry_set.entries.sort == other.entries.sort && comment == other.comment end end diff --git a/lib/zip/crypto/decrypted_io.rb b/lib/zip/crypto/decrypted_io.rb index 1dab17c0..cddce8a8 100644 --- a/lib/zip/crypto/decrypted_io.rb +++ b/lib/zip/crypto/decrypted_io.rb @@ -12,6 +12,7 @@ def read(length = nil, outbuf = +'') while length.nil? || (buffer.bytesize < length) break if input_finished? + buffer << produce_input end diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 155b136e..bed82f85 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -48,6 +48,7 @@ def set_default_vars_values def check_name(name) return unless name.start_with?('/') + raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /" end @@ -104,6 +105,7 @@ def time=(value) def file_type_is?(type) raise InternalError, "current filetype is unknown: #{inspect}" unless @ftype + @ftype == type end @@ -124,6 +126,7 @@ def name_is_directory? #:nodoc:all def name_safe? cleanpath = Pathname.new(@name).cleanpath return false unless cleanpath.relative? + root = ::File::SEPARATOR naive_expanded_path = ::File.join(root, cleanpath.to_s) ::File.absolute_path(cleanpath.to_s, root) == naive_expanded_path @@ -153,6 +156,7 @@ def calculate_local_header_size #:nodoc:all # that we didn't change the header size (and thus clobber file data or something) def verify_local_header_size! return if @local_header_size.nil? + new_size = calculate_local_header_size raise Error, "local header size changed (#{@local_header_size} -> #{new_size})" if @local_header_size != new_size end @@ -255,6 +259,7 @@ def read_local_entry(io) #:nodoc:all unless @header_signature == ::Zip::LOCAL_ENTRY_SIGNATURE raise ::Zip::Error, "Zip local header magic not found at location '#{local_header_offset}'" end + set_time(@last_mod_date, @last_mod_time) @name = io.read(@name_length) @@ -274,6 +279,7 @@ def read_local_entry(io) #:nodoc:all @extra = ::Zip::ExtraField.new(extra) end end + parse_zip64_extra(true) @local_header_size = calculate_local_header_size end @@ -360,16 +366,19 @@ def set_ftype_from_c_dir_entry def check_c_dir_entry_static_header_length(buf) return if buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH + raise Error, 'Premature end of file. Not enough data for zip cdir entry header' end def check_c_dir_entry_signature return if header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE + raise Error, "Zip local header magic not found at location '#{local_header_offset}'" end def check_c_dir_entry_comment_size return if @comment && @comment.bytesize == @comment_length + raise ::Zip::Error, 'Truncated cdir zip entry header' end @@ -408,6 +417,7 @@ def file_stat(path) # :nodoc: def get_extra_attributes_from_path(path) # :nodoc: return if Zip::RUNNING_ON_WINDOWS + stat = file_stat(path) @unix_uid = stat.uid @unix_gid = stat.gid @@ -494,6 +504,7 @@ def write_c_dir_entry(io) #:nodoc:all def ==(other) return false unless other.class == self.class + # Compares contents of local entry and exposed fields keys_equal = %w[compression_method crc compressed_size size name extra filepath].all? do |k| other.__send__(k.to_sym) == __send__(k.to_sym) @@ -635,6 +646,7 @@ def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exi def create_directory(dest_path) return if ::File.directory?(dest_path) + if ::File.exist?(dest_path) if block_given? && yield(self, dest_path) ::FileUtils.rm_f dest_path @@ -659,6 +671,7 @@ def create_symlink(dest_path) # (required when file sizes exceed 2**32, but can be used for all files) def parse_zip64_extra(for_local_header) #:nodoc:all return if @extra['Zip64'].nil? + if for_local_header @size, @compressed_size = @extra['Zip64'].parse(@size, @compressed_size) else @@ -673,6 +686,7 @@ def data_descriptor_size # create a zip64 extra information field if we need one def prep_zip64_extra(for_local_header) #:nodoc:all return unless ::Zip.write_zip64_support + need_zip64 = @size >= 0xFFFFFFFF || @compressed_size >= 0xFFFFFFFF need_zip64 ||= @local_header_offset >= 0xFFFFFFFF unless for_local_header if need_zip64 diff --git a/lib/zip/entry_set.rb b/lib/zip/entry_set.rb index 3272b2a4..9c503781 100644 --- a/lib/zip/entry_set.rb +++ b/lib/zip/entry_set.rb @@ -50,6 +50,7 @@ def dup def ==(other) return false unless other.kind_of?(EntrySet) + @entry_set.values == other.entry_set.values end @@ -60,6 +61,7 @@ def parent(entry) def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB) entries.map do |entry| next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags) + yield(entry) if block_given? entry end.compact diff --git a/lib/zip/extra_field.rb b/lib/zip/extra_field.rb index 0dcf0d5e..b8bb8a5f 100644 --- a/lib/zip/extra_field.rb +++ b/lib/zip/extra_field.rb @@ -36,6 +36,7 @@ class << s def merge(binstr) return if binstr.empty? + i = 0 while i < binstr.bytesize id = binstr[i, 2] @@ -54,6 +55,7 @@ def create(name) unless (field_class = ID_MAP.values.find { |k| k.name == name }) raise Error, "Unknown extra field '#{name}'" end + self[name] = field_class.new end diff --git a/lib/zip/extra_field/generic.rb b/lib/zip/extra_field/generic.rb index d61137fe..0bb000b3 100644 --- a/lib/zip/extra_field/generic.rb +++ b/lib/zip/extra_field/generic.rb @@ -19,11 +19,13 @@ def initial_parse(binstr) warn 'WARNING: weird extra field header ID. Skip parsing it.' return false end + [binstr[2, 2].unpack('v')[0], binstr[4..-1]] end def ==(other) return false if self.class != other.class + each do |k, v| return false if v != other[k] end diff --git a/lib/zip/extra_field/ntfs.rb b/lib/zip/extra_field/ntfs.rb index 687704d8..f4f11b2d 100644 --- a/lib/zip/extra_field/ntfs.rb +++ b/lib/zip/extra_field/ntfs.rb @@ -19,6 +19,7 @@ def initialize(binstr = nil) def merge(binstr) return if binstr.empty? + size, content = initial_parse(binstr) (size && content) || return @@ -27,6 +28,7 @@ def merge(binstr) tag1 = tags[1] return unless tag1 + ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q= 5 # how many times should we retry? + retried += 1 retry end diff --git a/lib/zip/input_stream.rb b/lib/zip/input_stream.rb index 0bf24854..8d86897c 100644 --- a/lib/zip/input_stream.rb +++ b/lib/zip/input_stream.rb @@ -73,6 +73,7 @@ def get_next_entry # Rewinds the stream to the beginning of the current entry def rewind return if @current_entry.nil? + @lineno = 0 @pos = 0 @archive_io.seek(@current_entry.local_header_offset, IO::SEEK_SET) @@ -91,6 +92,7 @@ class << self def open(filename_or_io, offset = 0, decrypter = nil) zio = new(filename_or_io, offset, decrypter) return zio unless block_given? + begin yield zio ensure @@ -123,6 +125,7 @@ def open_entry if @current_entry && @current_entry.encrypted? && @decrypter.is_a?(NullEncrypter) raise Error, 'password required to decode zip file' end + if @current_entry && @current_entry.incomplete? && @current_entry.crc == 0 \ && @current_entry.compressed_size == 0 \ && @current_entry.size == 0 && !@complete_entry diff --git a/lib/zip/ioextras/abstract_input_stream.rb b/lib/zip/ioextras/abstract_input_stream.rb index d2c0db38..e3cf9839 100644 --- a/lib/zip/ioextras/abstract_input_stream.rb +++ b/lib/zip/ioextras/abstract_input_stream.rb @@ -35,6 +35,7 @@ def read(number_of_bytes = nil, buf = '') if tbuf.nil? || tbuf.empty? return nil if number_of_bytes + return '' end @@ -69,6 +70,7 @@ def gets(a_sep_string = $/, number_of_bytes = nil) end return read(number_of_bytes) if a_sep_string.nil? + a_sep_string = "#{$/}#{$/}" if a_sep_string.empty? buffer_index = 0 @@ -76,6 +78,7 @@ def gets(a_sep_string = $/, number_of_bytes = nil) while (match_index = @output_buffer.index(a_sep_string, buffer_index)).nil? && !over_limit buffer_index = [buffer_index, @output_buffer.bytesize - a_sep_string.bytesize].max return @output_buffer.empty? ? nil : flush if input_finished? + @output_buffer << produce_input over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes) end @@ -97,6 +100,7 @@ def flush def readline(a_sep_string = $/) ret_val = gets(a_sep_string) raise EOFError unless ret_val + ret_val end diff --git a/lib/zip/output_stream.rb b/lib/zip/output_stream.rb index d9bbc4df..6ab4a484 100644 --- a/lib/zip/output_stream.rb +++ b/lib/zip/output_stream.rb @@ -49,6 +49,7 @@ def initialize(file_name, stream = false, encrypter = nil) class << self def open(file_name, encrypter = nil) return new(file_name) unless block_given? + zos = new(file_name, false, encrypter) yield zos ensure @@ -66,6 +67,7 @@ def write_buffer(io = ::StringIO.new(''), encrypter = nil) # Closes the stream and writes the central directory to the zip file def close return if @closed + finalize_current_entry update_local_headers write_central_directory @@ -76,6 +78,7 @@ def close # Closes the stream and writes the central directory to the zip file def close_buffer return @output_stream if @closed + finalize_current_entry update_local_headers write_central_directory @@ -87,6 +90,7 @@ def close_buffer # +entry+ can be a ZipEntry object or a string. def put_next_entry(entry_name, comment = nil, extra = nil, compression_method = Entry::DEFLATED, level = Zip.default_compression) raise Error, 'zip stream is closed' if @closed + new_entry = if entry_name.kind_of?(Entry) entry_name else @@ -105,6 +109,7 @@ 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) + finalize_current_entry @entry_set << entry src_pos = entry.local_header_offset @@ -123,6 +128,7 @@ def copy_raw_entry(entry) def finalize_current_entry return unless @current_entry + finish @current_entry.compressed_size = @output_stream.tell - @current_entry.local_header_offset - @current_entry.calculate_local_header_size @current_entry.size = @compressor.size diff --git a/lib/zip/streamable_stream.rb b/lib/zip/streamable_stream.rb index 642ddae2..90a44447 100644 --- a/lib/zip/streamable_stream.rb +++ b/lib/zip/streamable_stream.rb @@ -22,6 +22,7 @@ def get_input_stream unless @temp_file.closed? raise StandardError, "cannot open entry for reading while its open for writing - #{name}" end + @temp_file.open # reopens tempfile from top @temp_file.binmode if block_given? diff --git a/samples/zipfind.rb b/samples/zipfind.rb index 400e0a69..cd76c264 100755 --- a/samples/zipfind.rb +++ b/samples/zipfind.rb @@ -13,6 +13,7 @@ def self.find(path, zipFilePattern = /\.zip$/i) 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) diff --git a/test/file_split_test.rb b/test/file_split_test.rb index dfea837d..c488f180 100644 --- a/test/file_split_test.rb +++ b/test/file_split_test.rb @@ -28,6 +28,7 @@ def test_split result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false) return if result.nil? + Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index| File.open(zip_file_name, 'rb') do |zip_file| zip_file.read([::Zip::File::SPLIT_SIGNATURE].pack('V').size) if index == 0 diff --git a/test/file_test.rb b/test/file_test.rb index c08bbdb6..fb7ec5cc 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -623,6 +623,7 @@ def test_streaming Zip::File.open_buffer(f) do |zipfile| zipfile.each do |entry| next unless entry.name =~ /README.md/ + data = zipfile.read(entry) end end diff --git a/test/gentestfiles.rb b/test/gentestfiles.rb index 3e76e7d0..bb803b99 100755 --- a/test/gentestfiles.rb +++ b/test/gentestfiles.rb @@ -52,6 +52,7 @@ def create_random_binary(filename, size) def ensure_dir(name) if File.exist?(name) return if File.stat(name).directory? + File.delete(name) end Dir.mkdir(name) From 61c83b2a1a5e3050c1452021c794ece4c9021af4 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 13:25:04 +0000 Subject: [PATCH 17/56] Configure Layout/HashAlignment cop. --- .rubocop.yml | 4 +++ .rubocop_todo.yml | 12 -------- lib/zip/constants.rb | 36 ++++++++++++------------ test/filesystem/file_nonmutating_test.rb | 8 ++++-- test/path_traversal_test.rb | 14 ++++----- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 111c7549..ccc55719 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,9 @@ inherit_from: .rubocop_todo.yml +Layout/HashAlignment: + EnforcedHashRocketStyle: table + EnforcedColonStyle: table + # In some cases we just need to catch an exception, rather than # actually handle it. Allow the tests to make use of this shortcut. Lint/SuppressedException: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8ecc67db..85630180 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,18 +14,6 @@ Layout/EmptyLinesAroundClassBody: Exclude: - 'test/extra_field_ut_test.rb' -# Offense count: 26 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'lib/zip/constants.rb' - - 'lib/zip/file.rb' - - 'rubyzip.gemspec' - # Offense count: 120 Metrics/AbcSize: Max: 60 diff --git a/lib/zip/constants.rb b/lib/zip/constants.rb index 6feda25d..428c5126 100644 --- a/lib/zip/constants.rb +++ b/lib/zip/constants.rb @@ -87,29 +87,29 @@ module Zip COMPRESSION_METHOD_AES = 99 COMPRESSION_METHODS = { - COMPRESSION_METHOD_STORE => 'Store (no compression)', - COMPRESSION_METHOD_SHRINK => 'Shrink', - COMPRESSION_METHOD_REDUCE_1 => 'Reduce with compression factor 1', - COMPRESSION_METHOD_REDUCE_2 => 'Reduce with compression factor 2', - COMPRESSION_METHOD_REDUCE_3 => 'Reduce with compression factor 3', - COMPRESSION_METHOD_REDUCE_4 => 'Reduce with compression factor 4', - COMPRESSION_METHOD_IMPLODE => 'Implode', + COMPRESSION_METHOD_STORE => 'Store (no compression)', + COMPRESSION_METHOD_SHRINK => 'Shrink', + COMPRESSION_METHOD_REDUCE_1 => 'Reduce with compression factor 1', + COMPRESSION_METHOD_REDUCE_2 => 'Reduce with compression factor 2', + COMPRESSION_METHOD_REDUCE_3 => 'Reduce with compression factor 3', + COMPRESSION_METHOD_REDUCE_4 => 'Reduce with compression factor 4', + COMPRESSION_METHOD_IMPLODE => 'Implode', # RESERVED = 7 - COMPRESSION_METHOD_DEFLATE => 'Deflate', - COMPRESSION_METHOD_DEFLATE_64 => 'Deflate64(tm)', + COMPRESSION_METHOD_DEFLATE => 'Deflate', + COMPRESSION_METHOD_DEFLATE_64 => 'Deflate64(tm)', COMPRESSION_METHOD_PKWARE_DCLI => 'PKWARE Data Compression Library Imploding (old IBM TERSE)', # RESERVED = 11 - COMPRESSION_METHOD_BZIP2 => 'BZIP2', + COMPRESSION_METHOD_BZIP2 => 'BZIP2', # RESERVED = 13 - COMPRESSION_METHOD_LZMA => 'LZMA', + COMPRESSION_METHOD_LZMA => 'LZMA', # RESERVED = 15 - COMPRESSION_METHOD_IBM_CMPSC => 'IBM z/OS CMPSC Compression', + COMPRESSION_METHOD_IBM_CMPSC => 'IBM z/OS CMPSC Compression', # RESERVED = 17 - COMPRESSION_METHOD_IBM_TERSE => 'IBM TERSE (new)', - COMPRESSION_METHOD_IBM_LZ77 => 'IBM LZ77 z Architecture (PFS)', - COMPRESSION_METHOD_JPEG => 'JPEG variant', - COMPRESSION_METHOD_WAVPACK => 'WavPack compressed data', - COMPRESSION_METHOD_PPMD => 'PPMd version I, Rev 1', - COMPRESSION_METHOD_AES => 'AES encryption', + COMPRESSION_METHOD_IBM_TERSE => 'IBM TERSE (new)', + COMPRESSION_METHOD_IBM_LZ77 => 'IBM LZ77 z Architecture (PFS)', + COMPRESSION_METHOD_JPEG => 'JPEG variant', + COMPRESSION_METHOD_WAVPACK => 'WavPack compressed data', + COMPRESSION_METHOD_PPMD => 'PPMd version I, Rev 1', + COMPRESSION_METHOD_AES => 'AES encryption', }.freeze end diff --git a/test/filesystem/file_nonmutating_test.rb b/test/filesystem/file_nonmutating_test.rb index e416eec1..af575fac 100644 --- a/test/filesystem/file_nonmutating_test.rb +++ b/test/filesystem/file_nonmutating_test.rb @@ -434,9 +434,11 @@ def test_glob ::Zip::File.open('test/data/globTest.zip') do |zf| { 'globTest/foo.txt' => ['globTest/foo.txt'], - '*/foo.txt' => ['globTest/foo.txt'], - '**/foo.txt' => ['globTest/foo.txt', 'globTest/foo/bar/baz/foo.txt'], - '*/foo/**/*.txt' => ['globTest/foo/bar/baz/foo.txt'] + '*/foo.txt' => ['globTest/foo.txt'], + '**/foo.txt' => [ + 'globTest/foo.txt', 'globTest/foo/bar/baz/foo.txt' + ], + '*/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 }) diff --git a/test/path_traversal_test.rb b/test/path_traversal_test.rb index 6950fbcb..47c7e30f 100644 --- a/test/path_traversal_test.rb +++ b/test/path_traversal_test.rb @@ -62,7 +62,7 @@ def test_leading_dot_dot def test_non_leading_dot_dot_with_existing_folder entries = { - 'tmp/' => '', + 'tmp/' => '', 'tmp/../../moo' => /WARNING: skipped \'tmp\/\.\.\/\.\.\/moo\'/ } in_tmpdir do @@ -92,7 +92,7 @@ def test_file_symlink def test_directory_symlink # Can't create tmp/moo, because the tmp symlink is skipped. entries = { - 'tmp' => /WARNING: skipped symlink \'tmp\'/, + 'tmp' => /WARNING: skipped symlink \'tmp\'/, 'tmp/moo' => :error } in_tmpdir do @@ -104,8 +104,8 @@ def test_directory_symlink def test_two_directory_symlinks_a # Can't create par/moo because the symlinks are skipped. entries = { - 'cur' => /WARNING: skipped symlink \'cur\'/, - 'par' => /WARNING: skipped symlink \'par\'/, + 'cur' => /WARNING: skipped symlink \'cur\'/, + 'par' => /WARNING: skipped symlink \'par\'/, 'par/moo' => :error } in_tmpdir do @@ -119,7 +119,7 @@ def test_two_directory_symlinks_a def test_two_directory_symlinks_b # Can't create par/moo, because the symlinks are skipped. entries = { - 'cur' => /WARNING: skipped symlink \'cur\'/, + 'cur' => /WARNING: skipped symlink \'cur\'/, 'cur/par' => /WARNING: skipped symlink \'cur\/par\'/, 'par/moo' => :error } @@ -132,7 +132,7 @@ def test_two_directory_symlinks_b def test_entry_name_with_absolute_path_does_not_extract entries = { - '/tmp/' => /WARNING: skipped \'\/tmp\/\'/, + '/tmp/' => /WARNING: skipped \'\/tmp\/\'/, '/tmp/file.txt' => /WARNING: skipped \'\/tmp\/file.txt\'/ } in_tmpdir do @@ -156,7 +156,7 @@ def test_entry_name_with_absolute_path_extract_when_given_different_path def test_entry_name_with_relative_symlink # Doesn't create the symlink path, so can't create path/file.txt. entries = { - 'path' => /WARNING: skipped symlink \'path\'/, + 'path' => /WARNING: skipped symlink \'path\'/, 'path/file.txt' => :error } in_tmpdir do From 68259ed7b01ea50ab24a427cd42bca01ebd33077 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 14:57:28 +0000 Subject: [PATCH 18/56] Fix Style/Encoding cop. --- .rubocop_todo.yml | 8 -------- rubyzip.gemspec | 2 -- test/errors_test.rb | 2 -- test/unicode_file_names_and_comments_test.rb | 2 -- 4 files changed, 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 85630180..c6c22138 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -161,14 +161,6 @@ Style/CommentedKeyword: Style/Documentation: Enabled: false -# Offense count: 3 -# Cop supports --auto-correct. -Style/Encoding: - Exclude: - - 'rubyzip.gemspec' - - 'test/errors_test.rb' - - 'test/unicode_file_names_and_comments_test.rb' - # Offense count: 2 Style/EvalWithLocation: Exclude: diff --git a/rubyzip.gemspec b/rubyzip.gemspec index 5b08a597..59c04c91 100644 --- a/rubyzip.gemspec +++ b/rubyzip.gemspec @@ -1,5 +1,3 @@ -#-*- encoding: utf-8 -*- - lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'zip/version' diff --git a/test/errors_test.rb b/test/errors_test.rb index 2c6adb2f..5e6260f8 100644 --- a/test/errors_test.rb +++ b/test/errors_test.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'test_helper' class ErrorsTest < MiniTest::Test diff --git a/test/unicode_file_names_and_comments_test.rb b/test/unicode_file_names_and_comments_test.rb index aac3e256..4d2fc20f 100644 --- a/test/unicode_file_names_and_comments_test.rb +++ b/test/unicode_file_names_and_comments_test.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'test_helper' class ZipUnicodeFileNamesAndComments < MiniTest::Test From 70d036b3ad32e533b21881c23bd06e1ede8eeb0f Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 15 Sep 2019 17:06:27 +0100 Subject: [PATCH 19/56] Fix Style/ExpandPathArguments cop. --- .rubocop_todo.yml | 6 ------ rubyzip.gemspec | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c6c22138..9b89750c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -166,12 +166,6 @@ Style/EvalWithLocation: Exclude: - 'test/test_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/ExpandPathArguments: - Exclude: - - 'rubyzip.gemspec' - # Offense count: 1 # Configuration parameters: EnforcedStyle. # SupportedStyles: left_coerce, right_coerce, single_coerce, fdiv diff --git a/rubyzip.gemspec b/rubyzip.gemspec index 59c04c91..1707ef5d 100644 --- a/rubyzip.gemspec +++ b/rubyzip.gemspec @@ -1,4 +1,4 @@ -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'zip/version' From 6544563dd0828f884ecc177265ea0b06af42d38f Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 15:08:24 +0000 Subject: [PATCH 20/56] Configure Style/ZeroLengthPredicate so it doesn't misfire. --- .rubocop.yml | 7 +++++++ .rubocop_todo.yml | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ccc55719..36e8cf2e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,3 +15,10 @@ Lint/SuppressedException: Lint/UselessComparison: Exclude: - 'test/entry_test.rb' + +# Turn this cop off for these files as it fires for objects without +# an empty? method. +Style/ZeroLengthPredicate: + Exclude: + - 'lib/zip/file.rb' + - 'lib/zip/input_stream.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9b89750c..fe523ebb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -437,13 +437,6 @@ Style/UnpackFirst: - 'lib/zip/extra_field/generic.rb' - 'lib/zip/extra_field/zip64.rb' -# Offense count: 3 -# Cop supports --auto-correct. -Style/ZeroLengthPredicate: - Exclude: - - 'lib/zip/file.rb' - - 'lib/zip/input_stream.rb' - # Offense count: 247 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. From 19aa7e834c5613d1565e67784b902ba96c4b60e2 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 15 Sep 2019 17:36:50 +0100 Subject: [PATCH 21/56] Fix Style/RescueStandardError cop. --- .rubocop_todo.yml | 8 -------- test/gentestfiles.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fe523ebb..aef8638b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -312,14 +312,6 @@ Style/RegexpLiteral: - 'test/path_traversal_test.rb' - 'test/settings_test.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'test/gentestfiles.rb' - # Offense count: 17 # Cop supports --auto-correct. # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. diff --git a/test/gentestfiles.rb b/test/gentestfiles.rb index bb803b99..a50f51d5 100755 --- a/test/gentestfiles.rb +++ b/test/gentestfiles.rb @@ -107,7 +107,7 @@ def self.create_test_zips raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}") raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}") - rescue + rescue StandardError # If there are any Windows developers wanting to use a command line zip.exe # to help create the following files, there's a free one available from # http://stahlworks.com/dev/index.php?tool=zipunzip From 5a1baf46ab41299932a1eb8d50c96ffa9aff06ad Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 15 Sep 2019 17:40:12 +0100 Subject: [PATCH 22/56] Fix Style/RedundantReturn cop. --- .rubocop_todo.yml | 7 ------- lib/zip/central_directory.rb | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index aef8638b..a78a480d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -294,13 +294,6 @@ Style/NumericPredicate: - 'test/file_split_test.rb' - 'test/test_helper.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/zip/central_directory.rb' - # Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, AllowInnerSlashes. diff --git a/lib/zip/central_directory.rb b/lib/zip/central_directory.rb index 54ada42e..04e0b1e6 100644 --- a/lib/zip/central_directory.rb +++ b/lib/zip/central_directory.rb @@ -194,9 +194,9 @@ def size def self.read_from_stream(io) #:nodoc: cdir = new cdir.read_from_stream(io) - return cdir + cdir rescue Error - return nil + nil end def ==(other) #:nodoc: From b3c4c37882e761ee8976045484286fcf5eba1e30 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 15 Sep 2019 19:01:57 +0100 Subject: [PATCH 23/56] Fix Style/NonNilCheck cop. Use the `refute_nil` method for most of these. --- .rubocop_todo.yml | 9 --------- test/case_sensitivity_test.rb | 2 +- test/file_test.rb | 16 ++++++++-------- test/settings_test.rb | 4 ++-- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a78a480d..f04bf510 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -252,15 +252,6 @@ Style/Next: Exclude: - 'lib/zip/entry.rb' -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: IncludeSemanticChanges. -Style/NonNilCheck: - Exclude: - - 'test/case_sensitivity_test.rb' - - 'test/file_test.rb' - - 'test/settings_test.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedOctalStyle. diff --git a/test/case_sensitivity_test.rb b/test/case_sensitivity_test.rb index 6ed07069..7749e06b 100644 --- a/test/case_sensitivity_test.rb +++ b/test/case_sensitivity_test.rb @@ -63,7 +63,7 @@ def test_add_case_sensitive_read_case_insensitive private def assert_contains(zf, entryName, filename = entryName) - assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}") + refute_nil(zf.entries.detect { |e| e.name == entryName }, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}") assert_entry_contents(zf, entryName, filename) if File.exist?(filename) end end diff --git a/test/file_test.rb b/test/file_test.rb index fb7ec5cc..392a5027 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -432,8 +432,8 @@ def test_commit zf.commit zfRead = ::Zip::File.new(TEST_ZIP.zip_name) - assert(zfRead.entries.detect { |e| e.name == newName } != nil) - assert(zfRead.entries.detect { |e| e.name == oldName }.nil?) + refute_nil(zfRead.entries.detect { |e| e.name == newName }) + assert_nil(zfRead.entries.detect { |e| e.name == oldName }) zfRead.close zf.close @@ -451,8 +451,8 @@ def test_double_commit(filename = 'test/data/generated/double_commit_test.zip') zf.commit zf.close zf2 = ::Zip::File.open(filename) - assert(zf2.entries.detect { |e| e.name == 'test1.txt' } != nil) - assert(zf2.entries.detect { |e| e.name == 'test2.txt' } != nil) + refute_nil(zf2.entries.detect { |e| e.name == 'test1.txt' }) + refute_nil(zf2.entries.detect { |e| e.name == 'test2.txt' }) res = system("unzip -tqq #{filename}") assert_equal(res, true) end @@ -471,8 +471,8 @@ def test_write_buffer buffer = zf.write_buffer(io) File.open(TEST_ZIP.zip_name, 'wb') { |f| f.write buffer.string } zfRead = ::Zip::File.new(TEST_ZIP.zip_name) - assert(zfRead.entries.detect { |e| e.name == newName } != nil) - assert(zfRead.entries.detect { |e| e.name == oldName }.nil?) + refute_nil(zfRead.entries.detect { |e| e.name == newName }) + assert_nil(zfRead.entries.detect { |e| e.name == oldName }) zfRead.close zf.close @@ -678,11 +678,11 @@ def test_find_get_entry private def assert_contains(zf, entryName, filename = entryName) - assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}") + refute_nil(zf.entries.detect { |e| e.name == entryName }, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}") assert_entry_contents(zf, entryName, filename) if File.exist?(filename) end def assert_not_contains(zf, entryName) - assert(zf.entries.detect { |e| e.name == entryName }.nil?, "entry #{entryName} in #{zf.entries.join(', ')} in zip file #{zf}") + assert_nil(zf.entries.detect { |e| e.name == entryName }, "entry #{entryName} in #{zf.entries.join(', ')} in zip file #{zf}") end end diff --git a/test/settings_test.rb b/test/settings_test.rb index 7c1331a6..ab5aa223 100644 --- a/test/settings_test.rb +++ b/test/settings_test.rb @@ -18,7 +18,7 @@ def teardown end def open_zip(&aProc) - assert(!aProc.nil?) + refute_nil(aProc) ::Zip::File.open(TestZipFile::TEST_ZIP4.zip_name, &aProc) end @@ -89,7 +89,7 @@ def test_true_warn_invalid_date private def assert_contains(zf, entryName, filename = entryName) - assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}") + refute_nil(zf.entries.detect { |e| e.name == entryName }, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}") assert_entry_contents(zf, entryName, filename) if File.exist?(filename) end end From b3f241353a43f82453e7f6789e3c5551e001ff8f Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 15:23:35 +0000 Subject: [PATCH 24/56] Fix Style/CommentedKeyword cop. --- .rubocop_todo.yml | 6 ------ lib/zip/ioextras.rb | 2 +- lib/zip/streamable_stream.rb | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f04bf510..cb777371 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -151,12 +151,6 @@ Style/ClassCheck: - 'test/ioextras/fake_io_test.rb' - 'test/output_stream_test.rb' -# Offense count: 2 -Style/CommentedKeyword: - Exclude: - - 'lib/zip/ioextras.rb' - - 'lib/zip/streamable_stream.rb' - # Offense count: 26 Style/Documentation: Enabled: false diff --git a/lib/zip/ioextras.rb b/lib/zip/ioextras.rb index 2412480b..63774d33 100644 --- a/lib/zip/ioextras.rb +++ b/lib/zip/ioextras.rb @@ -25,7 +25,7 @@ def kind_of?(object) object == IO || super end end - end # IOExtras namespace module + end end require 'zip/ioextras/abstract_input_stream' diff --git a/lib/zip/streamable_stream.rb b/lib/zip/streamable_stream.rb index 90a44447..1a726b99 100644 --- a/lib/zip/streamable_stream.rb +++ b/lib/zip/streamable_stream.rb @@ -1,5 +1,5 @@ module Zip - class StreamableStream < DelegateClass(Entry) # nodoc:all + class StreamableStream < DelegateClass(Entry) # :nodoc:all def initialize(entry) super(entry) @temp_file = Tempfile.new(::File.basename(name)) From 468a80ce0224ff56ab27eb34c5664d2d59e098c3 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 21 Sep 2019 19:11:37 +0100 Subject: [PATCH 25/56] Fix Style/IfInsideElse cop. --- .rubocop_todo.yml | 6 ------ lib/zip/entry.rb | 10 +++++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cb777371..03f18960 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -189,12 +189,6 @@ Style/GuardClause: - 'samples/zipfind.rb' - 'test/test_helper.rb' -# Offense count: 1 -# Configuration parameters: AllowIfModifier. -Style/IfInsideElse: - Exclude: - - 'lib/zip/entry.rb' - # Offense count: 17 # Cop supports --auto-correct. Style/IfUnlessModifier: diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index bed82f85..d3470e19 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -272,12 +272,12 @@ def read_local_entry(io) #:nodoc:all if extra && extra.bytesize != @extra_length raise ::Zip::Error, 'Truncated local zip entry header' + end + + if @extra.is_a?(::Zip::ExtraField) + @extra.merge(extra) if extra else - if @extra.is_a?(::Zip::ExtraField) - @extra.merge(extra) if extra - else - @extra = ::Zip::ExtraField.new(extra) - end + @extra = ::Zip::ExtraField.new(extra) end parse_zip64_extra(true) From 3121ad066f1eacc008eb3a2468648ea871cd1ac7 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 15:28:30 +0000 Subject: [PATCH 26/56] Fix Style/Alias cop. --- .rubocop_todo.yml | 10 ---------- lib/zip/inflater.rb | 2 +- lib/zip/ioextras/abstract_input_stream.rb | 4 ++-- lib/zip/pass_thru_decompressor.rb | 2 +- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 03f18960..896a891e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -113,16 +113,6 @@ Style/AccessModifierDeclarations: - 'lib/zip/extra_field/zip64.rb' - 'lib/zip/filesystem.rb' -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: prefer_alias, prefer_alias_method -Style/Alias: - Exclude: - - 'lib/zip/inflater.rb' - - 'lib/zip/ioextras/abstract_input_stream.rb' - - 'lib/zip/pass_thru_decompressor.rb' - # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. diff --git a/lib/zip/inflater.rb b/lib/zip/inflater.rb index ff12c10e..f63de688 100644 --- a/lib/zip/inflater.rb +++ b/lib/zip/inflater.rb @@ -23,7 +23,7 @@ def eof @buffer.empty? && input_finished? end - alias_method :eof?, :eof + alias eof? eof private diff --git a/lib/zip/ioextras/abstract_input_stream.rb b/lib/zip/ioextras/abstract_input_stream.rb index e3cf9839..85f4974e 100644 --- a/lib/zip/ioextras/abstract_input_stream.rb +++ b/lib/zip/ioextras/abstract_input_stream.rb @@ -110,13 +110,13 @@ def each_line(a_sep_string = $/) # We just need to catch this; we don't need to handle it. end - alias_method :each, :each_line + alias each each_line def eof @output_buffer.empty? && input_finished? end - alias_method :eof?, :eof + alias eof? eof end end end diff --git a/lib/zip/pass_thru_decompressor.rb b/lib/zip/pass_thru_decompressor.rb index ac21b61e..730882d3 100644 --- a/lib/zip/pass_thru_decompressor.rb +++ b/lib/zip/pass_thru_decompressor.rb @@ -20,7 +20,7 @@ def eof @read_so_far >= decompressed_size end - alias_method :eof?, :eof + alias eof? eof end ::Zip::Decompressor.register(::Zip::COMPRESSION_METHOD_STORE, ::Zip::PassThruDecompressor) From 1b8f1a6f3ca7d9542e3fdb230762cd3af20534e1 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 21 Sep 2019 19:24:52 +0100 Subject: [PATCH 27/56] Fix Naming/RescuedExceptionsVariableName cop. --- .rubocop_todo.yml | 7 ------- samples/zipfind.rb | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 896a891e..6a4e86f3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -91,13 +91,6 @@ Naming/MemoizedInstanceVariableName: Naming/MethodParameterName: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: PreferredName. -Naming/RescuedExceptionsVariableName: - Exclude: - - 'samples/zipfind.rb' - # Offense count: 721 # Configuration parameters: EnforcedStyle. # SupportedStyles: snake_case, camelCase diff --git a/samples/zipfind.rb b/samples/zipfind.rb index cd76c264..7a8ac452 100755 --- a/samples/zipfind.rb +++ b/samples/zipfind.rb @@ -18,8 +18,8 @@ def self.find(path, zipFilePattern = /\.zip$/i) Zip::File.foreach(fileName) do |zipEntry| yield(fileName + File::SEPARATOR + zipEntry.to_s) end - rescue Errno::EACCES => ex - puts ex + rescue Errno::EACCES => e + puts e end end end From bce841639e9d02cb48edff375dc93d883b3ff134 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 21 Sep 2019 19:34:41 +0100 Subject: [PATCH 28/56] Fix Style/MixinUsage cop. --- .rubocop_todo.yml | 5 ----- samples/write_simple.rb | 4 +--- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6a4e86f3..21879bf2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -184,11 +184,6 @@ Style/IfUnlessModifier: - 'lib/zip/pass_thru_decompressor.rb' - 'lib/zip/streamable_stream.rb' -# Offense count: 1 -Style/MixinUsage: - Exclude: - - 'samples/write_simple.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, Autocorrect. diff --git a/samples/write_simple.rb b/samples/write_simple.rb index be2a9704..0c534ede 100755 --- a/samples/write_simple.rb +++ b/samples/write_simple.rb @@ -4,9 +4,7 @@ require 'zip' -include Zip - -OutputStream.open('simple.zip') do |zos| +::Zip::OutputStream.open('simple.zip') do |zos| zos.put_next_entry 'entry.txt' zos.puts 'Hello world' end From 45f4c2dc29a388ef4510eb186f0240d91d8d4f95 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 15:50:00 +0000 Subject: [PATCH 29/56] Fix Style/GuardClause cop. --- .rubocop_todo.yml | 9 --------- lib/zip/entry.rb | 17 ++++++----------- lib/zip/extra_field/generic.rb | 13 ++++++------- samples/zipfind.rb | 8 ++++---- test/test_helper.rb | 25 ++++++++++++------------- 5 files changed, 28 insertions(+), 44 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 21879bf2..b35b103e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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: diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index d3470e19..0801ad26 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -182,12 +182,9 @@ def extract(dest_path = nil, &block) 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 @@ def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exi 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 diff --git a/lib/zip/extra_field/generic.rb b/lib/zip/extra_field/generic.rb index 0bb000b3..7baf9e4a 100644 --- a/lib/zip/extra_field/generic.rb +++ b/lib/zip/extra_field/generic.rb @@ -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 @@ def self.name # 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 diff --git a/samples/zipfind.rb b/samples/zipfind.rb index 7a8ac452..59ca1fdb 100755 --- a/samples/zipfind.rb +++ b/samples/zipfind.rb @@ -48,10 +48,10 @@ def self.run(args) end def self.check_args(args) - if args.size != 3 - usage - exit - end + return if args.size == 3 + + usage + exit end def self.usage diff --git a/test/test_helper.rb b/test/test_helper.rb index 7a0edfc9..d1777bd7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -42,11 +42,10 @@ def seek(index, offset) 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 @@ def assert_entry_contents_for_stream(filename, zis, entryName) 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 From 2e11a88fd2f9bd6a21df95dc971be8924cdbb695 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 15:57:46 +0000 Subject: [PATCH 30/56] Fix Style/StringLiterals cop. --- .rubocop_todo.yml | 11 ----------- lib/zip/crypto/decrypted_io.rb | 2 +- lib/zip/inflater.rb | 2 +- lib/zip/pass_thru_decompressor.rb | 2 +- test/file_test.rb | 2 +- 5 files changed, 4 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b35b103e..88e3f86b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -301,17 +301,6 @@ Style/SpecialGlobalVars: - 'test/output_stream_test.rb' - 'test/test_helper.rb' -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'lib/zip/crypto/decrypted_io.rb' - - 'lib/zip/inflater.rb' - - 'lib/zip/pass_thru_decompressor.rb' - - 'test/file_test.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: MinSize. diff --git a/lib/zip/crypto/decrypted_io.rb b/lib/zip/crypto/decrypted_io.rb index cddce8a8..8d8191f0 100644 --- a/lib/zip/crypto/decrypted_io.rb +++ b/lib/zip/crypto/decrypted_io.rb @@ -8,7 +8,7 @@ def initialize(io, decrypter) end def read(length = nil, outbuf = +'') - return ((length.nil? || length.zero?) ? "" : nil) if eof + return ((length.nil? || length.zero?) ? '' : nil) if eof while length.nil? || (buffer.bytesize < length) break if input_finished? diff --git a/lib/zip/inflater.rb b/lib/zip/inflater.rb index f63de688..609ccc79 100644 --- a/lib/zip/inflater.rb +++ b/lib/zip/inflater.rb @@ -8,7 +8,7 @@ def initialize(*args) end def read(length = nil, outbuf = '') - return ((length.nil? || length.zero?) ? "" : nil) if eof + return ((length.nil? || length.zero?) ? '' : nil) if eof while length.nil? || (@buffer.bytesize < length) break if input_finished? diff --git a/lib/zip/pass_thru_decompressor.rb b/lib/zip/pass_thru_decompressor.rb index 730882d3..d7892ce4 100644 --- a/lib/zip/pass_thru_decompressor.rb +++ b/lib/zip/pass_thru_decompressor.rb @@ -6,7 +6,7 @@ def initialize(*args) end def read(length = nil, outbuf = '') - return ((length.nil? || length.zero?) ? "" : nil) if eof + return ((length.nil? || length.zero?) ? '' : nil) if eof if length.nil? || (@read_so_far + length) > decompressed_size length = decompressed_size - @read_so_far diff --git a/test/file_test.rb b/test/file_test.rb index 392a5027..ba3f0eac 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -57,7 +57,7 @@ def test_create_from_scratch_with_old_create_parameter def test_get_input_stream_stored_with_gpflag_bit3 ::Zip::File.open('test/data/gpbit3stored.zip') do |zf| - assert_equal("foo\n", zf.read("foo.txt")) + assert_equal("foo\n", zf.read('foo.txt')) end end From cc0e3723519598c14253078d69cdbe96eb2d8551 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 16:00:05 +0000 Subject: [PATCH 31/56] Configure Style/SymbolArray cop. --- .rubocop.yml | 3 +++ .rubocop_todo.yml | 7 ------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 36e8cf2e..63b8ad8c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,9 @@ Lint/UselessComparison: Exclude: - 'test/entry_test.rb' +Style/SymbolArray: + EnforcedStyle: brackets + # Turn this cop off for these files as it fires for objects without # an empty? method. Style/ZeroLengthPredicate: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 88e3f86b..362ab5c2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -301,13 +301,6 @@ Style/SpecialGlobalVars: - 'test/output_stream_test.rb' - 'test/test_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: MinSize. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets - # Offense count: 42 # Cop supports --auto-correct. # Configuration parameters: IgnoredMethods. From 4e1b679c73f5f01e278e8808344ab9d187e9e2a3 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 22 Sep 2019 10:06:20 +0100 Subject: [PATCH 32/56] Fix Style/TrailingCommaInArrayLiteral cop. --- .rubocop_todo.yml | 8 -------- lib/zip/central_directory.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 362ab5c2..ad2bed27 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -327,14 +327,6 @@ Style/TernaryParentheses: - 'lib/zip/inflater.rb' - 'lib/zip/pass_thru_decompressor.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArrayLiteral: - Exclude: - - 'lib/zip/central_directory.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline. diff --git a/lib/zip/central_directory.rb b/lib/zip/central_directory.rb index 04e0b1e6..496d668d 100644 --- a/lib/zip/central_directory.rb +++ b/lib/zip/central_directory.rb @@ -65,7 +65,7 @@ def write_64_e_o_c_d(io, offset, cdir_size) #:nodoc: @entry_set ? @entry_set.size : 0, # number of entries on this disk @entry_set ? @entry_set.size : 0, # number of entries total cdir_size, # size of central directory - offset, # offset of start of central directory in its disk + offset # offset of start of central directory in its disk ] io << tmp.pack('VQ Date: Sun, 22 Sep 2019 11:23:35 +0100 Subject: [PATCH 33/56] Fix Style/UnpackFirst cop. --- .rubocop_todo.yml | 9 --------- lib/zip/entry.rb | 6 +++--- lib/zip/extra_field.rb | 2 +- lib/zip/extra_field/generic.rb | 2 +- lib/zip/extra_field/zip64.rb | 2 +- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ad2bed27..0946af8d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -335,15 +335,6 @@ Style/TrailingCommaInHashLiteral: Exclude: - 'lib/zip/constants.rb' -# Offense count: 6 -# Cop supports --auto-correct. -Style/UnpackFirst: - Exclude: - - 'lib/zip/entry.rb' - - 'lib/zip/extra_field.rb' - - 'lib/zip/extra_field/generic.rb' - - 'lib/zip/extra_field/zip64.rb' - # Offense count: 247 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 0801ad26..44b3319d 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -194,15 +194,15 @@ def to_s class << self def read_zip_short(io) # :nodoc: - io.read(2).unpack('v')[0] + io.read(2).unpack1('v') end def read_zip_long(io) # :nodoc: - io.read(4).unpack('V')[0] + io.read(4).unpack1('V') end def read_zip_64_long(io) # :nodoc: - io.read(8).unpack('Q<')[0] + io.read(8).unpack1('Q<') end def read_c_dir_entry(io) #:nodoc:all diff --git a/lib/zip/extra_field.rb b/lib/zip/extra_field.rb index b8bb8a5f..e4b00b66 100644 --- a/lib/zip/extra_field.rb +++ b/lib/zip/extra_field.rb @@ -40,7 +40,7 @@ def merge(binstr) i = 0 while i < binstr.bytesize id = binstr[i, 2] - len = binstr[i + 2, 2].to_s.unpack('v').first + len = binstr[i + 2, 2].to_s.unpack1('v') if id && ID_MAP.member?(id) extra_field_type_exist(binstr, id, len, i) elsif id diff --git a/lib/zip/extra_field/generic.rb b/lib/zip/extra_field/generic.rb index 7baf9e4a..5eb702d6 100644 --- a/lib/zip/extra_field/generic.rb +++ b/lib/zip/extra_field/generic.rb @@ -19,7 +19,7 @@ def initial_parse(binstr) return false end - [binstr[2, 2].unpack('v')[0], binstr[4..-1]] + [binstr[2, 2].unpack1('v'), binstr[4..-1]] end def ==(other) diff --git a/lib/zip/extra_field/zip64.rb b/lib/zip/extra_field/zip64.rb index 7e2954d0..9826c6cf 100644 --- a/lib/zip/extra_field/zip64.rb +++ b/lib/zip/extra_field/zip64.rb @@ -46,7 +46,7 @@ def parse(original_size, compressed_size, relative_header_offset = nil, disk_sta end def extract(size, format) - @content.slice!(0, size).unpack(format)[0] + @content.slice!(0, size).unpack1(format) end private :extract From 41f2359c4bb4befead13d8928c882689dc38d259 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 16:07:46 +0000 Subject: [PATCH 34/56] Configure Style/RegexpLiteral cop. Allow inner slashes when using // for regex literals. Allow the Guardfile to use a syntax that is more consistent with its own style. --- .rubocop.yml | 7 +++++++ .rubocop_todo.yml | 11 ----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 63b8ad8c..03345f89 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,13 @@ Lint/UselessComparison: Exclude: - 'test/entry_test.rb' +# Allow inner slashes when using // for regex literals. Allow the +# Guardfile to use a syntax that is more consistent with its own style. +Style/RegexpLiteral: + AllowInnerSlashes: true + Exclude: + - 'Guardfile' + Style/SymbolArray: EnforcedStyle: brackets diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0946af8d..a0668e19 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -242,17 +242,6 @@ Style/NumericPredicate: - 'test/file_split_test.rb' - 'test/test_helper.rb' -# Offense count: 12 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'lib/zip/filesystem.rb' - - 'test/entry_test.rb' - - 'test/path_traversal_test.rb' - - 'test/settings_test.rb' - # Offense count: 17 # Cop supports --auto-correct. # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. From 5e32204ec464d61adec6dc43790844d087d47f7c Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 16:11:01 +0000 Subject: [PATCH 35/56] Configure Style/MultilineBlockChain cop. --- .rubocop.yml | 6 ++++++ .rubocop_todo.yml | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 03345f89..978750d6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,12 @@ Lint/UselessComparison: Exclude: - 'test/entry_test.rb' +# Allow this multi-line block chain as it actually reads better +# than the alternatives. +Style/MultilineBlockChain: + Exclude: + - 'lib/zip/crypto/traditional_encryption.rb' + # Allow inner slashes when using // for regex literals. Allow the # Guardfile to use a syntax that is more consistent with its own style. Style/RegexpLiteral: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a0668e19..3bdb4a7d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -183,11 +183,6 @@ Style/ModuleFunction: Exclude: - 'lib/zip.rb' -# Offense count: 1 -Style/MultilineBlockChain: - Exclude: - - 'lib/zip/crypto/traditional_encryption.rb' - # Offense count: 2 # Cop supports --auto-correct. Style/MultilineWhenThen: From 172ab4b567cc1171a9e19bccaf8421a6b9228016 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 22 Sep 2019 12:24:44 +0100 Subject: [PATCH 36/56] Fix Style/FloatDivision cop. --- .rubocop_todo.yml | 7 ------- samples/example.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3bdb4a7d..f853fe40 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -143,13 +143,6 @@ Style/EvalWithLocation: Exclude: - 'test/test_helper.rb' -# Offense count: 1 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: left_coerce, right_coerce, single_coerce, fdiv -Style/FloatDivision: - Exclude: - - 'samples/example.rb' - # Offense count: 3 # Configuration parameters: . # SupportedStyles: annotated, template, unannotated diff --git a/samples/example.rb b/samples/example.rb index 224d4f1c..407ff6c6 100755 --- a/samples/example.rb +++ b/samples/example.rb @@ -71,7 +71,7 @@ # Track splitting an archive Zip::File.split('large_zip_file.zip', 1_048_576, true, 'part_zip_file') do |part_count, part_index, chunk_bytes, segment_bytes| - puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f / segment_bytes.to_f * 100).to_i}%" + puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f / segment_bytes * 100).to_i}%" end # For other examples, look at zip.rb and ziptest.rb From d42c66ce2cb03dab55be52bf5f769fb4e08d3d0a Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 22 Sep 2019 14:23:57 +0100 Subject: [PATCH 37/56] Fix Style/MultilineWhenThen cop. --- .rubocop_todo.yml | 6 ------ lib/zip/output_stream.rb | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f853fe40..9255d879 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -176,12 +176,6 @@ Style/ModuleFunction: Exclude: - 'lib/zip.rb' -# Offense count: 2 -# Cop supports --auto-correct. -Style/MultilineWhenThen: - Exclude: - - 'lib/zip/output_stream.rb' - # Offense count: 56 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/lib/zip/output_stream.rb b/lib/zip/output_stream.rb index 6ab4a484..fa60e855 100644 --- a/lib/zip/output_stream.rb +++ b/lib/zip/output_stream.rb @@ -150,9 +150,9 @@ def init_next_entry(entry, level = Zip.default_compression) def get_compressor(entry, level) case entry.compression_method - when Entry::DEFLATED then + when Entry::DEFLATED ::Zip::Deflater.new(@output_stream, level, @encrypter) - when Entry::STORED then + when Entry::STORED ::Zip::PassThruCompressor.new(@output_stream) else raise ::Zip::CompressionMethodError, From 2dc9b49568390b517e0f113c1fb5d932382d3238 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 22 Sep 2019 14:36:45 +0100 Subject: [PATCH 38/56] Fix Style/EvalWithLocation cop. --- .rubocop_todo.yml | 5 ----- test/test_helper.rb | 9 ++++++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9255d879..b0776ce2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -138,11 +138,6 @@ Style/ClassCheck: Style/Documentation: Enabled: false -# Offense count: 2 -Style/EvalWithLocation: - Exclude: - - 'test/test_helper.rb' - # Offense count: 3 # Configuration parameters: . # SupportedStyles: annotated, template, unannotated diff --git a/test/test_helper.rb b/test/test_helper.rb index d1777bd7..ab52bad4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -193,18 +193,21 @@ module ExtraAssertions def assert_forwarded(anObject, method, retVal, *expectedArgs) callArgs = nil setCallArgsProc = proc { |args| callArgs = args } - anObject.instance_eval <<-"end_eval" + anObject.instance_eval <<-END_EVAL, __FILE__, __LINE__ + 1 alias #{method}_org #{method} def #{method}(*args) ObjectSpace._id2ref(#{setCallArgsProc.object_id}).call(args) ObjectSpace._id2ref(#{retVal.object_id}) end - end_eval + END_EVAL assert_equal(retVal, yield) # Invoke test assert_equal(expectedArgs, callArgs) ensure - anObject.instance_eval "undef #{method}; alias #{method} #{method}_org" + anObject.instance_eval <<-END_EVAL, __FILE__, __LINE__ + 1 + undef #{method} + alias #{method} #{method}_org + END_EVAL end end From 835843d99223074fb845032f904ef4db2dcc77fc Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 22 Sep 2019 16:19:57 +0100 Subject: [PATCH 39/56] Fix Naming/HeredocDelimiterCase cop. --- .rubocop_todo.yml | 8 -------- lib/zip/filesystem.rb | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b0776ce2..df5c84f6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -69,14 +69,6 @@ Naming/BlockParameterName: - 'test/output_stream_test.rb' - 'test/test_helper.rb' -# Offense count: 2 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: lowercase, uppercase -Naming/HeredocDelimiterCase: - Exclude: - - 'lib/zip/filesystem.rb' - - 'test/test_helper.rb' - # Offense count: 2 # Configuration parameters: EnforcedStyleForLeadingUnderscores. # SupportedStylesForLeadingUnderscores: disallowed, required, optional diff --git a/lib/zip/filesystem.rb b/lib/zip/filesystem.rb index abf98020..15c9c0c0 100644 --- a/lib/zip/filesystem.rb +++ b/lib/zip/filesystem.rb @@ -70,11 +70,11 @@ class ZipFsStat class << self def delegate_to_fs_file(*methods) methods.each do |method| - class_eval <<-end_eval, __FILE__, __LINE__ + 1 + class_eval <<-END_EVAL, __FILE__, __LINE__ + 1 def #{method} # def file? @zipFsFile.#{method}(@entryName) # @zipFsFile.file?(@entryName) end # end - end_eval + END_EVAL end end end From 7978abb85edab818a4d8a7e81e586d2dc17430bb Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 22 Sep 2019 17:32:00 +0100 Subject: [PATCH 40/56] Configure Naming/MemoizedInstanceVariableName cop. --- .rubocop.yml | 6 ++++++ .rubocop_todo.yml | 8 -------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 978750d6..d40eabcf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,12 @@ Lint/UselessComparison: Exclude: - 'test/entry_test.rb' +# Rubocop confuses these as instances of "memoization". +Naming/MemoizedInstanceVariableName: + Exclude: + - 'lib/zip/extra_field/old_unix.rb' + - 'lib/zip/extra_field/unix.rb' + # Allow this multi-line block chain as it actually reads better # than the alternatives. Style/MultilineBlockChain: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index df5c84f6..47c6e638 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -69,14 +69,6 @@ Naming/BlockParameterName: - 'test/output_stream_test.rb' - 'test/test_helper.rb' -# Offense count: 2 -# Configuration parameters: EnforcedStyleForLeadingUnderscores. -# SupportedStylesForLeadingUnderscores: disallowed, required, optional -Naming/MemoizedInstanceVariableName: - Exclude: - - 'lib/zip/extra_field/old_unix.rb' - - 'lib/zip/extra_field/unix.rb' - # Offense count: 140 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. # AllowedNames: io, id, to, by, on, in, at, ip, db, os From 2f993221c0f67a94e05707fc67b1185dcaef8517 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Wed, 25 Sep 2019 22:44:48 +0100 Subject: [PATCH 41/56] Fix Style/Next cop. --- .rubocop_todo.yml | 8 -------- lib/zip/entry.rb | 12 ++++++------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 47c6e638..12fdade5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -162,14 +162,6 @@ Style/ModuleFunction: Style/MutableConstant: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinBodyLength. -# SupportedStyles: skip_modifier_ifs, always -Style/Next: - Exclude: - - 'lib/zip/entry.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedOctalStyle. diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 44b3319d..a3ad4997 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -625,13 +625,13 @@ def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exi while (buf = is.sysread(::Zip::Decompressor::CHUNK_SIZE, buf)) os << buf bytes_written += buf.bytesize - if bytes_written > size && !warned - message = "entry '#{name}' should be #{size}B, but is larger when inflated." - raise ::Zip::EntrySizeError, message if ::Zip.validate_entry_sizes + next unless bytes_written > size && !warned - warn "WARNING: #{message}" - warned = true - end + message = "entry '#{name}' should be #{size}B, but is larger when inflated." + raise ::Zip::EntrySizeError, message if ::Zip.validate_entry_sizes + + warn "WARNING: #{message}" + warned = true end end end From 2cbdbf110b6083d03d4f6715b7db1c28b6de1f91 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Thu, 26 Sep 2019 13:58:43 +0100 Subject: [PATCH 42/56] Fix Style/SignalException cop. --- .rubocop_todo.yml | 13 ------------- test/central_directory_entry_test.rb | 2 +- test/central_directory_test.rb | 4 ++-- test/filesystem/file_nonmutating_test.rb | 2 +- test/ioextras/abstract_input_stream_test.rb | 2 +- test/local_entry_test.rb | 2 +- test/test_helper.rb | 4 ++-- 7 files changed, 8 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 12fdade5..213ad155 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -209,19 +209,6 @@ Style/SafeNavigation: - 'test/filesystem/file_stat_test.rb' - 'test/test_helper.rb' -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: only_raise, only_fail, semantic -Style/SignalException: - Exclude: - - 'test/central_directory_entry_test.rb' - - 'test/central_directory_test.rb' - - 'test/filesystem/file_nonmutating_test.rb' - - 'test/ioextras/abstract_input_stream_test.rb' - - 'test/local_entry_test.rb' - - 'test/test_helper.rb' - # Offense count: 30 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/test/central_directory_entry_test.rb b/test/central_directory_entry_test.rb index fa0d8065..c060a4d3 100644 --- a/test/central_directory_entry_test.rb +++ b/test/central_directory_entry_test.rb @@ -63,7 +63,7 @@ def test_read_entry_from_truncated_zip_file fragment.extend(IOizeString) entry = ::Zip::Entry.new entry.read_c_dir_entry(fragment) - fail 'ZipError expected' + raise 'ZipError expected' rescue ::Zip::Error end end diff --git a/test/central_directory_test.rb b/test/central_directory_test.rb index 26be6424..28e12f4a 100644 --- a/test/central_directory_test.rb +++ b/test/central_directory_test.rb @@ -22,7 +22,7 @@ def test_read_from_invalid_stream cdir = ::Zip::CentralDirectory.new cdir.read_from_stream(zipFile) end - fail 'ZipError expected!' + raise 'ZipError expected!' rescue ::Zip::Error end @@ -33,7 +33,7 @@ def test_read_from_truncated_zip_file fragment.extend(IOizeString) entry = ::Zip::CentralDirectory.new entry.read_from_stream(fragment) - fail 'ZipError expected' + raise 'ZipError expected' rescue ::Zip::Error end diff --git a/test/filesystem/file_nonmutating_test.rb b/test/filesystem/file_nonmutating_test.rb index af575fac..73161cf6 100644 --- a/test/filesystem/file_nonmutating_test.rb +++ b/test/filesystem/file_nonmutating_test.rb @@ -80,7 +80,7 @@ def test_new end begin is = @zip_file.file.new('file1') do - fail 'should not call block' + raise 'should not call block' end ensure is.close if is diff --git a/test/ioextras/abstract_input_stream_test.rb b/test/ioextras/abstract_input_stream_test.rb index 3ae005d1..46925a8d 100644 --- a/test/ioextras/abstract_input_stream_test.rb +++ b/test/ioextras/abstract_input_stream_test.rb @@ -95,7 +95,7 @@ def test_readline test_gets begin @io.readline - fail 'EOFError expected' + raise 'EOFError expected' rescue EOFError end end diff --git a/test/local_entry_test.rb b/test/local_entry_test.rb index 666a63a0..b02deb67 100644 --- a/test/local_entry_test.rb +++ b/test/local_entry_test.rb @@ -46,7 +46,7 @@ def test_read_local_entry_from_truncated_zip_file zipFragment.extend(IOizeString).reset entry = ::Zip::Entry.new entry.read_local_entry(zipFragment) - fail 'ZipError expected' + raise 'ZipError expected' rescue ::Zip::Error end diff --git a/test/test_helper.rb b/test/test_helper.rb index ab52bad4..a8b719f0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -95,7 +95,7 @@ def assert_entry_contents_for_stream(filename, zis, entryName) if (expected && actual) && (expected.length > 400 || actual.length > 400) zipEntryFilename = entryName + '.zipEntry' File.open(zipEntryFilename, 'wb') { |entryfile| entryfile << actual } - fail("File '#{filename}' is different from '#{zipEntryFilename}'") + raise("File '#{filename}' is different from '#{zipEntryFilename}'") else assert_equal(expected, actual) end @@ -111,7 +111,7 @@ def self.assert_contents(filename, 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}'") + raise("File '#{filename}' is different from contents of string stored in '#{stringFile}'") else assert_equal(fileContents, aString) end From bb3b4474fa1c034aa9ef749fec5679045f78f5f1 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Thu, 26 Sep 2019 21:46:00 +0100 Subject: [PATCH 43/56] Fix Style/SpecialGlobalVars cop. --- .rubocop_todo.yml | 21 -------------------- lib/zip.rb | 1 + lib/zip/filesystem.rb | 2 +- lib/zip/ioextras/abstract_input_stream.rb | 12 +++++------ lib/zip/ioextras/abstract_output_stream.rb | 2 +- samples/example.rb | 2 +- samples/example_filesystem.rb | 2 +- samples/gtk_ruby_zip.rb | 2 +- samples/qtzip.rb | 4 ++-- samples/write_simple.rb | 2 +- samples/zipfind.rb | 6 +++--- test/gentestfiles.rb | 2 +- test/ioextras/abstract_input_stream_test.rb | 6 +++--- test/ioextras/abstract_output_stream_test.rb | 4 ++-- test/output_stream_test.rb | 8 ++++---- test/test_helper.rb | 2 +- 16 files changed, 29 insertions(+), 49 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 213ad155..ededff08 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -209,27 +209,6 @@ Style/SafeNavigation: - 'test/filesystem/file_stat_test.rb' - 'test/test_helper.rb' -# Offense count: 30 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: use_perl_names, use_english_names -Style/SpecialGlobalVars: - Exclude: - - 'lib/zip/filesystem.rb' - - 'lib/zip/ioextras/abstract_input_stream.rb' - - 'lib/zip/ioextras/abstract_output_stream.rb' - - 'samples/example.rb' - - 'samples/example_filesystem.rb' - - 'samples/gtk_ruby_zip.rb' - - 'samples/qtzip.rb' - - 'samples/write_simple.rb' - - 'samples/zipfind.rb' - - 'test/gentestfiles.rb' - - 'test/ioextras/abstract_input_stream_test.rb' - - 'test/ioextras/abstract_output_stream_test.rb' - - 'test/output_stream_test.rb' - - 'test/test_helper.rb' - # Offense count: 42 # Cop supports --auto-correct. # Configuration parameters: IgnoredMethods. diff --git a/lib/zip.rb b/lib/zip.rb index 5261fd77..8cf982a5 100644 --- a/lib/zip.rb +++ b/lib/zip.rb @@ -1,3 +1,4 @@ +require 'English' require 'delegate' require 'singleton' require 'tempfile' diff --git a/lib/zip/filesystem.rb b/lib/zip/filesystem.rb index 15c9c0c0..2a5dbdf5 100644 --- a/lib/zip/filesystem.rb +++ b/lib/zip/filesystem.rb @@ -401,7 +401,7 @@ def popen(*args, &aProc) ::File.popen(*args, &aProc) end - def foreach(fileName, aSep = $/, &aProc) + def foreach(fileName, aSep = $INPUT_RECORD_SEPARATOR, &aProc) self.open(fileName) { |is| is.each_line(aSep, &aProc) } end diff --git a/lib/zip/ioextras/abstract_input_stream.rb b/lib/zip/ioextras/abstract_input_stream.rb index 85f4974e..8392d240 100644 --- a/lib/zip/ioextras/abstract_input_stream.rb +++ b/lib/zip/ioextras/abstract_input_stream.rb @@ -49,13 +49,13 @@ def read(number_of_bytes = nil, buf = '') buf end - def readlines(a_sep_string = $/) + def readlines(a_sep_string = $INPUT_RECORD_SEPARATOR) ret_val = [] each_line(a_sep_string) { |line| ret_val << line } ret_val end - def gets(a_sep_string = $/, number_of_bytes = nil) + def gets(a_sep_string = $INPUT_RECORD_SEPARATOR, number_of_bytes = nil) @lineno = @lineno.next if number_of_bytes.respond_to?(:to_int) @@ -63,7 +63,7 @@ def gets(a_sep_string = $/, number_of_bytes = nil) a_sep_string = a_sep_string.to_str if a_sep_string elsif a_sep_string.respond_to?(:to_int) number_of_bytes = a_sep_string.to_int - a_sep_string = $/ + a_sep_string = $INPUT_RECORD_SEPARATOR else number_of_bytes = nil a_sep_string = a_sep_string.to_str if a_sep_string @@ -71,7 +71,7 @@ def gets(a_sep_string = $/, number_of_bytes = nil) return read(number_of_bytes) if a_sep_string.nil? - a_sep_string = "#{$/}#{$/}" if a_sep_string.empty? + a_sep_string = "#{$INPUT_RECORD_SEPARATOR}#{$INPUT_RECORD_SEPARATOR}" if a_sep_string.empty? buffer_index = 0 over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes) @@ -97,14 +97,14 @@ def flush ret_val end - def readline(a_sep_string = $/) + def readline(a_sep_string = $INPUT_RECORD_SEPARATOR) ret_val = gets(a_sep_string) raise EOFError unless ret_val ret_val end - def each_line(a_sep_string = $/) + def each_line(a_sep_string = $INPUT_RECORD_SEPARATOR) loop { yield readline(a_sep_string) } rescue EOFError # We just need to catch this; we don't need to handle it. diff --git a/lib/zip/ioextras/abstract_output_stream.rb b/lib/zip/ioextras/abstract_output_stream.rb index 69d0cc7c..b94c9d49 100644 --- a/lib/zip/ioextras/abstract_output_stream.rb +++ b/lib/zip/ioextras/abstract_output_stream.rb @@ -11,7 +11,7 @@ def write(data) end def print(*params) - self << params.join($,) << $\.to_s + self << params.join($OUTPUT_FIELD_SEPARATOR) << $OUTPUT_RECORD_SEPARATOR.to_s end def printf(a_format_string, *params) diff --git a/samples/example.rb b/samples/example.rb index 407ff6c6..345e7e19 100755 --- a/samples/example.rb +++ b/samples/example.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$: << '../lib' +$LOAD_PATH << '../lib' system('zip example.zip example.rb gtk_ruby_zip.rb') require 'zip' diff --git a/samples/example_filesystem.rb b/samples/example_filesystem.rb index f253a5e5..0d93ab6b 100755 --- a/samples/example_filesystem.rb +++ b/samples/example_filesystem.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$: << '../lib' +$LOAD_PATH << '../lib' require 'zip/filesystem' diff --git a/samples/gtk_ruby_zip.rb b/samples/gtk_ruby_zip.rb index 62f005a5..4ce1cae0 100755 --- a/samples/gtk_ruby_zip.rb +++ b/samples/gtk_ruby_zip.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$: << '../lib' +$LOAD_PATH << '../lib' $VERBOSE = true diff --git a/samples/qtzip.rb b/samples/qtzip.rb index 1d450a78..f76f57a7 100755 --- a/samples/qtzip.rb +++ b/samples/qtzip.rb @@ -2,7 +2,7 @@ $VERBOSE = true -$: << '../lib' +$LOAD_PATH << '../lib' require 'Qt' system('rbuic -o zipdialogui.rb zipdialogui.ui') @@ -80,7 +80,7 @@ def extract_files end unless ARGV[0] - puts "usage: #{$0} zipname" + puts "usage: #{$PROGRAM_NAME} zipname" exit end diff --git a/samples/write_simple.rb b/samples/write_simple.rb index 0c534ede..8bb31bb3 100755 --- a/samples/write_simple.rb +++ b/samples/write_simple.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$: << '../lib' +$LOAD_PATH << '../lib' require 'zip' diff --git a/samples/zipfind.rb b/samples/zipfind.rb index 59ca1fdb..a88bc42d 100755 --- a/samples/zipfind.rb +++ b/samples/zipfind.rb @@ -2,7 +2,7 @@ $VERBOSE = true -$: << '../lib' +$LOAD_PATH << '../lib' require 'zip' require 'find' @@ -32,7 +32,7 @@ def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i) end end -if $0 == __FILE__ +if $PROGRAM_NAME == __FILE__ module ZipFindConsoleRunner PATH_ARG_INDEX = 0 FILENAME_PATTERN_ARG_INDEX = 1 @@ -55,7 +55,7 @@ def self.check_args(args) end def self.usage - puts "Usage: #{$0} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN" + puts "Usage: #{$PROGRAM_NAME} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN" end def self.report_entry_found(fileName) diff --git a/test/gentestfiles.rb b/test/gentestfiles.rb index a50f51d5..3427ad42 100755 --- a/test/gentestfiles.rb +++ b/test/gentestfiles.rb @@ -112,7 +112,7 @@ def self.create_test_zips # to help create the following files, there's a free one available from # http://stahlworks.com/dev/index.php?tool=zipunzip # that works with the above code - raise $!.to_s + + raise $ERROR_INFO.to_s + "\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" \ "to create test data. If you don't have it you can download\n" \ 'the necessary test files at http://sf.net/projects/rubyzip.' diff --git a/test/ioextras/abstract_input_stream_test.rb b/test/ioextras/abstract_input_stream_test.rb index 46925a8d..f8986b84 100644 --- a/test/ioextras/abstract_input_stream_test.rb +++ b/test/ioextras/abstract_input_stream_test.rb @@ -4,8 +4,8 @@ class AbstractInputStreamTest < MiniTest::Test # AbstractInputStream subclass that provides a read method - TEST_LINES = ["Hello world#{$/}", - "this is the second line#{$/}", + TEST_LINES = ["Hello world#{$INPUT_RECORD_SEPARATOR}", + "this is the second line#{$INPUT_RECORD_SEPARATOR}", 'this is the last line'] TEST_STRING = TEST_LINES.join class TestAbstractInputStream @@ -50,7 +50,7 @@ def test_gets def test_gets_multi_char_seperator assert_equal('Hell', @io.gets('ll')) - assert_equal("o world#{$/}this is the second l", @io.gets('d l')) + assert_equal("o world#{$INPUT_RECORD_SEPARATOR}this is the second l", @io.gets('d l')) end LONG_LINES = [ diff --git a/test/ioextras/abstract_output_stream_test.rb b/test/ioextras/abstract_output_stream_test.rb index 3077db43..17b31a78 100644 --- a/test/ioextras/abstract_output_stream_test.rb +++ b/test/ioextras/abstract_output_stream_test.rb @@ -20,8 +20,8 @@ def <<(data) def setup @output_stream = TestOutputStream.new - @origCommaSep = $, - @origOutputSep = $\ + @origCommaSep = $OUTPUT_FIELD_SEPARATOR + @origOutputSep = $OUTPUT_RECORD_SEPARATOR end def teardown diff --git a/test/output_stream_test.rb b/test/output_stream_test.rb index f3875266..106ba6af 100644 --- a/test/output_stream_test.rb +++ b/test/output_stream_test.rb @@ -58,10 +58,10 @@ def test_cannot_open_file begin ::Zip::OutputStream.open(name) rescue SystemCallError - assert($!.kind_of?(Errno::EISDIR) || # Linux - $!.kind_of?(Errno::EEXIST) || # Windows/cygwin - $!.kind_of?(Errno::EACCES), # Windows - "Expected Errno::EISDIR (or on win/cygwin: Errno::EEXIST), but was: #{$!.class}") + assert($ERROR_INFO.kind_of?(Errno::EISDIR) || # Linux + $ERROR_INFO.kind_of?(Errno::EEXIST) || # Windows/cygwin + $ERROR_INFO.kind_of?(Errno::EACCES), # Windows + "Expected Errno::EISDIR (or on win/cygwin: Errno::EEXIST), but was: #{$ERROR_INFO.class}") end end diff --git a/test/test_helper.rb b/test/test_helper.rb index a8b719f0..0e14b6da 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -61,7 +61,7 @@ module DecompressorTests def setup @refText = '' File.open(TEST_FILE) { |f| @refText = f.read } - @refLines = @refText.split($/) + @refLines = @refText.split($INPUT_RECORD_SEPARATOR) end def test_read_everything From 0df6cb3059a9d770ac4fd800ad3fdb45872192cb Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Thu, 26 Sep 2019 22:38:28 +0100 Subject: [PATCH 44/56] Fix Style/SymbolProc cop. --- .rubocop_todo.yml | 16 ------- lib/zip/file.rb | 2 +- lib/zip/filesystem.rb | 2 +- test/basic_zip_file_test.rb | 2 +- test/case_sensitivity_test.rb | 7 +-- test/deflater_test.rb | 2 +- test/file_extract_test.rb | 4 +- test/file_split_test.rb | 4 +- test/file_test.rb | 57 +++++++++++++----------- test/filesystem/file_nonmutating_test.rb | 8 ++-- 10 files changed, 46 insertions(+), 58 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ededff08..9f090fac 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -209,22 +209,6 @@ Style/SafeNavigation: - 'test/filesystem/file_stat_test.rb' - 'test/test_helper.rb' -# Offense count: 42 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to, define_method -Style/SymbolProc: - Exclude: - - 'lib/zip/file.rb' - - 'lib/zip/filesystem.rb' - - 'test/basic_zip_file_test.rb' - - 'test/case_sensitivity_test.rb' - - 'test/deflater_test.rb' - - 'test/file_extract_test.rb' - - 'test/file_split_test.rb' - - 'test/file_test.rb' - - 'test/filesystem/file_nonmutating_test.rb' - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, AllowSafeAssignment. diff --git a/lib/zip/file.rb b/lib/zip/file.rb index 346bbad6..37dcd921 100644 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -288,7 +288,7 @@ def to_s # Returns a string containing the contents of the specified entry def read(entry) - get_input_stream(entry) { |is| is.read } + get_input_stream(entry, &:read) end # Convenience method for adding the contents of a file to the archive diff --git a/lib/zip/filesystem.rb b/lib/zip/filesystem.rb index 2a5dbdf5..4f3e9954 100644 --- a/lib/zip/filesystem.rb +++ b/lib/zip/filesystem.rb @@ -390,7 +390,7 @@ def stat(fileName) alias lstat stat def readlines(fileName) - self.open(fileName) { |is| is.readlines } + self.open(fileName, &:readlines) end def read(fileName) diff --git a/test/basic_zip_file_test.rb b/test/basic_zip_file_test.rb index 9e490b4a..3d21ae89 100644 --- a/test/basic_zip_file_test.rb +++ b/test/basic_zip_file_test.rb @@ -10,7 +10,7 @@ def setup def test_entries assert_equal(TestZipFile::TEST_ZIP2.entry_names.sort, - @zip_file.entries.entries.sort.map { |e| e.name }) + @zip_file.entries.entries.sort.map(&:name)) end def test_each diff --git a/test/case_sensitivity_test.rb b/test/case_sensitivity_test.rb index 7749e06b..92fc0f6c 100644 --- a/test/case_sensitivity_test.rb +++ b/test/case_sensitivity_test.rb @@ -25,7 +25,7 @@ def test_add_case_sensitive SRC_FILES.each_with_index do |a, i| assert_equal(a.last, zfRead.entries[i].name) AssertEntry.assert_contents(a.first, - zfRead.get_input_stream(a.last) { |zis| zis.read }) + zfRead.get_input_stream(a.last, &:read)) end end @@ -56,8 +56,9 @@ def test_add_case_sensitive_read_case_insensitive zfRead = ::Zip::File.new(EMPTY_FILENAME) assert_equal(SRC_FILES.collect { |_fn, en| en.downcase }.uniq.size, zfRead.entries.length) assert_equal(SRC_FILES.last.last.downcase, zfRead.entries.first.name.downcase) - AssertEntry.assert_contents(SRC_FILES.last.first, - zfRead.get_input_stream(SRC_FILES.last.last) { |zis| zis.read }) + AssertEntry.assert_contents( + SRC_FILES.last.first, zfRead.get_input_stream(SRC_FILES.last.last, &:read) + ) end private diff --git a/test/deflater_test.rb b/test/deflater_test.rb index d1970ce9..78c22dfc 100644 --- a/test/deflater_test.rb +++ b/test/deflater_test.rb @@ -43,7 +43,7 @@ def test_data_error private def load_file(fileName) - File.open(fileName, 'rb') { |f| f.read } + File.open(fileName, 'rb', &:read) end def deflate(data, fileName) diff --git a/test/file_extract_test.rb b/test/file_extract_test.rb index a494f781..3992a1ad 100644 --- a/test/file_extract_test.rb +++ b/test/file_extract_test.rb @@ -20,7 +20,7 @@ def test_extract assert(File.exist?(EXTRACTED_FILENAME)) AssertEntry.assert_contents(EXTRACTED_FILENAME, - zf.get_input_stream(ENTRY_TO_EXTRACT) { |is| is.read }) + zf.get_input_stream(ENTRY_TO_EXTRACT, &:read)) ::File.unlink(EXTRACTED_FILENAME) @@ -29,7 +29,7 @@ def test_extract assert(File.exist?(EXTRACTED_FILENAME)) AssertEntry.assert_contents(EXTRACTED_FILENAME, - entry.get_input_stream { |is| is.read }) + entry.get_input_stream(&:read)) end end diff --git a/test/file_split_test.rb b/test/file_split_test.rb index c488f180..22dd1348 100644 --- a/test/file_split_test.rb +++ b/test/file_split_test.rb @@ -43,7 +43,7 @@ def test_split assert(File.exist?(EXTRACTED_FILENAME)) AssertEntry.assert_contents(EXTRACTED_FILENAME, - zf.get_input_stream(ENTRY_TO_EXTRACT) { |is| is.read }) + zf.get_input_stream(ENTRY_TO_EXTRACT, &:read)) File.unlink(EXTRACTED_FILENAME) @@ -52,7 +52,7 @@ def test_split assert(File.exist?(EXTRACTED_FILENAME)) AssertEntry.assert_contents(EXTRACTED_FILENAME, - entry.get_input_stream { |is| is.read }) + entry.get_input_stream(&:read)) end end end diff --git a/test/file_test.rb b/test/file_test.rb index ba3f0eac..21aa72f7 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -106,14 +106,14 @@ def test_get_output_stream def test_open_buffer_with_string string = File.read('test/data/rubycode.zip') ::Zip::File.open_buffer string do |zf| - assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb') + assert zf.entries.map(&:name).include?('zippedruby1.rb') end end def test_open_buffer_with_stringio string_io = StringIO.new File.read('test/data/rubycode.zip') ::Zip::File.open_buffer string_io do |zf| - assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb') + assert zf.entries.map(&:name).include?('zippedruby1.rb') end end @@ -171,7 +171,7 @@ def test_open_buffer_with_io_and_block def test_open_buffer_without_block string_io = StringIO.new File.read('test/data/rubycode.zip') zf = ::Zip::File.open_buffer string_io - assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb') + assert zf.entries.map(&:name).include?('zippedruby1.rb') end def test_cleans_up_tempfiles_after_close @@ -201,7 +201,7 @@ def test_add assert_equal(1, zfRead.entries.length) assert_equal(entryName, zfRead.entries.first.name) AssertEntry.assert_contents(srcFile, - zfRead.get_input_stream(entryName) { |zis| zis.read }) + zfRead.get_input_stream(entryName, &:read)) end def test_add_stored @@ -221,7 +221,7 @@ def test_add_stored assert_equal(entry.size, entry.compressed_size) assert_equal(::Zip::Entry::STORED, entry.compression_method) AssertEntry.assert_contents(srcFile, - zfRead.get_input_stream(entryName) { |zis| zis.read }) + zfRead.get_input_stream(entryName, &:read)) end def test_recover_permissions_after_add_files_to_archive @@ -277,15 +277,15 @@ def test_remove FileUtils.cp(TestZipFile::TEST_ZIP2.zip_name, TEST_ZIP.zip_name) zf = ::Zip::File.new(TEST_ZIP.zip_name) - assert(zf.entries.map { |e| e.name }.include?(entryToRemove)) + assert(zf.entries.map(&:name).include?(entryToRemove)) zf.remove(entryToRemove) - assert(!zf.entries.map { |e| e.name }.include?(entryToRemove)) - assert_equal(zf.entries.map { |x| x.name }.sort, remainingEntries.sort) + assert(!zf.entries.map(&:name).include?(entryToRemove)) + assert_equal(zf.entries.map(&:name).sort, remainingEntries.sort) zf.close zfRead = ::Zip::File.new(TEST_ZIP.zip_name) - assert(!zfRead.entries.map { |e| e.name }.include?(entryToRemove)) - assert_equal(zfRead.entries.map { |x| x.name }.sort, remainingEntries.sort) + assert(!zfRead.entries.map(&:name).include?(entryToRemove)) + assert_equal(zfRead.entries.map(&:name).sort, remainingEntries.sort) zfRead.close end @@ -293,21 +293,21 @@ def test_rename entryToRename, * = TEST_ZIP.entry_names zf = ::Zip::File.new(TEST_ZIP.zip_name) - assert(zf.entries.map { |e| e.name }.include?(entryToRename)) + assert(zf.entries.map(&:name).include?(entryToRename)) contents = zf.read(entryToRename) newName = 'changed entry name' - assert(!zf.entries.map { |e| e.name }.include?(newName)) + assert(!zf.entries.map(&:name).include?(newName)) zf.rename(entryToRename, newName) - assert(zf.entries.map { |e| e.name }.include?(newName)) + assert(zf.entries.map(&:name).include?(newName)) assert_equal(contents, zf.read(newName)) zf.close zfRead = ::Zip::File.new(TEST_ZIP.zip_name) - assert(zfRead.entries.map { |e| e.name }.include?(newName)) + assert(zfRead.entries.map(&:name).include?(newName)) assert_equal(contents, zfRead.read(newName)) zfRead.close end @@ -352,7 +352,7 @@ def test_rename_to_existing_entry end ::Zip::File.open(TEST_ZIP.zip_name) do |zf| - assert_equal(oldEntries.sort.map { |e| e.name }, zf.entries.sort.map { |e| e.name }) + assert_equal(oldEntries.sort.map(&:name), zf.entries.sort.map(&:name)) end end @@ -373,8 +373,8 @@ def test_rename_to_existing_entry_overwrite assert(gotCalled) oldEntries.delete_if { |e| e.name == renamedEntryName } ::Zip::File.open(TEST_ZIP.zip_name) do |zf| - assert_equal(oldEntries.sort.map { |e| e.name }, - zf.entries.sort.map { |e| e.name }) + assert_equal(oldEntries.sort.map(&:name), + zf.entries.sort.map(&:name)) end end @@ -407,13 +407,16 @@ def test_replace zf.close zfRead = ::Zip::File.new(TEST_ZIP.zip_name) AssertEntry.assert_contents(newEntrySrcFilename, - zfRead.get_input_stream(entryToReplace) { |is| is.read }) + zfRead.get_input_stream(entryToReplace, &:read)) AssertEntry.assert_contents(TEST_ZIP.entry_names[0], - zfRead.get_input_stream(TEST_ZIP.entry_names[0]) { |is| is.read }) + zfRead.get_input_stream(TEST_ZIP.entry_names[0], + &:read)) AssertEntry.assert_contents(TEST_ZIP.entry_names[1], - zfRead.get_input_stream(TEST_ZIP.entry_names[1]) { |is| is.read }) + zfRead.get_input_stream(TEST_ZIP.entry_names[1], + &:read)) AssertEntry.assert_contents(TEST_ZIP.entry_names[3], - zfRead.get_input_stream(TEST_ZIP.entry_names[3]) { |is| is.read }) + zfRead.get_input_stream(TEST_ZIP.entry_names[3], + &:read)) zfRead.close end @@ -555,7 +558,7 @@ def test_compound2 zf.add(filename, filename) assert_contains(zf, filename) end - assert_equal(zf.entries.sort.map { |e| e.name }, TestFiles::ASCII_TEST_FILES) + assert_equal(zf.entries.sort.map(&:name), TestFiles::ASCII_TEST_FILES) zf.rename(TestFiles::ASCII_TEST_FILES[0], 'newName') assert_not_contains(zf, TestFiles::ASCII_TEST_FILES[0]) @@ -588,7 +591,7 @@ def test_change_comment def test_preserve_file_order entryNames = nil ::Zip::File.open(TEST_ZIP.zip_name) do |zf| - entryNames = zf.entries.map { |e| e.to_s } + entryNames = zf.entries.map(&:to_s) zf.get_output_stream('a.txt') { |os| os.write 'this is a.txt' } zf.get_output_stream('z.txt') { |os| os.write 'this is z.txt' } zf.get_output_stream('k.txt') { |os| os.write 'this is k.txt' } @@ -596,16 +599,16 @@ def test_preserve_file_order end ::Zip::File.open(TEST_ZIP.zip_name) do |zf| - assert_equal(entryNames, zf.entries.map { |e| e.to_s }) - entries = zf.entries.sort_by { |e| e.name }.reverse + assert_equal(entryNames, zf.entries.map(&:to_s)) + entries = zf.entries.sort_by(&:name).reverse entries.each do |e| zf.remove e zf.get_output_stream(e) { |os| os.write 'foo' } end - entryNames = entries.map { |e| e.to_s } + entryNames = entries.map(&:to_s) end ::Zip::File.open(TEST_ZIP.zip_name) do |zf| - assert_equal(entryNames, zf.entries.map { |e| e.to_s }) + assert_equal(entryNames, zf.entries.map(&:to_s)) end end diff --git a/test/filesystem/file_nonmutating_test.rb b/test/filesystem/file_nonmutating_test.rb index 73161cf6..af4db8f2 100644 --- a/test/filesystem/file_nonmutating_test.rb +++ b/test/filesystem/file_nonmutating_test.rb @@ -468,12 +468,12 @@ def test_popen if Zip::RUNNING_ON_WINDOWS # This is pretty much projectile vomit but it allows the test to be # run on windows also - system_dir = ::File.popen('dir') { |f| f.read }.gsub(/Dir\(s\).*$/, '') - zipfile_dir = @zip_file.file.popen('dir') { |f| f.read }.gsub(/Dir\(s\).*$/, '') + system_dir = ::File.popen('dir', &:read).gsub(/Dir\(s\).*$/, '') + zipfile_dir = @zip_file.file.popen('dir', &:read).gsub(/Dir\(s\).*$/, '') assert_equal(system_dir, zipfile_dir) else - assert_equal(::File.popen('ls') { |f| f.read }, - @zip_file.file.popen('ls') { |f| f.read }) + assert_equal(::File.popen('ls', &:read), + @zip_file.file.popen('ls', &:read)) end end From 6cab5922bc778cc89108c6bd3144383ca4d32217 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Thu, 26 Sep 2019 22:00:46 +0100 Subject: [PATCH 45/56] Configure and fix Metrics/LineLength cop. Set a workable line length for now, and fix a couple of particularly bad examples. Also, turn off for the tests. --- .rubocop.yml | 7 ++++++ .rubocop_todo.yml | 9 ++------ lib/zip/file.rb | 6 ++++- lib/zip/output_stream.rb | 4 +++- test/gentestfiles.rb | 46 ++++++++++++++++++++++++++++++-------- test/output_stream_test.rb | 3 ++- 6 files changed, 56 insertions(+), 19 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d40eabcf..4fe77b94 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,13 @@ Layout/HashAlignment: EnforcedHashRocketStyle: table EnforcedColonStyle: table +# Set a workable line length, given the current state of the code, +# and turn off for the tests. +Layout/LineLength: + Max: 135 + Exclude: + - 'test/**/*.rb' + # In some cases we just need to catch an exception, rather than # actually handle it. Allow the tests to make use of this shortcut. Lint/SuppressedException: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9f090fac..8ed38aa7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,6 +37,8 @@ Metrics/CyclomaticComplexity: # Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 45 + Exclude: + - 'test/**/*.rb' # Offense count: 2 # Configuration parameters: CountKeywordArgs. @@ -226,10 +228,3 @@ Style/TernaryParentheses: Style/TrailingCommaInHashLiteral: Exclude: - 'lib/zip/constants.rb' - -# Offense count: 247 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Layout/LineLength: - Max: 236 diff --git a/lib/zip/file.rb b/lib/zip/file.rb index 37dcd921..2d274081 100644 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -264,7 +264,11 @@ def get_input_stream(entry, &aProc) # specified. If a block is passed the stream object is passed to the block and # the stream is automatically closed afterwards just as with ruby's builtin # File.open method. - def get_output_stream(entry, permission_int = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil, &aProc) + def get_output_stream(entry, permission_int = nil, comment = nil, + extra = nil, compressed_size = nil, crc = nil, + compression_method = nil, size = nil, time = nil, + &aProc) + new_entry = if entry.kind_of?(Entry) entry diff --git a/lib/zip/output_stream.rb b/lib/zip/output_stream.rb index fa60e855..978f4b01 100644 --- a/lib/zip/output_stream.rb +++ b/lib/zip/output_stream.rb @@ -130,7 +130,9 @@ def finalize_current_entry return unless @current_entry finish - @current_entry.compressed_size = @output_stream.tell - @current_entry.local_header_offset - @current_entry.calculate_local_header_size + @current_entry.compressed_size = @output_stream.tell - \ + @current_entry.local_header_offset - \ + @current_entry.calculate_local_header_size @current_entry.size = @compressor.size @current_entry.crc = @compressor.crc @output_stream << @encrypter.data_descriptor(@current_entry.crc, @current_entry.compressed_size, @current_entry.size) diff --git a/test/gentestfiles.rb b/test/gentestfiles.rb index 3427ad42..acdada45 100755 --- a/test/gentestfiles.rb +++ b/test/gentestfiles.rb @@ -72,8 +72,12 @@ def initialize(zip_name, entry_names, comment = '') end def self.create_test_zips - raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} test/data/file2.txt") - raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} -d test/data/file2.txt") + raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" \ + unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} test/data/file2.txt") + raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" \ + unless system( + "/usr/bin/zip -q #{TEST_ZIP1.zip_name} -d test/data/file2.txt" + ) File.open('test/data/generated/empty.txt', 'w') {} File.open('test/data/generated/empty_chmod640.txt', 'w') {} @@ -94,19 +98,34 @@ def self.create_test_zips file << testBinaryPattern << rand << "\0" while file.tell < 6E5 end - raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}") + raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" \ + unless system( + "/usr/bin/zip -q #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}" + ) if RUBY_PLATFORM =~ /mswin|mingw|cygwin/ - raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"") + raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" \ + unless system( + "echo #{TEST_ZIP2.comment}| /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"" + ) else # without bash system interprets everything after echo as parameters to # echo including | zip -z ... - raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"") + raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" \ + unless system( + "bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"" + ) end - raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}") + raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" \ + unless system( + "/usr/bin/zip -q #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}" + ) - raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}") + raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" \ + unless system( + "/usr/bin/zip -q #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}" + ) rescue StandardError # If there are any Windows developers wanting to use a command line zip.exe # to help create the following files, there's a free one available from @@ -119,8 +138,17 @@ def self.create_test_zips end TEST_ZIP1 = TestZipFile.new('test/data/generated/empty.zip', []) - TEST_ZIP2 = TestZipFile.new('test/data/generated/5entry.zip', %w[test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin], - 'my zip comment') + TEST_ZIP2 = TestZipFile.new( + 'test/data/generated/5entry.zip', + %w[ + test/data/generated/longAscii.txt + test/data/generated/empty.txt + test/data/generated/empty_chmod640.txt + test/data/generated/short.txt + test/data/generated/longBinary.bin + ], + 'my zip comment' + ) TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w[test/data/file1.txt]) TEST_ZIP4 = TestZipFile.new('test/data/generated/zipWithDir.zip', ['test/data/file1.txt', TestFiles::EMPTY_TEST_DIR]) diff --git a/test/output_stream_test.rb b/test/output_stream_test.rb index 106ba6af..40205076 100644 --- a/test/output_stream_test.rb +++ b/test/output_stream_test.rb @@ -90,7 +90,8 @@ def test_put_next_entry_using_zip_entry_creates_entries_with_correct_timestamps ::Zip::InputStream.open(TEST_ZIP.zip_name) do |io| while (entry = io.get_next_entry) - assert(::Zip::DOSTime.at(file.mtime).dos_equals(::Zip::DOSTime.at(entry.mtime))) # Compare DOS Times, since they are stored with two seconds accuracy + # Compare DOS Times, since they are stored with two seconds accuracy + assert(::Zip::DOSTime.at(file.mtime).dos_equals(::Zip::DOSTime.at(entry.mtime))) end end end From 0e25e63d38723730136ffbee551a872990152c76 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 29 Sep 2019 19:49:16 +0100 Subject: [PATCH 46/56] Turn off Metrics/BlockLength for the tests. --- .rubocop.yml | 5 +++++ .rubocop_todo.yml | 7 ------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 4fe77b94..99c0e84c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -23,6 +23,11 @@ Lint/UselessComparison: Exclude: - 'test/entry_test.rb' +# Turn block length metrics off for the tests. +Metrics/BlockLength: + Exclude: + - 'test/**/*.rb' + # Rubocop confuses these as instances of "memoization". Naming/MemoizedInstanceVariableName: Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8ed38aa7..d165d400 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -18,12 +18,6 @@ Layout/EmptyLinesAroundClassBody: Metrics/AbcSize: Max: 60 -# Offense count: 3 -# Configuration parameters: CountComments, ExcludedMethods. -# ExcludedMethods: refine -Metrics/BlockLength: - Max: 43 - # Offense count: 15 # Configuration parameters: CountComments. Metrics/ClassLength: @@ -210,7 +204,6 @@ Style/SafeNavigation: - 'test/filesystem/file_nonmutating_test.rb' - 'test/filesystem/file_stat_test.rb' - 'test/test_helper.rb' - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, AllowSafeAssignment. From c97d560b691667ab2da6473702c2053ba885edce Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 29 Sep 2019 20:00:07 +0100 Subject: [PATCH 47/56] Configure Metrics/AbcSize and turn off for the tests. --- .rubocop.yml | 7 +++++++ .rubocop_todo.yml | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 99c0e84c..e94a5a88 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -23,6 +23,13 @@ Lint/UselessComparison: Exclude: - 'test/entry_test.rb' +# Turn off ABC metrics for the tests and set a workable max given +# the current state of the code. +Metrics/AbcSize: + Max: 37 + Exclude: + - 'test/**/*.rb' + # Turn block length metrics off for the tests. Metrics/BlockLength: Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d165d400..09e6b00a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,10 +14,6 @@ Layout/EmptyLinesAroundClassBody: Exclude: - 'test/extra_field_ut_test.rb' -# Offense count: 120 -Metrics/AbcSize: - Max: 60 - # Offense count: 15 # Configuration parameters: CountComments. Metrics/ClassLength: From 5ce4e13ddd33443f01fa33c8208423b76d99fce3 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Mon, 30 Sep 2019 19:32:25 +0100 Subject: [PATCH 48/56] Configure and fix Style/ClassCheck cop. --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 14 -------------- lib/zip/entry.rb | 6 +++--- lib/zip/file.rb | 6 +++--- lib/zip/input_stream.rb | 2 +- lib/zip/output_stream.rb | 4 ++-- test/filesystem/file_nonmutating_test.rb | 2 +- 7 files changed, 14 insertions(+), 24 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e94a5a88..5ae4e6f6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 09e6b00a..81a0b020 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index a3ad4997..a67c6568 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -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 encrypted? @@ -271,7 +271,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) @@ -380,7 +380,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)) diff --git a/lib/zip/file.rb b/lib/zip/file.rb index 2d274081..c768d07d 100644 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -141,11 +141,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) @@ -344,7 +344,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| diff --git a/lib/zip/input_stream.rb b/lib/zip/input_stream.rb index 8d86897c..f942d190 100644 --- a/lib/zip/input_stream.rb +++ b/lib/zip/input_stream.rb @@ -122,7 +122,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.encrypted? && @decrypter.is_a?(NullEncrypter) + if @current_entry && @current_entry.encrypted? && @decrypter.kind_of?(NullEncrypter) raise Error, 'password required to decode zip file' end diff --git a/lib/zip/output_stream.rb b/lib/zip/output_stream.rb index 978f4b01..2f628931 100644 --- a/lib/zip/output_stream.rb +++ b/lib/zip/output_stream.rb @@ -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) @@ -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 diff --git a/test/filesystem/file_nonmutating_test.rb b/test/filesystem/file_nonmutating_test.rb index af4db8f2..cfe18ade 100644 --- a/test/filesystem/file_nonmutating_test.rb +++ b/test/filesystem/file_nonmutating_test.rb @@ -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 From a9adfa26d6f18f891673e4266826b2ea4acc489a Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 20:08:53 +0000 Subject: [PATCH 49/56] Configure Metrics/ClassLength and turn off for the tests. --- .rubocop.yml | 5 +++++ .rubocop_todo.yml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5ae4e6f6..2849a925 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -35,6 +35,11 @@ Metrics/BlockLength: Exclude: - 'test/**/*.rb' +# Turn class length metrics off for the tests. +Metrics/ClassLength: + Exclude: + - 'test/**/*.rb' + # Rubocop confuses these as instances of "memoization". Naming/MemoizedInstanceVariableName: Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 81a0b020..a5bd0ee4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -17,7 +17,7 @@ Layout/EmptyLinesAroundClassBody: # Offense count: 15 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 579 + Max: 580 # Offense count: 26 Metrics/CyclomaticComplexity: From a187ec0c3899e9f6fc5d03855a5e0801db5a5890 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 21:54:10 +0000 Subject: [PATCH 50/56] Configure Metrics/MethodLength and turn off for the tests. --- .rubocop.yml | 5 +++++ .rubocop_todo.yml | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2849a925..a3ccce57 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -40,6 +40,11 @@ Metrics/ClassLength: Exclude: - 'test/**/*.rb' +# Turn method length metrics off for the tests. +Metrics/MethodLength: + Exclude: + - 'test/**/*.rb' + # Rubocop confuses these as instances of "memoization". Naming/MemoizedInstanceVariableName: Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a5bd0ee4..c2e7565e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -26,9 +26,7 @@ Metrics/CyclomaticComplexity: # Offense count: 120 # Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: - Max: 45 - Exclude: - - 'test/**/*.rb' + Max: 30 # Offense count: 2 # Configuration parameters: CountKeywordArgs. From 4b8f74042aef46b7271c66f1331e7143ca79f649 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 22:09:00 +0000 Subject: [PATCH 51/56] Fix Layout/EmptyLinesAroundClassBody cop. --- .rubocop_todo.yml | 8 -------- test/extra_field_ut_test.rb | 1 - 2 files changed, 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c2e7565e..47a86b10 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'test/extra_field_ut_test.rb' - # Offense count: 15 # Configuration parameters: CountComments. Metrics/ClassLength: diff --git a/test/extra_field_ut_test.rb b/test/extra_field_ut_test.rb index ad2ab7a6..6b854978 100644 --- a/test/extra_field_ut_test.rb +++ b/test/extra_field_ut_test.rb @@ -1,7 +1,6 @@ require 'test_helper' class ZipExtraFieldUTTest < MiniTest::Test - PARSE_TESTS = [ ["UT\x05\x00\x01PS>A", 0b001, true, true, false], ["UT\x05\x00\x02PS>A", 0b010, false, true, true], From fae95e3c2984ce7ef5863627cca2cac1ddb4f420 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 22:38:18 +0000 Subject: [PATCH 52/56] Fix Style/NumericLiteralPrefix cop. --- .rubocop_todo.yml | 8 -------- test/file_options_test.rb | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 47a86b10..1b7af436 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -130,14 +130,6 @@ Style/ModuleFunction: Style/MutableConstant: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedOctalStyle. -# SupportedOctalStyles: zero_with_o, zero_only -Style/NumericLiteralPrefix: - Exclude: - - 'test/file_options_test.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: Strict. diff --git a/test/file_options_test.rb b/test/file_options_test.rb index 1a73e980..61b86e85 100644 --- a/test/file_options_test.rb +++ b/test/file_options_test.rb @@ -24,9 +24,9 @@ def teardown def test_restore_permissions # Copy and set up files with different permissions. ::FileUtils.cp(TXTPATH, TXTPATH_600) - ::File.chmod(0600, TXTPATH_600) + ::File.chmod(0o600, TXTPATH_600) ::FileUtils.cp(TXTPATH, TXTPATH_755) - ::File.chmod(0755, TXTPATH_755) + ::File.chmod(0o755, TXTPATH_755) ::Zip::File.open(ZIPPATH, true) do |zip| zip.add(ENTRY_1, TXTPATH) From d07b36b2e63b2b51feb0a935fe7e7c4bb169c1c3 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 22:44:08 +0000 Subject: [PATCH 53/56] Fix Style/TernaryParentheses cop. --- .rubocop_todo.yml | 9 --------- lib/zip/crypto/decrypted_io.rb | 2 +- lib/zip/inflater.rb | 2 +- lib/zip/pass_thru_decompressor.rb | 2 +- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1b7af436..283ebbde 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -168,15 +168,6 @@ Style/SafeNavigation: - 'test/filesystem/file_nonmutating_test.rb' - 'test/filesystem/file_stat_test.rb' - 'test/test_helper.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowSafeAssignment. -# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex -Style/TernaryParentheses: - Exclude: - - 'lib/zip/crypto/decrypted_io.rb' - - 'lib/zip/inflater.rb' - - 'lib/zip/pass_thru_decompressor.rb' # Offense count: 1 # Cop supports --auto-correct. diff --git a/lib/zip/crypto/decrypted_io.rb b/lib/zip/crypto/decrypted_io.rb index 8d8191f0..61a377da 100644 --- a/lib/zip/crypto/decrypted_io.rb +++ b/lib/zip/crypto/decrypted_io.rb @@ -8,7 +8,7 @@ def initialize(io, decrypter) end def read(length = nil, outbuf = +'') - return ((length.nil? || length.zero?) ? '' : nil) if eof + return (length.nil? || length.zero? ? '' : nil) if eof while length.nil? || (buffer.bytesize < length) break if input_finished? diff --git a/lib/zip/inflater.rb b/lib/zip/inflater.rb index 609ccc79..530f98aa 100644 --- a/lib/zip/inflater.rb +++ b/lib/zip/inflater.rb @@ -8,7 +8,7 @@ def initialize(*args) end def read(length = nil, outbuf = '') - return ((length.nil? || length.zero?) ? '' : nil) if eof + return (length.nil? || length.zero? ? '' : nil) if eof while length.nil? || (@buffer.bytesize < length) break if input_finished? diff --git a/lib/zip/pass_thru_decompressor.rb b/lib/zip/pass_thru_decompressor.rb index d7892ce4..e638540e 100644 --- a/lib/zip/pass_thru_decompressor.rb +++ b/lib/zip/pass_thru_decompressor.rb @@ -6,7 +6,7 @@ def initialize(*args) end def read(length = nil, outbuf = '') - return ((length.nil? || length.zero?) ? '' : nil) if eof + return (length.nil? || length.zero? ? '' : nil) if eof if length.nil? || (@read_so_far + length) > decompressed_size length = decompressed_size - @read_so_far From 989a565340c8cd60f80f59705d41af869ab02acf Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 22:45:54 +0000 Subject: [PATCH 54/56] Fix Style/TrailingCommaInHashLiteral cop. --- .rubocop_todo.yml | 8 -------- lib/zip/constants.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 283ebbde..99681397 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -168,11 +168,3 @@ Style/SafeNavigation: - 'test/filesystem/file_nonmutating_test.rb' - 'test/filesystem/file_stat_test.rb' - 'test/test_helper.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'lib/zip/constants.rb' diff --git a/lib/zip/constants.rb b/lib/zip/constants.rb index 428c5126..fe89847a 100644 --- a/lib/zip/constants.rb +++ b/lib/zip/constants.rb @@ -110,6 +110,6 @@ module Zip COMPRESSION_METHOD_JPEG => 'JPEG variant', COMPRESSION_METHOD_WAVPACK => 'WavPack compressed data', COMPRESSION_METHOD_PPMD => 'PPMd version I, Rev 1', - COMPRESSION_METHOD_AES => 'AES encryption', + COMPRESSION_METHOD_AES => 'AES encryption' }.freeze end From c31ab81cf62b37c414ce54ea0ee1c6aadceb245a Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 9 Feb 2020 22:49:06 +0000 Subject: [PATCH 55/56] Fix Style/NumericLiterals cop. --- .rubocop_todo.yml | 6 ------ test/stored_support_test.rb | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 99681397..4bff4fa4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -130,12 +130,6 @@ Style/ModuleFunction: Style/MutableConstant: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: Strict. -Style/NumericLiterals: - MinDigits: 6 - # Offense count: 23 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. diff --git a/test/stored_support_test.rb b/test/stored_support_test.rb index e0d3ae0e..28836b9e 100644 --- a/test/stored_support_test.rb +++ b/test/stored_support_test.rb @@ -10,11 +10,11 @@ def test_read Zip::InputStream.open(STORED_ZIP_TEST_FILE) do |zis| entry = zis.get_next_entry assert_equal 'file1.txt', entry.name - assert_equal 1327, entry.size + assert_equal 1_327, entry.size assert_equal ::File.open(INPUT_FILE1, 'r').read, zis.read entry = zis.get_next_entry assert_equal 'file2.txt', entry.name - assert_equal 41234, entry.size + assert_equal 41_234, entry.size assert_equal ::File.open(INPUT_FILE2, 'r').read, zis.read end end @@ -23,11 +23,11 @@ def test_encrypted_read Zip::InputStream.open(ENCRYPTED_STORED_ZIP_TEST_FILE, 0, Zip::TraditionalDecrypter.new('password')) do |zis| entry = zis.get_next_entry assert_equal 'file1.txt', entry.name - assert_equal 1327, entry.size + assert_equal 1_327, entry.size assert_equal ::File.open(INPUT_FILE1, 'r').read, zis.read entry = zis.get_next_entry assert_equal 'file2.txt', entry.name - assert_equal 41234, entry.size + assert_equal 41_234, entry.size assert_equal ::File.open(INPUT_FILE2, 'r').read, zis.read end end From 87a63e0cc3de00e0ad01c82b7f7086671f9707f1 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 15 Feb 2020 16:12:57 +0000 Subject: [PATCH 56/56] Set TargetRubyVersion to match that in the gemspec. Currently 2.4 is the earliest supported ruby version. --- .rubocop.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index a3ccce57..27712bd8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,10 @@ 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 + Layout/HashAlignment: EnforcedHashRocketStyle: table EnforcedColonStyle: table