diff --git a/Library/Homebrew/utils/autoremove.rb b/Library/Homebrew/utils/autoremove.rb index cb34473286..3a53c5d745 100644 --- a/Library/Homebrew/utils/autoremove.rb +++ b/Library/Homebrew/utils/autoremove.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true module Utils @@ -25,7 +25,7 @@ module Utils def formulae_with_no_formula_dependents(formulae) return [] if formulae.blank? - dependents = [] + dependents = T.let([], T::Array[Formula]) formulae.each do |formula| dependents += formula.runtime_formula_dependencies @@ -33,7 +33,7 @@ module Utils next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle formula.deps.select(&:build?).each do |dep| - suppress(FormulaUnavailableError) { dependents << dep.to_formula } + Kernel.suppress(FormulaUnavailableError) { dependents << dep.to_formula } end end formulae - dependents diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 80cf0517dc..049f889e96 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "open3" @@ -243,8 +243,8 @@ module Utils return unless url.start_with? "http" secure_url = url.sub(/\Ahttp:/, "https:") - secure_details = nil - hash_needed = false + secure_details = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped])) + hash_needed = T.let(false, T::Boolean) if url != secure_url user_agents.each do |user_agent| secure_details = begin @@ -267,7 +267,7 @@ module Utils end end - details = nil + details = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped])) user_agents.each do |user_agent| details = curl_http_content_headers_and_checksum( @@ -414,7 +414,7 @@ module Utils # Unknown charset in Content-Type header end end - file_contents = File.read(file.path, **open_args) + file_contents = File.read(T.must(file.path), **open_args) file_hash = Digest::SHA2.hexdigest(file_contents) if hash_needed end @@ -430,7 +430,7 @@ module Utils responses: responses, } ensure - file.unlink + T.must(file).unlink end def curl_supports_tls13? @@ -547,7 +547,7 @@ module Utils return response unless response_text.match?(HTTP_STATUS_LINE_REGEX) # Parse the status line and remove it - match = response_text.match(HTTP_STATUS_LINE_REGEX) + match = T.must(response_text.match(HTTP_STATUS_LINE_REGEX)) response[:status_code] = match["code"] if match["code"].present? response[:status_text] = match["text"] if match["text"].present? response_text = response_text.sub(%r{^HTTP/.* (\d+).*$\s*}, "") diff --git a/Library/Homebrew/utils/curl.rbi b/Library/Homebrew/utils/curl.rbi new file mode 100644 index 0000000000..e69d89d750 --- /dev/null +++ b/Library/Homebrew/utils/curl.rbi @@ -0,0 +1,6 @@ +# typed: strict + +module Utils::Curl + include Kernel + requires_ancestor { SystemCommand::Mixin } +end diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 3b7caae2b3..870364c142 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "utils/tty" @@ -91,11 +91,11 @@ module Formatter end fallback.call if objects.empty? - fallback.call if respond_to?(:tty?) ? !tty? : !$stdout.tty? + fallback.call if respond_to?(:tty?) ? !T.unsafe(self).tty? : !$stdout.tty? console_width = Tty.width object_lengths = objects.map { |obj| Tty.strip_ansi(obj).length } - cols = (console_width + gap_size) / (object_lengths.max + gap_size) + cols = (console_width + gap_size) / (T.must(object_lengths.max) + gap_size) fallback.call if cols < 2 @@ -109,14 +109,14 @@ module Formatter output = +"" rows.times do |row_index| - item_indices_for_row = row_index.step(objects.size - 1, rows).to_a + item_indices_for_row = T.cast(row_index.step(objects.size - 1, rows).to_a, T::Array[Integer]) - first_n = item_indices_for_row[0...-1].map do |index| - objects[index] + "".rjust(col_width - object_lengths[index]) + first_n = T.must(item_indices_for_row[0...-1]).map do |index| + objects[index] + "".rjust(col_width - object_lengths.fetch(index)) end # don't add trailing whitespace to last column - last = objects.values_at(item_indices_for_row.last) + last = objects.values_at(item_indices_for_row.fetch(-1)) output.concat((first_n + last) .join(gap_string)) diff --git a/Library/Homebrew/utils/formatter.rbi b/Library/Homebrew/utils/formatter.rbi new file mode 100644 index 0000000000..e9038dd0f3 --- /dev/null +++ b/Library/Homebrew/utils/formatter.rbi @@ -0,0 +1,5 @@ +# typed: strict + +module Formatter + include Kernel +end