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.
This commit is contained in:
Issy Long 2022-10-11 00:38:07 +01:00
parent 84e83dd1ad
commit 295d60b3a2
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
3 changed files with 4 additions and 29 deletions

View File

@ -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

View File

@ -236,6 +236,7 @@ DEPENDENCIES
simplecov-cobertura
sorbet-runtime
sorbet-static-and-runtime
spoom
tapioca
warning

View File

@ -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