From bca4fa34728dece277c24c99143e4efcc6fa6550 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 11 Oct 2022 00:29:28 +0100 Subject: [PATCH 1/5] dev-cmd/typecheck: Use Tapioca more as `srb rbi` is in maintenance - According to https://sorbet.org/blog/2022/07/27/srb-tapioca, Tapioca is the recommended way to generate RBIs for Sorbet these days and `srb rbi` is in maintenance mode. - There's a handy migration document - https://github.com/Shopify/tapioca/wiki/Migrating-to-Tapioca - and we're some of the way there already given we currently use Tapioca in some places. --- Library/Homebrew/dev-cmd/typecheck.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb index f8fa8101c3..3fc3a290ad 100644 --- a/Library/Homebrew/dev-cmd/typecheck.rb +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -67,8 +67,7 @@ module Homebrew ohai "Updating Tapioca RBI files..." safe_system "bundle", "exec", "tapioca", "gem", *tapioca_args safe_system "bundle", "exec", "parlour" - safe_system "bundle", "exec", "srb", "rbi", "hidden-definitions" - safe_system "bundle", "exec", "srb", "rbi", "todo" + safe_system "bundle", "exec", "tapioca", "todo" if args.suggest_typed? result = system_command( From 84e83dd1ad1a30ddbd3c0e1dea9ca78f33c8e296 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 11 Oct 2022 00:56:00 +0100 Subject: [PATCH 2/5] sorbet/rbi/todo: Update the comment now it's generated with Tapioca - Again, this was automatic with `brew typecheck --update`. --- Library/Homebrew/sorbet/rbi/todo.rbi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/sorbet/rbi/todo.rbi b/Library/Homebrew/sorbet/rbi/todo.rbi index 405a1f33e4..866476b0d6 100644 --- a/Library/Homebrew/sorbet/rbi/todo.rbi +++ b/Library/Homebrew/sorbet/rbi/todo.rbi @@ -1,7 +1,9 @@ -# This file is autogenerated. Do not edit it by hand. Regenerate it with: -# srb rbi todo +# DO NOT EDIT MANUALLY +# This is an autogenerated file for unresolved constants. +# Please instead update this file by running `bin/tapioca todo`. + +# typed: false -# typed: strong module ::StackProf; end module T::InterfaceWrapper::Helpers; end module T::Private::Abstract::Hooks; end From 295d60b3a25cdf230f0c71f12be81f373ecb1662 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 11 Oct 2022 00:38:07 +0100 Subject: [PATCH 3/5] Gemfile*,dev-cmd/typecheck: Use Spoom for `--suggest-typed` - Spoom is the gem that's recommended for automatically changing `typed` sigils in files now. It was recommended in the "migrate to Tapioca" guide at https://github.com/Shopify/tapioca/wiki/Migrating-to-Tapioca#things-that-do-not-need-to-happen. --- Library/Homebrew/Gemfile | 1 + Library/Homebrew/Gemfile.lock | 1 + Library/Homebrew/dev-cmd/typecheck.rb | 31 ++------------------------- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/Library/Homebrew/Gemfile b/Library/Homebrew/Gemfile index 4b844fe8f5..917b7b6309 100644 --- a/Library/Homebrew/Gemfile +++ b/Library/Homebrew/Gemfile @@ -34,6 +34,7 @@ gem "warning", require: false group :sorbet, optional: true do gem "parlour", require: false gem "sorbet-static-and-runtime", require: false + gem "spoom", require: false gem "tapioca", require: false end diff --git a/Library/Homebrew/Gemfile.lock b/Library/Homebrew/Gemfile.lock index abb5a04223..023ede5ef4 100644 --- a/Library/Homebrew/Gemfile.lock +++ b/Library/Homebrew/Gemfile.lock @@ -236,6 +236,7 @@ DEPENDENCIES simplecov-cobertura sorbet-runtime sorbet-static-and-runtime + spoom tapioca warning diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb index 3fc3a290ad..1a56d766e9 100644 --- a/Library/Homebrew/dev-cmd/typecheck.rb +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -70,35 +70,8 @@ module Homebrew safe_system "bundle", "exec", "tapioca", "todo" if args.suggest_typed? - result = system_command( - "bundle", - args: ["exec", "--", "srb", "tc", "--suggest-typed", "--typed=strict", - "--isolate-error-code=7022"], - print_stderr: false, - ) - - allowed_changes = { - "false" => ["true", "strict"], - "true" => ["strict"], - } - - # Workaround for `srb tc rbi suggest-typed`, which currently fails get to a converging state. - result.stderr.scan(/^(.*\.rb):\d+:\s+You could add `#\s*typed:\s*(.*?)`/).each do |path, new_level| - path = Pathname(path) - - next unless path.file? - - contents = path.read - - next unless (match = contents.match(/\A\s*#\s*typed:\s*([^\s]+)/)) - - existing_level = match[1] - - next unless allowed_changes.fetch(existing_level, []).include?(new_level) - - puts "#{path}: #{existing_level} -> #{new_level}" - path.atomic_write contents.sub(/\A(\s*#\s*typed:\s*)(?:[^\s]+)/, "\\1#{new_level}") - end + ohai "Bumping Sorbet `typed` sigils..." + safe_system "bundle", "exec", "spoom", "bump" end return From b7d997e80d2fa0037528ab652ea2217353419090 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 11 Oct 2022 00:52:32 +0100 Subject: [PATCH 4/5] sorbet: Bump some files from `typed: false` to `typed: true` - This was done with `brew typecheck --update --suggest-typed` which (as of the previous commit) uses Spoom, yet another gem. I thought I'd see how well it works. There are no Sorbet errors after these changes! --- Library/Homebrew/cask/artifact/mdimporter.rb | 2 +- Library/Homebrew/cask/artifact/moved.rb | 2 +- Library/Homebrew/cask/artifact/pkg.rb | 2 +- Library/Homebrew/cask/artifact/qlplugin.rb | 2 +- Library/Homebrew/cask/artifact/symlinked.rb | 2 +- Library/Homebrew/caveats.rb | 2 +- Library/Homebrew/dev-cmd/generate-man-completions.rb | 2 +- Library/Homebrew/dev-cmd/update-maintainers.rb | 2 +- Library/Homebrew/extend/os/args.rb | 2 +- Library/Homebrew/extend/os/linux/args.rb | 2 +- Library/Homebrew/extend/os/linux/parser.rb | 2 +- Library/Homebrew/extend/os/parser.rb | 2 +- Library/Homebrew/linuxbrew-core-migration.rb | 2 +- Library/Homebrew/livecheck/strategy/git.rb | 2 +- Library/Homebrew/rubocops/cask/variables.rb | 2 +- Library/Homebrew/unpack_strategy/uncompressed.rb | 2 +- Library/Homebrew/utils/fork.rb | 2 +- Library/Homebrew/utils/rubocop.rb | 2 +- Library/Homebrew/yard/ignore_directives.rb | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/cask/artifact/mdimporter.rb b/Library/Homebrew/cask/artifact/mdimporter.rb index 5a4ce2d052..d85cf27438 100644 --- a/Library/Homebrew/cask/artifact/mdimporter.rb +++ b/Library/Homebrew/cask/artifact/mdimporter.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "cask/artifact/moved" diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index 6ad4cf61cc..58ae0e9d95 100644 --- a/Library/Homebrew/cask/artifact/moved.rb +++ b/Library/Homebrew/cask/artifact/moved.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "cask/artifact/relocated" diff --git a/Library/Homebrew/cask/artifact/pkg.rb b/Library/Homebrew/cask/artifact/pkg.rb index 9c3ef09a13..924f731ae4 100644 --- a/Library/Homebrew/cask/artifact/pkg.rb +++ b/Library/Homebrew/cask/artifact/pkg.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "plist" diff --git a/Library/Homebrew/cask/artifact/qlplugin.rb b/Library/Homebrew/cask/artifact/qlplugin.rb index d50956d8ca..e5766f4ee3 100644 --- a/Library/Homebrew/cask/artifact/qlplugin.rb +++ b/Library/Homebrew/cask/artifact/qlplugin.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "cask/artifact/moved" diff --git a/Library/Homebrew/cask/artifact/symlinked.rb b/Library/Homebrew/cask/artifact/symlinked.rb index 653caeed91..a5d8d0ab9b 100644 --- a/Library/Homebrew/cask/artifact/symlinked.rb +++ b/Library/Homebrew/cask/artifact/symlinked.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "cask/artifact/relocated" diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 66b4fcf1a7..997c10b6e7 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "language/python" diff --git a/Library/Homebrew/dev-cmd/generate-man-completions.rb b/Library/Homebrew/dev-cmd/generate-man-completions.rb index 91d9dabc61..dfdd8dbebe 100644 --- a/Library/Homebrew/dev-cmd/generate-man-completions.rb +++ b/Library/Homebrew/dev-cmd/generate-man-completions.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "formula" diff --git a/Library/Homebrew/dev-cmd/update-maintainers.rb b/Library/Homebrew/dev-cmd/update-maintainers.rb index 2b66682777..42091f4a96 100644 --- a/Library/Homebrew/dev-cmd/update-maintainers.rb +++ b/Library/Homebrew/dev-cmd/update-maintainers.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "cli/parser" diff --git a/Library/Homebrew/extend/os/args.rb b/Library/Homebrew/extend/os/args.rb index e497060e41..2614878f98 100644 --- a/Library/Homebrew/extend/os/args.rb +++ b/Library/Homebrew/extend/os/args.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "extend/os/linux/args" if OS.linux? diff --git a/Library/Homebrew/extend/os/linux/args.rb b/Library/Homebrew/extend/os/linux/args.rb index 1d4b221909..cb1835d849 100644 --- a/Library/Homebrew/extend/os/linux/args.rb +++ b/Library/Homebrew/extend/os/linux/args.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true module Homebrew diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb index 939585859d..c056ad8fa0 100644 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ b/Library/Homebrew/extend/os/linux/parser.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true module Homebrew diff --git a/Library/Homebrew/extend/os/parser.rb b/Library/Homebrew/extend/os/parser.rb index 90b0d42da7..97225de0c8 100644 --- a/Library/Homebrew/extend/os/parser.rb +++ b/Library/Homebrew/extend/os/parser.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "extend/os/linux/parser" if OS.linux? diff --git a/Library/Homebrew/linuxbrew-core-migration.rb b/Library/Homebrew/linuxbrew-core-migration.rb index 22f879a915..73ec9eb24f 100644 --- a/Library/Homebrew/linuxbrew-core-migration.rb +++ b/Library/Homebrew/linuxbrew-core-migration.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true # List of formulae that had a revision in linuxbrew-core diff --git a/Library/Homebrew/livecheck/strategy/git.rb b/Library/Homebrew/livecheck/strategy/git.rb index 8dcd410d3a..8b0d6c2d5a 100644 --- a/Library/Homebrew/livecheck/strategy/git.rb +++ b/Library/Homebrew/livecheck/strategy/git.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "open3" diff --git a/Library/Homebrew/rubocops/cask/variables.rb b/Library/Homebrew/rubocops/cask/variables.rb index cf434e1b65..574e6f1dc3 100644 --- a/Library/Homebrew/rubocops/cask/variables.rb +++ b/Library/Homebrew/rubocops/cask/variables.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "forwardable" diff --git a/Library/Homebrew/unpack_strategy/uncompressed.rb b/Library/Homebrew/unpack_strategy/uncompressed.rb index 16ced6ca16..732cde1b4a 100644 --- a/Library/Homebrew/unpack_strategy/uncompressed.rb +++ b/Library/Homebrew/unpack_strategy/uncompressed.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true module UnpackStrategy diff --git a/Library/Homebrew/utils/fork.rb b/Library/Homebrew/utils/fork.rb index ac1ff1182a..4a6cfee9db 100644 --- a/Library/Homebrew/utils/fork.rb +++ b/Library/Homebrew/utils/fork.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "fcntl" diff --git a/Library/Homebrew/utils/rubocop.rb b/Library/Homebrew/utils/rubocop.rb index 35db8717bd..fe98ae580d 100755 --- a/Library/Homebrew/utils/rubocop.rb +++ b/Library/Homebrew/utils/rubocop.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# typed: false +# typed: true # frozen_string_literal: true require_relative "../standalone" diff --git a/Library/Homebrew/yard/ignore_directives.rb b/Library/Homebrew/yard/ignore_directives.rb index 4685ce026e..ecc616d037 100644 --- a/Library/Homebrew/yard/ignore_directives.rb +++ b/Library/Homebrew/yard/ignore_directives.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true # from https://github.com/lsegal/yard/issues/484#issuecomment-442586899 From 250f1882c87268a5af94e98d11a0e3cc6b1cc99a Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 11 Oct 2022 09:58:44 +0100 Subject: [PATCH 5/5] dev-cmd/typecheck: Reinstate `srb rbi hidden-definitions` - Turns out we do need this. I lulled us into a false sense of security by not deleting `sorbet/rbi/hidden-defintions/hidden.rbi` previously. - If we do delete that file then Sorbet reveals >200 typechecking issues. - The docs on moving from `srb rbi` to `tapioca` say that we don't need `hidden-definitions` anymore, but clearly we do. The blog post goes into a lot of detail on why `rbi hidden-defintions` exists and the fact that there's not an analogous command in Tapioca: https://sorbet.org/blog/2022/07/27/srb-tapioca#whats-happening-with-srb-rbi-hidden-definitions - Eventually we should try out `tapioca dsl`, since that's said to be a "partial replacement" for `hidden-definitions`, and removing our reliance on deprecated commands can only be a good thing? --- Library/Homebrew/dev-cmd/typecheck.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb index 1a56d766e9..b68a18834e 100644 --- a/Library/Homebrew/dev-cmd/typecheck.rb +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -67,6 +67,7 @@ module Homebrew ohai "Updating Tapioca RBI files..." safe_system "bundle", "exec", "tapioca", "gem", *tapioca_args safe_system "bundle", "exec", "parlour" + safe_system "bundle", "exec", "srb", "rbi", "hidden-definitions" safe_system "bundle", "exec", "tapioca", "todo" if args.suggest_typed?