From 807093f276a437849c62a2430f4444641ecf9317 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Mon, 12 Aug 2024 18:11:21 +0100 Subject: [PATCH 1/3] dev-cmd/typecheck: Support typechecking in taps ```shell $ brew typecheck homebrew/bundle No sorbet/ directory found. Maybe you want to run 'srb init'? A type checker for Ruby Usage: srb Same as "srb t" srb (init | initialize) Initializes the `sorbet` directory srb rbi [options] Manage the `sorbet` directory srb (t | tc | typecheck) [options] Typechecks the code Options: -h, --help View help for this subcommand. --version Show version. For full help: https://sorbet.org Check https://docs.brew.sh/Typechecking for more information on how to resolve these errors. ``` --- Library/Homebrew/dev-cmd/typecheck.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb index fac268dd6f9bf..b75040638abc0 100644 --- a/Library/Homebrew/dev-cmd/typecheck.rb +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -39,19 +39,20 @@ class Typecheck < AbstractCommand conflicts "--lsp", "--update-all" conflicts "--lsp", "--fix" - named_args :none + named_args :tap end sig { override.void } def run update = args.update? || args.update_all? + directory = args.no_named? ? HOMEBREW_LIBRARY_PATH : args.named.to_paths(only: :tap).first groups = update ? Homebrew.valid_gem_groups : ["typecheck"] Homebrew.install_bundler_gems!(groups:) # Sorbet doesn't use bash privileged mode so we align EUID and UID here. Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid - HOMEBREW_LIBRARY_PATH.cd do + directory.cd do if update workers = args.debug? ? ["--workers=1"] : [] safe_system "bundle", "exec", "tapioca", "dsl", *workers From feedc5c84e18bafc9d3eab079fd983a9f4fb631c Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 13 Aug 2024 11:04:15 +0100 Subject: [PATCH 2/3] dev-cmd/typecheck: Use Sorbet's `--dir` to set the tap path - This means we don't have to copy config files around, and users get instant results rather than having to run `srb init`. --- Library/Homebrew/dev-cmd/typecheck.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb index b75040638abc0..86b1d15a036e3 100644 --- a/Library/Homebrew/dev-cmd/typecheck.rb +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -44,15 +44,18 @@ class Typecheck < AbstractCommand sig { override.void } def run + if (args.dir.present? || args.file.present?) && args.named.present? + raise UsageError, "Cannot use `--dir` or `--file` when specifying a tap." + end + update = args.update? || args.update_all? - directory = args.no_named? ? HOMEBREW_LIBRARY_PATH : args.named.to_paths(only: :tap).first groups = update ? Homebrew.valid_gem_groups : ["typecheck"] Homebrew.install_bundler_gems!(groups:) # Sorbet doesn't use bash privileged mode so we align EUID and UID here. Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid - directory.cd do + HOMEBREW_LIBRARY_PATH.cd do if update workers = args.debug? ? ["--workers=1"] : [] safe_system "bundle", "exec", "tapioca", "dsl", *workers @@ -96,10 +99,11 @@ def run end srb_exec += ["--ignore", args.ignore] if args.ignore.present? - if args.file.present? || args.dir.present? + if args.file.present? || args.dir.present? || (tap_dir = args.named.to_paths(only: :tap).first).present? cd("sorbet") do srb_exec += ["--file", "../#{args.file}"] if args.file srb_exec += ["--dir", "../#{args.dir}"] if args.dir + srb_exec += ["--dir", tap_dir.to_s] if tap_dir end end success = system(*srb_exec) From 4e37436c3a3c9f53897c54db766cf101d1fdb841 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sat, 17 Aug 2024 21:47:42 +0100 Subject: [PATCH 3/3] dev-cmd/typecheck: Disallow `--fix` when in taps too - This could autocorrect files in Homebrew/brew when we should be targetting the tap, because of the weird hierarchy thing (https://github.com/Homebrew/brew/pull/18027#issuecomment-2294896044). Co-authored-by: Bo Anderson --- Library/Homebrew/dev-cmd/typecheck.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb index 86b1d15a036e3..de22b26b1545c 100644 --- a/Library/Homebrew/dev-cmd/typecheck.rb +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -46,6 +46,8 @@ class Typecheck < AbstractCommand def run if (args.dir.present? || args.file.present?) && args.named.present? raise UsageError, "Cannot use `--dir` or `--file` when specifying a tap." + elsif args.fix? && args.named.present? + raise UsageError, "Cannot use `--fix` when specifying a tap." end update = args.update? || args.update_all?