diff --git a/Library/Homebrew/cmd/--prefix.rb b/Library/Homebrew/cmd/--prefix.rb index c01fa7dc17..2f1a87fe80 100644 --- a/Library/Homebrew/cmd/--prefix.rb +++ b/Library/Homebrew/cmd/--prefix.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -91,6 +91,7 @@ module Homebrew private + sig { void } def list_unbrewed dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s } dirs -= %w[Library Cellar Caskroom .git] diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 8ab830d8ca..dd3b5e71b0 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -33,11 +33,14 @@ module Homebrew def run Install.perform_preinstall_checks(all_fatal: true) Install.perform_build_from_source_checks(all_fatal: true) - gistify_logs(args.named.to_resolved_formulae.first) + return unless (formula = args.named.to_resolved_formulae.first) + + gistify_logs(formula) end private + sig { params(formula: Formula).void } def gistify_logs(formula) files = load_logs(formula.logs) build_time = formula.logs.ctime @@ -86,6 +89,7 @@ module Homebrew puts url if url end + sig { params(formula: Formula, with_hostname: T::Boolean).returns(String) } def brief_build_info(formula, with_hostname:) build_time_string = formula.logs.ctime.strftime("%Y-%m-%d %H:%M:%S") string = +<<~EOS @@ -100,6 +104,7 @@ module Homebrew end # Causes some terminals to display secure password entry indicators. + sig { void } def noecho_gets system "stty", "-echo" result = $stdin.gets @@ -108,6 +113,7 @@ module Homebrew result end + sig { params(dir: Pathname, basedir: Pathname).returns(T::Hash[String, T::Hash[Symbol, String]]) } def load_logs(dir, basedir = dir) logs = {} if dir.exist? diff --git a/Library/Homebrew/cmd/home.rb b/Library/Homebrew/cmd/home.rb index b10ccb406a..8def8448c5 100644 --- a/Library/Homebrew/cmd/home.rb +++ b/Library/Homebrew/cmd/home.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -41,6 +41,7 @@ module Homebrew private + sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(String) } def name_of(formula_or_cask) if formula_or_cask.is_a? Formula "Formula #{formula_or_cask.name}" diff --git a/Library/Homebrew/cmd/leaves.rb b/Library/Homebrew/cmd/leaves.rb index b8b0061505..8bf66f3f46 100644 --- a/Library/Homebrew/cmd/leaves.rb +++ b/Library/Homebrew/cmd/leaves.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -39,12 +39,14 @@ module Homebrew private + sig { params(formula: Formula).returns(T::Boolean) } def installed_on_request?(formula) - formula.any_installed_keg.tab.installed_on_request + formula.any_installed_keg&.tab&.installed_on_request end + sig { params(formula: Formula).returns(T::Boolean) } def installed_as_dependency?(formula) - formula.any_installed_keg.tab.installed_as_dependency + formula.any_installed_keg&.tab&.installed_as_dependency end end end diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index 9c43e48e96..c185106751 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -123,6 +123,7 @@ module Homebrew private + sig { params(keg: Keg).void } def puts_keg_only_path_message(keg) bin = keg/"bin" sbin = keg/"sbin" diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 7652cbe462..509b91a166 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -160,6 +160,7 @@ module Homebrew private + sig { void } def filtered_list names = if args.no_named? Formula.racks @@ -189,6 +190,7 @@ module Homebrew end end + sig { void } def list_casks casks = if args.no_named? Cask::Caskroom.casks @@ -212,6 +214,7 @@ module Homebrew end class PrettyListing + sig { params(path: T.any(String, Pathname, Keg)).void } def initialize(path) Pathname.new(path).children.sort_by { |p| p.to_s.downcase }.each do |pn| case pn.basename.to_s @@ -240,7 +243,8 @@ module Homebrew private - def print_dir(root) + sig { params(root: Pathname, block: T.nilable(T.proc.params(arg0: Pathname).returns(T::Boolean))).void } + def print_dir(root, &block) dirs = [] remaining_root_files = [] other = "" @@ -248,7 +252,7 @@ module Homebrew root.children.sort.each do |pn| if pn.directory? dirs << pn - elsif block_given? && yield(pn) + elsif block && yield(pn) puts pn other = "other " elsif pn.basename.to_s != ".DS_Store" @@ -265,6 +269,7 @@ module Homebrew print_remaining_files remaining_root_files, root, other end + sig { params(files: T::Array[Pathname], root: Pathname, other: String).void } def print_remaining_files(files, root, other = "") if files.length == 1 puts files diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index f316890145..ad62093461 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -54,6 +54,7 @@ module Homebrew private + sig { params(formulae: T::Array[Formula]).void } def puts_options(formulae) formulae.each do |f| next if f.options.empty? diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb index 710e282c4a..17232e8dd4 100644 --- a/Library/Homebrew/cmd/outdated.rb +++ b/Library/Homebrew/cmd/outdated.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -86,6 +86,7 @@ module Homebrew private + sig { params(formulae_or_casks: T::Array[T.any(Formula, Cask::Cask)]).void } def print_outdated(formulae_or_casks) formulae_or_casks.each do |formula_or_cask| if formula_or_cask.is_a?(Formula) @@ -124,6 +125,13 @@ module Homebrew end end + sig { + params( + formulae_or_casks: T::Array[T.any(Formula, Cask::Cask)], + ).returns( + T::Array[T.any(T::Hash[String, T.untyped], T::Hash[String, T.untyped])], + ) + } def json_info(formulae_or_casks) formulae_or_casks.map do |formula_or_cask| if formula_or_cask.is_a?(Formula) @@ -149,10 +157,12 @@ module Homebrew end end + sig { returns(T::Boolean) } def verbose? ($stdout.tty? || Context.current.verbose?) && !Context.current.quiet? end + sig { params(version: T.nilable(T.any(TrueClass, String))).returns(T.nilable(Symbol)) } def json_version(version) version_hash = { nil => nil, @@ -166,18 +176,26 @@ module Homebrew version_hash[version] end + sig { returns(T::Array[Formula]) } def outdated_formulae - select_outdated((args.named.to_resolved_formulae.presence || Formula.installed)).sort + T.cast( + select_outdated((args.named.to_resolved_formulae.presence || Formula.installed)).sort, + T::Array[Formula], + ) end + sig { returns(T::Array[Cask::Cask]) } def outdated_casks - if args.named.present? + outdated = if args.named.present? select_outdated(args.named.to_casks) else select_outdated(Cask::Caskroom.casks) end + + T.cast(outdated, T::Array[Cask::Cask]) end + sig { returns([T::Array[T.any(Formula, Cask::Cask)], T::Array[T.any(Formula, Cask::Cask)]]) } def outdated_formulae_casks formulae, casks = args.named.to_resolved_formulae_to_casks @@ -189,6 +207,9 @@ module Homebrew [select_outdated(formulae).sort, select_outdated(casks)] end + sig { + params(formulae_or_casks: T::Array[T.any(Formula, Cask::Cask)]).returns(T::Array[T.any(Formula, Cask::Cask)]) + } def select_outdated(formulae_or_casks) formulae_or_casks.select do |formula_or_cask| if formula_or_cask.is_a?(Formula) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 8c6d89a344..9d0e6cf6bd 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -10,7 +10,7 @@ require "search" module Homebrew module Cmd class SearchCmd < AbstractCommand - PACKAGE_MANAGERS = { + PACKAGE_MANAGERS = T.let({ repology: ->(query) { "https://repology.org/projects/?search=#{query}" }, macports: ->(query) { "https://ports.macports.org/search/?q=#{query}" }, fink: ->(query) { "https://pdb.finkproject.org/pdb/browse.php?summary=#{query}" }, @@ -23,7 +23,7 @@ module Homebrew ubuntu: lambda { |query| "https://packages.ubuntu.com/search?keywords=#{query}&searchon=names&suite=all§ion=all" }, - }.freeze + }.freeze, T::Hash[Symbol, T.proc.params(query: String).returns(String)]) cmd_args do description <<~EOS @@ -89,6 +89,7 @@ module Homebrew private + sig { void } def print_regex_help return unless $stdout.tty? @@ -105,6 +106,7 @@ module Homebrew EOS end + sig { returns(T::Boolean) } def search_package_manager package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] } return false if package_manager.nil? @@ -114,6 +116,7 @@ module Homebrew true end + sig { params(query: String).returns(String) } def search_pull_requests(query) only = if args.open? && !args.closed? "open" @@ -124,6 +127,7 @@ module Homebrew GitHub.print_pull_requests_matching(query, only) end + sig { params(all_formulae: T::Array[String], all_casks: T::Array[String], query: String).void } def print_results(all_formulae, all_casks, query) count = all_formulae.size + all_casks.size @@ -148,6 +152,7 @@ module Homebrew odie "No formulae or casks found for #{query.inspect}." if count.zero? end + sig { params(query: String, found_matches: T::Boolean).void } def print_missing_formula_help(query, found_matches) return unless $stdout.tty? diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index f430de8ce0..2d00a70cb8 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -42,6 +42,7 @@ module Homebrew private + sig { params(taps: T::Array[Tap]).void } def print_tap_info(taps) if taps.none? tap_count = 0 @@ -83,6 +84,7 @@ module Homebrew end end + sig { params(taps: T::Array[Tap]).void } def print_tap_json(taps) puts JSON.pretty_generate(taps.map(&:to_hash)) end diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index eea29f5e7e..3bcb86a2e6 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "abstract_command" @@ -87,6 +87,7 @@ module Homebrew private + sig { params(use_runtime_dependents: T::Boolean, used_formulae: T::Array[Formula]).returns(T::Array[Formula]) } def intersection_of_dependents(use_runtime_dependents, used_formulae) recursive = args.recursive? show_formulae_and_casks = !args.formula? && !args.cask? @@ -137,6 +138,14 @@ module Homebrew end end + sig { + params( + dependents: T::Array[Formula], used_formulae: T::Array[Formula], recursive: T::Boolean, + includes: T::Array[Symbol], ignores: T::Array[Symbol] + ).returns( + T::Array[Formula], + ) + } def select_used_dependents(dependents, used_formulae, recursive, includes, ignores) dependents.select do |d| deps = if recursive diff --git a/Library/Homebrew/extend/os/linux/cmd/update-report.rb b/Library/Homebrew/extend/os/linux/cmd/update-report.rb index 2d448f0ec1..25947f07c4 100644 --- a/Library/Homebrew/extend/os/linux/cmd/update-report.rb +++ b/Library/Homebrew/extend/os/linux/cmd/update-report.rb @@ -1,13 +1,15 @@ -# typed: true +# typed: strict # frozen_string_literal: true module Homebrew module_function + sig { returns(String) } def no_changes_message "No changes to formulae." end + sig { void } def migrate_gcc_dependents_if_needed return if Settings.read("gcc-rpaths.fixed") == "true"