Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable strict typing in NamedArgs #18867

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
411 changes: 232 additions & 179 deletions Library/Homebrew/cli/named_args.rb

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ def print_info
info_formula(obj)
when Cask::Cask
info_cask(obj)
when FormulaUnreadableError, FormulaClassUnavailableError,
TapFormulaUnreadableError, TapFormulaClassUnavailableError,
Cask::CaskUnreadableError
dduugg marked this conversation as resolved.
Show resolved Hide resolved
# We found the formula/cask, but failed to read it
$stderr.puts obj.backtrace if Homebrew::EnvConfig.developer?
ofail obj.message
when FormulaOrCaskUnavailableError
# The formula/cask could not be found
ofail obj.message
Expand Down
5 changes: 1 addition & 4 deletions Library/Homebrew/cmd/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ class Reinstall < AbstractCommand

sig { override.void }
def run
formulae, casks = T.cast(
args.named.to_resolved_formulae_to_casks,
[T::Array[Formula], T::Array[Cask::Cask]],
)
formulae, casks = args.named.to_resolved_formulae_to_casks

if args.build_from_source?
unless DevelopmentTools.installed?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run
end
raise UsageError, "No marking option specified." if installed_on_request.nil?

formulae, casks = args.named.to_formulae_to_casks
formulae, casks = T.cast(args.named.to_formulae_to_casks, [T::Array[Formula], T::Array[Cask::Cask]])
formulae_not_installed = formulae.reject(&:any_version_installed?)
casks_not_installed = casks.reject(&:installed?)
if formulae_not_installed.any? || casks_not_installed.any?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def run
elsif args.no_named?
puts Tap.installed.sort_by(&:name)
else
tap = Tap.fetch(args.named.first)
tap = Tap.fetch(args.named.fetch(0))
begin
tap.install clone_target: args.named.second,
custom_remote: args.custom_remote?,
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/bump-cask-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
# Use the user's browser, too.
ENV["BROWSER"] = EnvConfig.browser

cask = args.named.to_casks.first
cask = args.named.to_casks.fetch(0)

Check warning on line 75 in Library/Homebrew/dev-cmd/bump-cask-pr.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bump-cask-pr.rb#L75

Added line #L75 was not covered by tests

odie "This cask is not in a tap!" if cask.tap.blank?
odie "This cask's tap is not a Git repository!" unless cask.tap.git?
Expand Down
19 changes: 10 additions & 9 deletions Library/Homebrew/dev-cmd/bump-formula-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,19 @@

odie "This formula is disabled!" if formula.disabled?
odie "This formula is deprecated and does not build!" if formula.deprecation_reason == :does_not_build
odie "This formula is not in a tap!" if formula.tap.blank?
odie "This formula's tap is not a Git repository!" unless formula.tap.git?
tap = formula.tap

Check warning on line 112 in Library/Homebrew/dev-cmd/bump-formula-pr.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bump-formula-pr.rb#L112

Added line #L112 was not covered by tests
odie "This formula is not in a tap!" if tap.blank?
odie "This formula's tap is not a Git repository!" unless tap.git?

odie <<~EOS unless formula.tap.allow_bump?(formula.name)
odie <<~EOS unless tap.allow_bump?(formula.name)
Whoops, the #{formula.name} formula has its version update
pull requests automatically opened by BrewTestBot every ~3 hours!
We'd still love your contributions, though, so try another one
that's not in the autobump list:
#{Formatter.url("#{formula.tap.remote}/blob/master/.github/autobump.txt")}
#{Formatter.url("#{tap.remote}/blob/master/.github/autobump.txt")}
EOS

odie "You have too many PRs open: close or merge some first!" if GitHub.too_many_open_prs?(formula.tap)
odie "You have too many PRs open: close or merge some first!" if GitHub.too_many_open_prs?(tap)

formula_spec = formula.stable
odie "#{formula}: no stable specification found!" if formula_spec.blank?
Expand All @@ -129,9 +130,9 @@
# spamming during normal output.
Homebrew.install_bundler_gems!(groups: ["audit", "style"]) unless args.no_audit?

tap_remote_repo = formula.tap.remote_repository
tap_remote_repo = T.must(tap.remote_repository)

Check warning on line 133 in Library/Homebrew/dev-cmd/bump-formula-pr.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bump-formula-pr.rb#L133

Added line #L133 was not covered by tests
remote = "origin"
remote_branch = formula.tap.git_repository.origin_branch_name
remote_branch = tap.git_repository.origin_branch_name

Check warning on line 135 in Library/Homebrew/dev-cmd/bump-formula-pr.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bump-formula-pr.rb#L135

Added line #L135 was not covered by tests
previous_branch = "-"

check_pull_requests(formula, tap_remote_repo, state: "open")
Expand Down Expand Up @@ -333,7 +334,7 @@
alias_rename = alias_update_pair(formula, new_formula_version)
if alias_rename.present?
ohai "Renaming alias #{alias_rename.first} to #{alias_rename.last}"
alias_rename.map! { |a| formula.tap.alias_dir/a }
alias_rename.map! { |a| tap.alias_dir/a }

Check warning on line 337 in Library/Homebrew/dev-cmd/bump-formula-pr.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bump-formula-pr.rb#L337

Added line #L337 was not covered by tests
end

unless args.dry_run?
Expand Down Expand Up @@ -389,7 +390,7 @@
branch_name: "bump-#{formula.name}-#{new_formula_version}",
commit_message: "#{formula.name} #{new_formula_version}",
previous_branch:,
tap: formula.tap,
tap: tap,
tap_remote_repo:,
pr_message:,
}
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

sig { returns(Pathname) }
def create_cask
url = args.named.first
url = args.named.fetch(0)

Check warning on line 84 in Library/Homebrew/dev-cmd/create.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/create.rb#L84

Added line #L84 was not covered by tests
name = if args.set_name.blank?
stem = Pathname.new(url).stem.rpartition("=").last
print "Cask name [#{stem}]: "
Expand Down Expand Up @@ -179,7 +179,7 @@
args.set_name,
args.set_version,
tap: args.tap,
url: args.named.first,
url: args.named.fetch(0),
mode:,
license: args.set_license,
fetch: !args.no_fetch?,
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/dev-cmd/determine-test-runners.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def run
raise UsageError, "`--all-supported` is mutually exclusive to other arguments."
end

testing_formulae = args.named.first&.split(",").to_a
testing_formulae.map! { |name| TestRunnerFormula.new(Formulary.factory(name), eval_all: args.eval_all?) }
.freeze
testing_formulae = args.named.first&.split(",").to_a.map do |name|
TestRunnerFormula.new(Formulary.factory(name), eval_all: args.eval_all?)
end.freeze
dduugg marked this conversation as resolved.
Show resolved Hide resolved
deleted_formulae = args.named.second&.split(",").to_a.freeze
runner_matrix = GitHubRunnerMatrix.new(testing_formulae, deleted_formulae,
all_supported: args.all_supported?,
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def run
if (tap_with_name = args.named.first&.then { Tap.with_formula_name(_1) })
source_tap, name = tap_with_name
else
name = args.named.first.downcase
name = args.named.fetch(0).downcase
source_tap = CoreTap.instance
end
raise TapFormulaUnavailableError.new(source_tap, name) unless source_tap.installed?

destination_tap = Tap.fetch(args.named.second)
destination_tap = Tap.fetch(args.named.fetch(1))
unless Homebrew::EnvConfig.developer?
odie "Cannot extract formula to homebrew/core!" if destination_tap.core_tap?
odie "Cannot extract formula to homebrew/cask!" if destination_tap.core_cask_tap?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/pr-pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def run
arg = "#{tap.default_remote}/pull/#{arg}" if arg.to_i.positive?
url_match = arg.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX
_, user, repo, pr = *url_match
odie "Not a GitHub pull request: #{arg}" unless pr
odie "Not a GitHub pull request: #{arg}" if !user || !repo || !pr

git_repo = tap.git_repository
if !git_repo.default_origin_branch? && !args.branch_okay? && !args.no_commit? && !args.no_cherry_pick?
Expand Down
Loading