From 002930884439d360ec11ca25c8b68deaf56c5262 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 26 Sep 2024 13:01:31 -0400 Subject: [PATCH 1/3] completions: `typed: strict` --- Library/Homebrew/completions.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/completions.rb b/Library/Homebrew/completions.rb index af795741cb465..6246c0dd02a5b 100644 --- a/Library/Homebrew/completions.rb +++ b/Library/Homebrew/completions.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "utils/link" @@ -16,8 +16,8 @@ module Completions keyword_init: true, ) - COMPLETIONS_DIR = (HOMEBREW_REPOSITORY/"completions").freeze - TEMPLATE_DIR = (HOMEBREW_LIBRARY_PATH/"completions").freeze + COMPLETIONS_DIR = T.let((HOMEBREW_REPOSITORY/"completions").freeze, Pathname) + TEMPLATE_DIR = T.let((HOMEBREW_LIBRARY_PATH/"completions").freeze, Pathname) SHELLS = %w[bash fish zsh].freeze COMPLETIONS_EXCLUSION_LIST = %w[ @@ -26,7 +26,7 @@ module Completions update-report ].freeze - BASH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = { + BASH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = T.let({ formula: "__brew_complete_formulae", installed_formula: "__brew_complete_installed_formulae", outdated_formula: "__brew_complete_outdated_formulae", @@ -38,9 +38,9 @@ module Completions command: "__brew_complete_commands", diagnostic_check: '__brewcomp "${__HOMEBREW_DOCTOR_CHECKS=$(brew doctor --list-checks)}"', file: "__brew_complete_files", - }.freeze + }.freeze, T::Hash[Symbol, String]) - ZSH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = { + ZSH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = T.let({ formula: "__brew_formulae", installed_formula: "__brew_installed_formulae", outdated_formula: "__brew_outdated_formulae", @@ -52,9 +52,9 @@ module Completions command: "__brew_commands", diagnostic_check: "__brew_diagnostic_checks", file: "__brew_formulae_or_ruby_files", - }.freeze + }.freeze, T::Hash[Symbol, String]) - FISH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = { + FISH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = T.let({ formula: "__fish_brew_suggest_formulae_all", installed_formula: "__fish_brew_suggest_formulae_installed", outdated_formula: "__fish_brew_suggest_formulae_outdated", @@ -65,7 +65,7 @@ module Completions installed_tap: "__fish_brew_suggest_taps_installed", command: "__fish_brew_suggest_commands", diagnostic_check: "__fish_brew_suggest_diagnostic_checks", - }.freeze + }.freeze, T::Hash[Symbol, String]) sig { void } def self.link! @@ -264,6 +264,7 @@ def self.generate_zsh_subcommand_completion(command) COMPLETION end + sig { params(command: String, option: String).returns(String) } def self.generate_zsh_option_exclusions(command, option) conflicts = Commands.option_conflicts(command, option.gsub(/^--/, "")) return "" unless conflicts.presence From cce425dda10dc824054cb887e4ec274c381eec10 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 26 Sep 2024 13:30:37 -0400 Subject: [PATCH 2/3] cxxstdlib: `typed: strong` --- Library/Homebrew/cxxstdlib.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cxxstdlib.rb b/Library/Homebrew/cxxstdlib.rb index e863b226bbc9a..8b259144a875f 100644 --- a/Library/Homebrew/cxxstdlib.rb +++ b/Library/Homebrew/cxxstdlib.rb @@ -1,23 +1,30 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strong # frozen_string_literal: true require "compilers" # Combination of C++ standard library and compiler. class CxxStdlib + sig { params(type: T.nilable(Symbol), compiler: T.any(Symbol, String)).returns(CxxStdlib) } def self.create(type, compiler) raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && [:libstdcxx, :libcxx].exclude?(type) CxxStdlib.new(type, compiler) end - attr_reader :type, :compiler + sig { returns(T.nilable(Symbol)) } + attr_reader :type + sig { returns(Symbol) } + attr_reader :compiler + + sig { params(type: T.nilable(Symbol), compiler: T.any(Symbol, String)).void } def initialize(type, compiler) @type = type - @compiler = compiler.to_sym + @compiler = T.let(compiler.to_sym, Symbol) end + sig { returns(String) } def type_string type.to_s.gsub(/cxx$/, "c++") end From dca3e70f98b717ed3f8ad36ad1a395f0d9a1c86f Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 26 Sep 2024 14:48:32 -0400 Subject: [PATCH 3/3] formula_pin: `typed: strict` --- Library/Homebrew/formula_pin.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formula_pin.rb b/Library/Homebrew/formula_pin.rb index 3682bcb3e426f..141b30bad2540 100644 --- a/Library/Homebrew/formula_pin.rb +++ b/Library/Homebrew/formula_pin.rb @@ -1,24 +1,28 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "keg" # Helper functions for pinning a formula. class FormulaPin + sig { params(formula: Formula).void } def initialize(formula) @formula = formula end + sig { returns(Pathname) } def path HOMEBREW_PINNED_KEGS/@formula.name end + sig { params(version: PkgVersion).void } def pin_at(version) HOMEBREW_PINNED_KEGS.mkpath - version_path = @formula.rack/version + version_path = @formula.rack/version.to_s path.make_relative_symlink(version_path) if !pinned? && version_path.exist? end + sig { void } def pin latest_keg = @formula.installed_kegs.max_by(&:scheme_and_version) return if latest_keg.nil? @@ -26,19 +30,23 @@ def pin pin_at(latest_keg.version) end + sig { void } def unpin path.unlink if pinned? HOMEBREW_PINNED_KEGS.rmdir_if_possible end + sig { returns(T::Boolean) } def pinned? path.symlink? end + sig { returns(T::Boolean) } def pinnable? !@formula.installed_prefixes.empty? end + sig { returns(T.nilable(PkgVersion)) } def pinned_version Keg.new(path.resolved_path).version if pinned? end