diff --git a/Library/Homebrew/development_tools.rb b/Library/Homebrew/development_tools.rb index 9d900f5a0f101..5a379a04f12de 100644 --- a/Library/Homebrew/development_tools.rb +++ b/Library/Homebrew/development_tools.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "version" @@ -16,7 +16,7 @@ def locate(tool) # Don't call tools (cc, make, strip, etc.) directly! # Give the name of the binary you look for as a string to this method # in order to get the full path back as a Pathname. - (@locate ||= {}).fetch(tool) do |key| + (@locate ||= T.let({}, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]))).fetch(tool) do |key| @locate[key] = if File.executable?((path = "/usr/bin/#{tool}")) Pathname.new path # Homebrew GCCs most frequently; much faster to check this before xcrun @@ -62,12 +62,14 @@ def default_compiler # @api public sig { returns(Version) } def clang_version - @clang_version ||= if (path = locate("clang")) && - (build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1]) - Version.new build_version - else - Version::NULL - end + @clang_version ||= T.let( + if (path = locate("clang")) && + (build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1]) + Version.new(build_version) + else + Version::NULL + end, T.nilable(Version) + ) end # Get the Clang build version. @@ -75,13 +77,14 @@ def clang_version # @api public sig { returns(Version) } def clang_build_version - @clang_build_version ||= if (path = locate("clang")) && - (build_version = `#{path} --version`[ -%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2]) - Version.new build_version - else - Version::NULL - end + @clang_build_version ||= T.let( + if (path = locate("clang")) && + (build_version = `#{path} --version`[%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2]) + Version.new(build_version) + else + Version::NULL + end, T.nilable(Version) + ) end # Get the LLVM Clang build version. @@ -89,15 +92,14 @@ def clang_build_version # @api public sig { returns(Version) } def llvm_clang_build_version - @llvm_clang_build_version ||= begin + @llvm_clang_build_version ||= T.let(begin path = Formulary.factory("llvm").opt_prefix/"bin/clang" - if path.executable? && - (build_version = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1]) - Version.new build_version + if path.executable? && (build_version = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1]) + Version.new(build_version) else Version::NULL end - end + end, T.nilable(Version)) end # Get the GCC version. @@ -105,12 +107,12 @@ def llvm_clang_build_version # @api internal sig { params(cc: String).returns(Version) } def gcc_version(cc) - (@gcc_version ||= {}).fetch(cc) do + (@gcc_version ||= T.let({}, T.nilable(T::Hash[String, Version]))).fetch(cc) do path = HOMEBREW_PREFIX/"opt/#{CompilerSelector.preferred_gcc}/bin"/cc path = locate(cc) unless path.exist? version = if path && (build_version = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1]) - Version.new build_version + Version.new(build_version) else Version::NULL end @@ -120,8 +122,8 @@ def gcc_version(cc) sig { void } def clear_version_cache - @clang_version = @clang_build_version = nil - @gcc_version = {} + @clang_version = @clang_build_version = T.let(nil, T.nilable(Version)) + @gcc_version = T.let({}, T.nilable(T::Hash[String, Version])) end sig { returns(T::Boolean) } diff --git a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb index da2ec316920e0..f220474ddd040 100644 --- a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb +++ b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb @@ -8,7 +8,7 @@ class Zip module MacOSZipExtension private - sig { params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) with_env(TZ: "UTC") do if merge_xattrs && contains_extended_attributes?(path) diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb index a7d6d0dd77e40..db3320b62a5f4 100644 --- a/Library/Homebrew/formula_assertions.rb +++ b/Library/Homebrew/formula_assertions.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module Homebrew @@ -10,15 +10,18 @@ module Assertions require "minitest/assertions" include ::Minitest::Assertions + sig { params(assertions: Integer).returns(Integer) } attr_writer :assertions + sig { returns(Integer) } def assertions - @assertions ||= 0 + @assertions ||= T.let(0, T.nilable(Integer)) end # Returns the output of running cmd and asserts the exit status. # # @api public + sig { params(cmd: String, result: Integer).returns(String) } def shell_output(cmd, result = 0) ohai cmd output = `#{cmd}` @@ -33,6 +36,7 @@ def shell_output(cmd, result = 0) # optionally asserts the exit status. # # @api public + sig { params(cmd: String, input: T.nilable(String), result: T.nilable(Integer)).returns(String) } def pipe_output(cmd, input = nil, result = nil) ohai cmd output = IO.popen(cmd, "w+") do |pipe| diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 74e49473cbcaa..b3581c8ad75f9 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "system_command" @@ -6,11 +6,30 @@ # Module containing all available strategies for unpacking archives. module UnpackStrategy extend T::Helpers - include SystemCommand::Mixin + abstract! + + # FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed. + # rubocop:disable Style/MutableConstant + UnpackStrategyType = T.type_alias { T.all(T::Class[UnpackStrategy], UnpackStrategy::ClassMethods) } + # rubocop:enable Style/MutableConstant + + module ClassMethods + extend T::Helpers + abstract! + + sig { abstract.returns(T::Array[String]) } + def extensions; end + sig { abstract.params(path: Pathname).returns(T::Boolean) } + def can_extract?(path); end + end + + mixes_in_class_methods(ClassMethods) + + sig { returns(T.nilable(T::Array[UnpackStrategyType])) } def self.strategies - @strategies ||= [ + @strategies ||= T.let([ Tar, # Needs to be before Bzip2/Gzip/Xz/Lzma/Zstd. Pax, Gzip, @@ -43,10 +62,11 @@ def self.strategies Sit, Rar, Lha, - ].freeze + ].freeze, T.nilable(T::Array[UnpackStrategyType])) end private_class_method :strategies + sig { params(type: Symbol).returns(T.nilable(UnpackStrategyType)) } def self.from_type(type) type = { naked: :uncompressed, @@ -61,23 +81,31 @@ def self.from_type(type) end end + sig { params(extension: String).returns(T.nilable(UnpackStrategyType)) } def self.from_extension(extension) - strategies.sort_by { |s| s.extensions.map(&:length).max || 0 } - .reverse - .find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } } + return unless strategies + + strategies&.sort_by { |s| s.extensions.map(&:length).max || 0 } + &.reverse + &.find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } } end + sig { params(path: Pathname).returns(T.nilable(UnpackStrategyType)) } def self.from_magic(path) - strategies.find { |s| s.can_extract?(path) } + strategies&.find { |s| s.can_extract?(path) } end - def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil) + sig { + params(path: Pathname, prioritize_extension: T::Boolean, type: T.nilable(Symbol), ref_type: T.nilable(Symbol), + ref: T.nilable(String), merge_xattrs: T::Boolean).returns(T.untyped) + } + def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: false) strategy = from_type(type) if type if prioritize_extension && path.extname.present? strategy ||= from_extension(path.extname) - strategy ||= strategies.select { |s| s < Directory || s == Fossil } - .find { |s| s.can_extract?(path) } + + strategy ||= strategies&.find { |s| (s < Directory || s == Fossil) && s.can_extract?(path) } else strategy ||= from_magic(path) strategy ||= from_extension(path.extname) @@ -88,24 +116,31 @@ def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref strategy.new(path, ref_type:, ref:, merge_xattrs:) end - attr_reader :path, :merge_xattrs + sig { returns(Pathname) } + attr_reader :path - def initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil) - @path = Pathname(path).expand_path - @ref_type = ref_type - @ref = ref - @merge_xattrs = merge_xattrs + sig { returns(T::Boolean) } + attr_reader :merge_xattrs + + sig { + params(path: T.any(String, Pathname), ref_type: T.nilable(Symbol), ref: T.nilable(String), + merge_xattrs: T::Boolean).void + } + def initialize(path, ref_type: nil, ref: nil, merge_xattrs: false) + @path = T.let(Pathname(path).expand_path, Pathname) + @ref_type = T.let(ref_type, T.nilable(Symbol)) + @ref = T.let(ref, T.nilable(String)) + @merge_xattrs = T.let(merge_xattrs, T::Boolean) end - abstract! - sig { abstract.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { abstract.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:); end private :extract_to_dir sig { params( to: T.nilable(Pathname), basename: T.nilable(T.any(String, Pathname)), verbose: T::Boolean, - ).returns(T.untyped) + ).void } def extract(to: nil, basename: nil, verbose: false) basename ||= path.basename @@ -131,7 +166,10 @@ def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extensio children = tmp_unpack_dir.children if children.size == 1 && !children.fetch(0).directory? - s = UnpackStrategy.detect(children.first, prioritize_extension:) + first_child = children.first + next if first_child.nil? + + s = UnpackStrategy.detect(first_child, prioritize_extension:) s.extract_nestedly(to:, verbose:, prioritize_extension:) @@ -149,6 +187,7 @@ def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extensio end end + sig { returns(T::Array[String]) } def dependencies [] end diff --git a/Library/Homebrew/unpack_strategy/air.rb b/Library/Homebrew/unpack_strategy/air.rb index c4a6ba601a8b5..6415995419295 100644 --- a/Library/Homebrew/unpack_strategy/air.rb +++ b/Library/Homebrew/unpack_strategy/air.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,18 +6,20 @@ module UnpackStrategy class Air include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".air"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) mime_type = "application/vnd.adobe.air-application-installer-package+zip" path.magic_number.match?(/.{59}#{Regexp.escape(mime_type)}/) end + sig { returns(T.nilable(T::Array[Cask::Cask])) } def dependencies - @dependencies ||= [Cask::CaskLoader.load("adobe-air")] + @dependencies ||= T.let([Cask::CaskLoader.load("adobe-air")], T.nilable(T::Array[Cask::Cask])) end AIR_APPLICATION_INSTALLER = @@ -27,7 +29,7 @@ def dependencies private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! AIR_APPLICATION_INSTALLER, args: ["-silent", "-location", unpack_dir, path], diff --git a/Library/Homebrew/unpack_strategy/bazaar.rb b/Library/Homebrew/unpack_strategy/bazaar.rb index f73902b3aaf7f..770cca92aad86 100644 --- a/Library/Homebrew/unpack_strategy/bazaar.rb +++ b/Library/Homebrew/unpack_strategy/bazaar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,13 +6,14 @@ module UnpackStrategy # Strategy for unpacking Bazaar archives. class Bazaar < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/".bzr").directory? + !!(super && (path/".bzr").directory?) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) super diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index af1248c466f53..12190c6a6995d 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,18 +6,19 @@ module UnpackStrategy class Bzip2 include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".bz2"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\ABZh/n) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/cab.rb b/Library/Homebrew/unpack_strategy/cab.rb index af73d82fdd008..a4cc7993a6c06 100644 --- a/Library/Homebrew/unpack_strategy/cab.rb +++ b/Library/Homebrew/unpack_strategy/cab.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,16 +6,17 @@ module UnpackStrategy class Cab include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".cab"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\AMSCF/n) end - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "cabextract", args: ["-d", unpack_dir, "--", path], @@ -23,8 +24,9 @@ def extract_to_dir(unpack_dir, basename:, verbose:) verbose: end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["cabextract"]] + @dependencies ||= T.let([Formula["cabextract"]], T.nilable(T::Array[Formula])) end end end diff --git a/Library/Homebrew/unpack_strategy/compress.rb b/Library/Homebrew/unpack_strategy/compress.rb index 00823122144e6..504f31390bb0c 100644 --- a/Library/Homebrew/unpack_strategy/compress.rb +++ b/Library/Homebrew/unpack_strategy/compress.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "tar" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking compress archives. class Compress < Tar - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".Z"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A\037\235/n) end diff --git a/Library/Homebrew/unpack_strategy/cvs.rb b/Library/Homebrew/unpack_strategy/cvs.rb index af6f0a3a7755b..7e3c5b018b178 100644 --- a/Library/Homebrew/unpack_strategy/cvs.rb +++ b/Library/Homebrew/unpack_strategy/cvs.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,8 +6,9 @@ module UnpackStrategy # Strategy for unpacking CVS repositories. class Cvs < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/"CVS").directory? + !!(super && (path/"CVS").directory?) end end end diff --git a/Library/Homebrew/unpack_strategy/directory.rb b/Library/Homebrew/unpack_strategy/directory.rb index 90b5ade18e772..62c76284bd014 100644 --- a/Library/Homebrew/unpack_strategy/directory.rb +++ b/Library/Homebrew/unpack_strategy/directory.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,18 +6,19 @@ module UnpackStrategy class Directory include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.directory? end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) path.children.each do |child| system_command! "cp", diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index 92c7f8ca49fd5..b63bd439f507f 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -121,9 +121,15 @@ def eject(verbose: false) end end + sig { override.returns(T::Array[String]) } + def self.extensions = [] + + sig { override.params(_path: Pathname).returns(T::Boolean) } + def self.can_extract?(_path) = false + private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) tries = 3 bom = begin @@ -165,7 +171,7 @@ def extract_to_dir(unpack_dir, basename:, verbose:) end private_constant :Mount - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".dmg"] end @@ -177,7 +183,7 @@ def self.can_extract?(path) private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) mount(verbose:) do |mounts| raise "No mounts found in '#{path}'; perhaps this is a bad disk image?" if mounts.empty? diff --git a/Library/Homebrew/unpack_strategy/executable.rb b/Library/Homebrew/unpack_strategy/executable.rb index 4c5e712da815f..51cf812786e55 100644 --- a/Library/Homebrew/unpack_strategy/executable.rb +++ b/Library/Homebrew/unpack_strategy/executable.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking executables. class Executable < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".sh", ".bash"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A#!\s*\S+/n) || path.magic_number.match?(/\AMZ/n) diff --git a/Library/Homebrew/unpack_strategy/fossil.rb b/Library/Homebrew/unpack_strategy/fossil.rb index 1e2dcc00a8871..8914c05aa8a7f 100644 --- a/Library/Homebrew/unpack_strategy/fossil.rb +++ b/Library/Homebrew/unpack_strategy/fossil.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "system_command" @@ -9,11 +9,12 @@ class Fossil include UnpackStrategy extend SystemCommand::Mixin - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return false unless path.magic_number.match?(/\ASQLite format 3\000/n) @@ -24,7 +25,7 @@ def self.can_extract?(path) private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) args = if @ref_type && @ref [@ref] diff --git a/Library/Homebrew/unpack_strategy/generic_unar.rb b/Library/Homebrew/unpack_strategy/generic_unar.rb index 0aee0ce3ac347..ecc6e2c256ec9 100644 --- a/Library/Homebrew/unpack_strategy/generic_unar.rb +++ b/Library/Homebrew/unpack_strategy/generic_unar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,22 +6,24 @@ module UnpackStrategy class GenericUnar include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [] end + sig { override.params(_path: Pathname).returns(T::Boolean) } def self.can_extract?(_path) false end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["unar"]] + @dependencies ||= T.let([Formula["unar"]], T.nilable(T::Array[Formula])) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "unar", args: [ diff --git a/Library/Homebrew/unpack_strategy/git.rb b/Library/Homebrew/unpack_strategy/git.rb index ab39f3c4e0cc5..42b906f125d6b 100644 --- a/Library/Homebrew/unpack_strategy/git.rb +++ b/Library/Homebrew/unpack_strategy/git.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,8 +6,9 @@ module UnpackStrategy # Strategy for unpacking Git repositories. class Git < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/".git").directory? + !!(super && (path/".git").directory?) end end end diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index 2ece0befdc456..b525cc6d0b1f0 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,18 +6,19 @@ module UnpackStrategy class Gzip include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".gz"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A\037\213/n) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/jar.rb b/Library/Homebrew/unpack_strategy/jar.rb index 892357b48be76..0be166bbaaebe 100644 --- a/Library/Homebrew/unpack_strategy/jar.rb +++ b/Library/Homebrew/unpack_strategy/jar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking Java archives. class Jar < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".apk", ".jar"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/lha.rb b/Library/Homebrew/unpack_strategy/lha.rb index 1da3021ad70d4..0fdb49ed55a5a 100644 --- a/Library/Homebrew/unpack_strategy/lha.rb +++ b/Library/Homebrew/unpack_strategy/lha.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,22 +6,24 @@ module UnpackStrategy class Lha include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".lha", ".lzh"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A..-(lh0|lh1|lz4|lz5|lzs|lh\\40|lhd|lh2|lh3|lh4|lh5)-/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["lha"]] + @dependencies ||= T.let([Formula["lha"]], T.nilable(T::Array[Formula])) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "lha", args: ["xq2w=#{unpack_dir}", path], diff --git a/Library/Homebrew/unpack_strategy/lua_rock.rb b/Library/Homebrew/unpack_strategy/lua_rock.rb index a01fcd2f88d31..f806364a0f046 100644 --- a/Library/Homebrew/unpack_strategy/lua_rock.rb +++ b/Library/Homebrew/unpack_strategy/lua_rock.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking LuaRock archives. class LuaRock < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".rock"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index 668aa4fdcfc18..710f3684db1d5 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,22 +6,24 @@ module UnpackStrategy class Lzip include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".lz"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\ALZIP/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["lzip"]] + @dependencies ||= T.let([Formula["lzip"]], T.nilable(T::Array[Formula])) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index d529e2de4c4f3..d1b6710c42e54 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,22 +6,24 @@ module UnpackStrategy class Lzma include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".lzma"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A\]\000\000\200\000/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["xz"]] + @dependencies ||= T.let([Formula["xz"]], T.nilable(T::Array[Formula])) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/mercurial.rb b/Library/Homebrew/unpack_strategy/mercurial.rb index c4a77d4d0df0f..146f686c9c0a6 100644 --- a/Library/Homebrew/unpack_strategy/mercurial.rb +++ b/Library/Homebrew/unpack_strategy/mercurial.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,12 +6,14 @@ module UnpackStrategy # Strategy for unpacking Mercurial repositories. class Mercurial < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/".hg").directory? + !!(super && (path/".hg").directory?) end private + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "hg", args: ["--cwd", path, "archive", "--subrepos", "-y", "-t", "files", unpack_dir], diff --git a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb index 2ad2a40644cd8..cb54b9b1f7235 100644 --- a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb +++ b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -6,7 +6,7 @@ module UnpackStrategy # Strategy for unpacking Microsoft Office documents. class MicrosoftOfficeXml < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [ ".doc", ".docx", @@ -15,6 +15,7 @@ def self.extensions ] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/otf.rb b/Library/Homebrew/unpack_strategy/otf.rb index 7a75f78c4cdc7..da593812a5639 100644 --- a/Library/Homebrew/unpack_strategy/otf.rb +++ b/Library/Homebrew/unpack_strategy/otf.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking OpenType fonts. class Otf < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".otf"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\AOTTO/n) end diff --git a/Library/Homebrew/unpack_strategy/p7zip.rb b/Library/Homebrew/unpack_strategy/p7zip.rb index 19e0154491d59..44a8c4b986544 100644 --- a/Library/Homebrew/unpack_strategy/p7zip.rb +++ b/Library/Homebrew/unpack_strategy/p7zip.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,22 +6,24 @@ module UnpackStrategy class P7Zip include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".7z"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A7z\xBC\xAF\x27\x1C/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["p7zip"]] + @dependencies ||= T.let([Formula["p7zip"]], T.nilable(T::Array[Formula])) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "7zr", args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"], diff --git a/Library/Homebrew/unpack_strategy/pax.rb b/Library/Homebrew/unpack_strategy/pax.rb index 9a47b9d1d531b..9cbc799c23f64 100644 --- a/Library/Homebrew/unpack_strategy/pax.rb +++ b/Library/Homebrew/unpack_strategy/pax.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,18 +6,19 @@ module UnpackStrategy class Pax include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".pax"] end + sig { override.params(_path: Pathname).returns(T::Boolean) } def self.can_extract?(_path) false end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "pax", args: ["-rf", path], diff --git a/Library/Homebrew/unpack_strategy/pkg.rb b/Library/Homebrew/unpack_strategy/pkg.rb index b48a55244b07a..585edfbea95fd 100644 --- a/Library/Homebrew/unpack_strategy/pkg.rb +++ b/Library/Homebrew/unpack_strategy/pkg.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking macOS package installers. class Pkg < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".pkg", ".mkpg"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.extname.match?(/\A.m?pkg\Z/) && (path.directory? || path.magic_number.match?(/\Axar!/n)) diff --git a/Library/Homebrew/unpack_strategy/rar.rb b/Library/Homebrew/unpack_strategy/rar.rb index 289da9134c480..7d8109d654cae 100644 --- a/Library/Homebrew/unpack_strategy/rar.rb +++ b/Library/Homebrew/unpack_strategy/rar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,22 +6,24 @@ module UnpackStrategy class Rar include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".rar"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\ARar!/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["libarchive"]] + @dependencies ||= T.let([Formula["libarchive"]], T.nilable(T::Array[Formula])) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "bsdtar", args: ["x", "-f", path, "-C", unpack_dir], diff --git a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb index b32cfa825cff4..58bad3be74057 100644 --- a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb +++ b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "generic_unar" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking self-extracting executables. class SelfExtractingExecutable < GenericUnar - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\AMZ/n) && path.file_type.include?("self-extracting archive") diff --git a/Library/Homebrew/unpack_strategy/sit.rb b/Library/Homebrew/unpack_strategy/sit.rb index 7d447eaf69faa..82c48e6d19ba2 100644 --- a/Library/Homebrew/unpack_strategy/sit.rb +++ b/Library/Homebrew/unpack_strategy/sit.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "generic_unar" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking Stuffit archives. class Sit < GenericUnar - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".sit"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\AStuffIt/n) end diff --git a/Library/Homebrew/unpack_strategy/subversion.rb b/Library/Homebrew/unpack_strategy/subversion.rb index 7ba74fa5e0f0b..81c037d73e81d 100644 --- a/Library/Homebrew/unpack_strategy/subversion.rb +++ b/Library/Homebrew/unpack_strategy/subversion.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,12 +6,14 @@ module UnpackStrategy # Strategy for unpacking Subversion repositories. class Subversion < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/".svn").directory? + !!(super && (path/".svn").directory?) end private + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "svn", args: ["export", "--force", ".", unpack_dir], diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index c3300e7155d47..ae3ff08cd233b 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "system_command" @@ -9,7 +9,7 @@ class Tar include UnpackStrategy extend SystemCommand::Mixin - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [ ".tar", @@ -22,6 +22,7 @@ def self.extensions ] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return true if path.magic_number.match?(/\A.{257}ustar/n) @@ -34,7 +35,7 @@ def self.can_extract?(path) private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) Dir.mktmpdir("homebrew-tar", HOMEBREW_TEMP) do |tmpdir| tar_path = if DependencyCollector.tar_needs_xz_dependency? && Xz.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/ttf.rb b/Library/Homebrew/unpack_strategy/ttf.rb index d741378d29583..c240f936792b6 100644 --- a/Library/Homebrew/unpack_strategy/ttf.rb +++ b/Library/Homebrew/unpack_strategy/ttf.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -6,11 +6,12 @@ module UnpackStrategy # Strategy for unpacking TrueType fonts. class Ttf < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".ttc", ".ttf"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) # TrueType Font path.magic_number.match?(/\A\000\001\000\000\000/n) || diff --git a/Library/Homebrew/unpack_strategy/uncompressed.rb b/Library/Homebrew/unpack_strategy/uncompressed.rb index 5d2c3dd511318..58e70082e96be 100644 --- a/Library/Homebrew/unpack_strategy/uncompressed.rb +++ b/Library/Homebrew/unpack_strategy/uncompressed.rb @@ -6,6 +6,12 @@ module UnpackStrategy class Uncompressed include UnpackStrategy + sig { override.returns(T::Array[String]) } + def self.extensions = [] + + sig { override.params(_path: Pathname).returns(T::Boolean) } + def self.can_extract?(_path) = false + sig { params( to: T.nilable(Pathname), @@ -20,7 +26,7 @@ def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extensio private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose: false) FileUtils.cp path, unpack_dir/basename.sub(/^[\da-f]{64}--/, ""), preserve: true, verbose: end diff --git a/Library/Homebrew/unpack_strategy/xar.rb b/Library/Homebrew/unpack_strategy/xar.rb index f473d35c79099..d6562f8d22f5f 100644 --- a/Library/Homebrew/unpack_strategy/xar.rb +++ b/Library/Homebrew/unpack_strategy/xar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,18 +6,19 @@ module UnpackStrategy class Xar include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".xar"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\Axar!/n) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "xar", args: ["-x", "-f", path, "-C", unpack_dir], diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 7ac0ceb4e6c38..2e155c687b114 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,22 +6,24 @@ module UnpackStrategy class Xz include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".xz"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A\xFD7zXZ\x00/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["xz"]] + @dependencies ||= T.let([Formula["xz"]], T.nilable(T::Array[Formula])) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/zip.rb b/Library/Homebrew/unpack_strategy/zip.rb index dc4d6d350b5b9..28e413e00adad 100644 --- a/Library/Homebrew/unpack_strategy/zip.rb +++ b/Library/Homebrew/unpack_strategy/zip.rb @@ -6,12 +6,12 @@ module UnpackStrategy class Zip include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".zip"] end - sig { params(path: Pathname).returns(T::Boolean) } + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\APK(\003\004|\005\006)/n) end @@ -23,6 +23,7 @@ def self.can_extract?(path) .returns(SystemCommand::Result) } def extract_to_dir(unpack_dir, basename:, verbose:) + odebug "in unpack_strategy, zip, extract_to_dir, verbose: #{verbose.inspect}" unzip = if which("unzip").blank? begin Formula["unzip"] diff --git a/Library/Homebrew/unpack_strategy/zstd.rb b/Library/Homebrew/unpack_strategy/zstd.rb index f8cdacb0abec3..475b0ca518e49 100644 --- a/Library/Homebrew/unpack_strategy/zstd.rb +++ b/Library/Homebrew/unpack_strategy/zstd.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -6,22 +6,24 @@ module UnpackStrategy class Zstd include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".zst"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\x28\xB5\x2F\xFD/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["zstd"]] + @dependencies ||= T.let([Formula["zstd"]], T.nilable(T::Array[Formula])) end private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/utils/shebang.rb b/Library/Homebrew/utils/shebang.rb index 3a5d784b1fa81..93df6425b1e66 100644 --- a/Library/Homebrew/utils/shebang.rb +++ b/Library/Homebrew/utils/shebang.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module Utils @@ -8,13 +8,20 @@ module Shebang # Specification on how to rewrite a given shebang. class RewriteInfo - attr_reader :regex, :max_length, :replacement + sig { returns(Regexp) } + attr_reader :regex + + sig { returns(Integer) } + attr_reader :max_length + + sig { returns(T.any(String, Pathname)) } + attr_reader :replacement sig { params(regex: Regexp, max_length: Integer, replacement: T.any(String, Pathname)).void } def initialize(regex, max_length, replacement) - @regex = regex - @max_length = max_length - @replacement = replacement + @regex = T.let(regex, Regexp) + @max_length = T.let(max_length, Integer) + @replacement = T.let(replacement, T.any(String, Pathname)) end end