Skip to content

Commit

Permalink
Merge pull request #18894 from Homebrew/unsafe-cleanup
Browse files Browse the repository at this point in the history
Remove unsafe references from CLI and Formulary code
  • Loading branch information
dduugg authored Dec 6, 2024
2 parents ba9581f + e2d1033 commit c1f664d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 146 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/cli/args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def named
end

sig { returns(T::Boolean) }
def no_named? = named.blank?
def no_named? = named.empty?

sig { returns(T::Array[String]) }
def build_from_source_formulae
Expand Down
20 changes: 8 additions & 12 deletions Library/Homebrew/cli/named_args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NamedArgs < Array
params(
args: String,
parent: Args,
override_spec: Symbol,
override_spec: T.nilable(Symbol),
force_bottle: T::Boolean,
flags: T::Array[String],
cask_options: T::Boolean,
Expand All @@ -28,9 +28,9 @@ class NamedArgs < Array
def initialize(
*args,
parent: Args.new,
override_spec: T.unsafe(nil),
force_bottle: T.unsafe(nil),
flags: T.unsafe(nil),
override_spec: nil,
force_bottle: false,
flags: [],
cask_options: false,
without_api: false
)
Expand Down Expand Up @@ -73,11 +73,7 @@ def to_formulae
).returns(T::Array[T.any(Formula, Keg, Cask::Cask)])
}
def to_formulae_and_casks(
only: parent.only_formula_or_cask,
ignore_unavailable: false,
method: T.unsafe(nil),
uniq: true,
warn: T.unsafe(nil)
only: parent.only_formula_or_cask, ignore_unavailable: false, method: nil, uniq: true, warn: false
)
@to_formulae_and_casks ||= T.let(
{}, T.nilable(T::Hash[T.nilable(Symbol), T::Array[T.any(Formula, Keg, Cask::Cask)]])
Expand Down Expand Up @@ -127,7 +123,7 @@ def to_formulae_and_casks_with_taps
T.cast(formula_or_cask, T.any(Formula, Cask::Cask)).tap&.installed?
end

return formulae_and_casks_with_taps if formulae_and_casks_without_taps.blank?
return formulae_and_casks_with_taps if formulae_and_casks_without_taps.empty?

types = []
types << "formulae" if formulae_and_casks_without_taps.any?(Formula)
Expand Down Expand Up @@ -369,7 +365,7 @@ def load_formula_or_cask(name, only: nil, method: nil, warn: nil)
options = { warn: }.compact
candidate_cask = Cask::CaskLoader.load(name, config:, **options)

if unreadable_error.present?
if unreadable_error
onoe <<~EOS
Failed to load formula: #{name}
#{unreadable_error}
Expand Down Expand Up @@ -435,7 +431,7 @@ def load_formula_or_cask(name, only: nil, method: nil, warn: nil)
end
end

raise unreadable_error if unreadable_error.present?
raise unreadable_error if unreadable_error

user, repo, short_name = name.downcase.split("/", 3)
if repo.present? && short_name.present?
Expand Down
10 changes: 4 additions & 6 deletions Library/Homebrew/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,9 @@ def formula_options
).void
}
def named_args(type = nil, number: nil, min: nil, max: nil, without_api: false)
if number.present? && (min.present? || max.present?)
raise ArgumentError, "Do not specify both `number` and `min` or `max`"
end
raise ArgumentError, "Do not specify both `number` and `min` or `max`" if number && (min || max)

if type == :none && (number.present? || min.present? || max.present?)
if type == :none && (number || min || max)
raise ArgumentError, "Do not specify both `number`, `min` or `max` with `named_args :none`"
end

Expand Down Expand Up @@ -527,9 +525,9 @@ def generate_usage_banner
"<#{@named_args_type}>"
end

named_args = if @min_named_args.blank? && @max_named_args == 1
named_args = if @min_named_args.nil? && @max_named_args == 1
" [#{arg_type}]"
elsif @min_named_args.blank?
elsif @min_named_args.nil?
" [#{arg_type} ...]"
elsif @min_named_args == 1 && @max_named_args == 1
" #{arg_type}"
Expand Down
Loading

0 comments on commit c1f664d

Please sign in to comment.