Created
October 23, 2021 00:53
-
-
Save soberstadt/8dd89f6e93be29baf46d3973ca5342b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "borrowed" from https://connorshea.gitlab.io/blog/how-i-write-and-maintain-type-sigs-in-my-rails-app-with-sorbet.html | |
namespace :sorbet do | |
namespace :update do | |
desc "Update Sorbet and Sorbet Rails RBIs." | |
task all: :environment do | |
Bundler.with_unbundled_env do | |
# Pull in community-created RBIs for popular gems, such as Faker. | |
# | |
# If you want to use a fork of sorbet-typed for any reason, you can set | |
# SRB_SORBET_TYPED_REPO to the git URL and SRB_SORBET_TYPED_REVISION | |
# to the "origin/master"-type branch reference). | |
system('bundle exec srb rbi sorbet-typed') | |
# We don't want to include the RBI files for these gems since they're not useful. | |
puts 'Removing unwanted gem definitions from sorbet-typed...' | |
['rspec-core', 'rake', 'rubocop'].each do |gem| | |
FileUtils.remove_dir(Rails.root.join("sorbet/rbi/sorbet-typed/lib/#{gem}")) | |
end | |
# Use Tapioca to generate RBIs for gems | |
system('bundle exec tapioca sync') | |
# Generate Sorbet Rails RBIs. | |
system('bundle exec rake rails_rbi:all') | |
# Generate a TODO RBI for constants Tapioca doesn't understand. | |
system('bundle exec tapioca todo') | |
# Run suggest-typed to increase/decrease the type level of files | |
# as-necessary (for example, if types became more strict in an | |
# autogenerated RBI this may cause Sorbet to downgrade the `typed:` | |
# sigil for one of your files to `false`). Ensures that our code will | |
# pass type checking regardless of any changes to the autogenerated | |
# RBIs. | |
system('bundle exec srb rbi suggest-typed') | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment