From d76fcd0edd60d4d770784be302c2f416ea30d221 Mon Sep 17 00:00:00 2001 From: botantony Date: Wed, 27 Aug 2025 19:33:42 +0200 Subject: [PATCH 1/2] keg_only_reason: `typed: strict` Signed-off-by: botantony --- Library/Homebrew/keg_only_reason.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/keg_only_reason.rb b/Library/Homebrew/keg_only_reason.rb index f254b2a07a..3b85610c76 100644 --- a/Library/Homebrew/keg_only_reason.rb +++ b/Library/Homebrew/keg_only_reason.rb @@ -1,28 +1,34 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true # Used to annotate formulae that duplicate macOS-provided software # or cause conflicts when linked in. class KegOnlyReason + sig { returns(T.any(Symbol, String)) } attr_reader :reason + sig { params(reason: T.any(Symbol, String), explanation: String).void } def initialize(reason, explanation) @reason = reason @explanation = explanation end + sig { returns(T::Boolean) } def versioned_formula? @reason == :versioned_formula end + sig { returns(T::Boolean) } def provided_by_macos? @reason == :provided_by_macos end + sig { returns(T::Boolean) } def shadowed_by_macos? @reason == :shadowed_by_macos end + sig { returns(T::Boolean) } def by_macos? provided_by_macos? || shadowed_by_macos? end @@ -53,10 +59,11 @@ class KegOnlyReason parallel can cause all kinds of trouble EOS else - @reason + @reason.to_s end.strip end + sig { returns(T::Hash[String, String]) } def to_hash reason_string = if @reason.is_a?(Symbol) @reason.inspect From 6458a5ba43b005b2fc1dc55e975db9c9d3313d97 Mon Sep 17 00:00:00 2001 From: botantony Date: Wed, 27 Aug 2025 19:33:50 +0200 Subject: [PATCH 2/2] locale: `typed: strict` Signed-off-by: botantony --- Library/Homebrew/locale.rb | 50 +++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index 040647f218..2efaa1c56f 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true # Representation of a system locale. @@ -24,6 +24,7 @@ class Locale LOCALE_REGEX = /\A((?:#{LANGUAGE_REGEX}|#{REGION_REGEX}|#{SCRIPT_REGEX})(?:-|$)){1,3}\Z/ private_constant :LOCALE_REGEX + sig { params(string: String).returns(T.attached_class) } def self.parse(string) if (locale = try_parse(string)) return locale @@ -55,25 +56,42 @@ class Locale new(language, script, region) end - attr_reader :language, :script, :region + sig { returns(T.nilable(String)) } + attr_reader :language + sig { returns(T.nilable(String)) } + attr_reader :script + + sig { returns(T.nilable(String)) } + attr_reader :region + + sig { params(language: T.nilable(String), script: T.nilable(String), region: T.nilable(String)).void } def initialize(language, script, region) raise ArgumentError, "#{self.class} cannot be empty" if language.nil? && region.nil? && script.nil? - { - language:, - script:, - region:, - }.each do |key, value| - next if value.nil? + unless language.nil? + regex = LANGUAGE_REGEX + raise ParserError, "'language' does not match #{regex}" unless language.match?(regex) - regex = self.class.const_get(:"#{key.upcase}_REGEX") - raise ParserError, "'#{value}' does not match #{regex}" unless value&.match?(regex) - - instance_variable_set(:"@#{key}", value) + @language = T.let(language, T.nilable(String)) end + + unless script.nil? + regex = SCRIPT_REGEX + raise ParserError, "'script' does not match #{regex}" unless script.match?(regex) + + @script = T.let(script, T.nilable(String)) + end + + return if region.nil? + + regex = REGION_REGEX + raise ParserError, "'region' does not match #{regex}" unless region.match?(regex) + + @region = T.let(region, T.nilable(String)) end + sig { params(other: T.any(String, Locale)).returns(T::Boolean) } def include?(other) unless other.is_a?(self.class) other = self.class.try_parse(other) @@ -87,6 +105,7 @@ class Locale end end + sig { params(other: T.any(String, Locale)).returns(T::Boolean) } def eql?(other) unless other.is_a?(self.class) other = self.class.try_parse(other) @@ -99,6 +118,13 @@ class Locale end alias == eql? + sig { + params( + locale_groups: T::Enumerable[T::Enumerable[T.any(String, Locale)]], + ).returns( + T.nilable(T::Enumerable[T.any(String, Locale)]), + ) + } def detect(locale_groups) locale_groups.find { |locales| locales.any? { |locale| eql?(locale) } } || locale_groups.find { |locales| locales.any? { |locale| include?(locale) } }