:warning: Note: This software is currently under active development. The API and interface should be considered unstable until a v1.0.0 release.
Tapioca - The swiss army knife of RBI generation
Tapioca makes it easy to work with Sorbet in your codebase. It surfaces types and methods from many sources that Sorbet cannot otherwise see – such as gems, Rails and other DSLs – compiles them into RBI files and makes it easy for you to add gradual typing to your application.
Features:
- Easy installation and configuration
- Generation of RBI files for the gems used in your application
- Automatic generation from your application's Gemfile
- Importing of signatures from the source code of gems
- Importing of documentation from the source code of gems
- Synchronization validation for your CI
- Generation of RBI files for various DSL patterns that relies on meta-programming
- Automatic generation from your application's content
- Support many DSL patterns such as Rails, Google Protobuf, SmartProperties and more out of the box
- Extensible interface that allows you to write your own DSL compilers for other DSL patterns
- Automatic generation of signatures for methods from known DSLs
- Synchronization validation for your CI
- Management of shim RBI files
- Find useless definitions in shim RBI files from gems generated RBI files
- Find useless definitions in shim RBI files from DSL generated RBI files
- Find useless definitions in shim RBI files from Sorbet's embedded RBI for core and stdlib
- Synchronization validation for your CI
Table of Contents
Installation
Add this line to your application's Gemfile:
group :development, :test do
gem 'tapioca', require: false
end
Run bundle install and make sure Tapioca is properly installed:
$ tapioca help
Commands:
tapioca --version, -v # Show version
tapioca annotations # Pull gem RBI annotations from remote sources
tapioca check-shims # Check duplicated definitions in shim RBIs
tapioca configure # Initialize folder structure and type checking configuration
tapioca dsl [constant...] # Generate RBIs for dynamic methods
tapioca gem [gem...] # Generate RBIs from gems
tapioca help [COMMAND] # Describe available commands or one specific command
tapioca init # Get project ready for type checking
tapioca require # Generate the list of files to be required by tapioca
tapioca todo # Generate the list of unresolved constants
tapioca tree # Print a tree of all available commands
Options:
-c, [--config=<config file path>] # Path to the Tapioca configuration file
# Default: sorbet/tapioca/config.yml
-V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
# Default: false
Getting started
Execute this command to get started:
$ bundle exec tapioca init
This will:
- create the configuration file for Sorbet, the configuration file for Tapioca and the require.rb file
- install the binstub for Tapioca in your app's
bin/ folder, so that you can use bin/tapioca to run commands in your app
- pull the community RBI annotations from the central repository matching your app's gems
- generate the RBIs for your app's gems
- generate the RBI file for missing constants
See the following sections for more details about each step.
$ tapioca help init
Usage:
tapioca init
Options:
-c, [--config=<config file path>] # Path to the Tapioca configuration file
# Default: sorbet/tapioca/config.yml
-V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
# Default: false
Get project ready for type checking
Usage
Generating RBI files for gems
Sorbet does not read the code in your gem dependencies, so it does not know the constants and methods declared inside gems. Tapioca is able to load your gem dependencies from your application's Gemfile and compile RBI files to represent their content.
In order to generate the RBI files for the gems used in your application, run the following command:
$ bin/tapioca gems [gems...]
Removing RBI files of gems that have been removed:
Nothing to do.
Generating RBI files of gems that are added or updated:
Requiring all gems to prepare for compiling... Done
Compiled ansi
create sorbet/rbi/gems/ansi@1.5.0.rbi
...
All operations performed in working directory.
Please review changes and commit them.
This will load your application, find all the gems required by it and generate an RBI file for each gem under the sorbet/rbi/gems directory for each of those gems. This process will also import signatures that can be found inside each gem sources, and, optionally, any documentation inside the gem.
$ tapioca help gem
Usage:
tapioca gem [gem...]
Options:
--out, -o, [--outdir=directory] # The output directory for generated gem RBI files
# Default: sorbet/rbi/gems
[--file-header], [--no-file-header], [--skip-file-header] # Add a "This file is generated" header on top of each generated RBI file
# Default: true
[--all], [--no-all], [--skip-all] # Regenerate RBI files for all gems
# Default: false
--pre, -b, [--prerequire=file] # A file to be required before Bundler.require is called
--post, -a, [--postrequire=file] # A file to be required after Bundler.require is called
# Default: sorbet/tapioca/require.rb
-x, [--exclude=gem [gem ...]] # Exclude the given gem(s) from RBI generation
[--include-dependencies], [--no-include-dependencies], [--skip-include-dependencies] # Generate RBI files for dependencies of the given gem(s)
# Default: false
--typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Override for typed sigils for generated gem RBIs
# Default: {"activesupport" => "false"}
[--verify], [--no-verify], [--skip-verify] # Verify RBIs are up-to-date
# Default: false
[--doc], [--no-doc], [--skip-doc] # Include documentation from sources when generating RBIs
# Default: true
[--loc], [--no-loc], [--skip-loc] # Include comments with source location when generating RBIs
# Default: true
[--exported-gem-rbis], [--no-exported-gem-rbis], [--skip-exported-gem-rbis] # Include RBIs found in the `rbi/` directory of the gem
# Default: true
-w, [--workers=N] # Number of parallel workers to use when generating RBIs (default: auto)
[--auto-strictness], [--no-auto-strictness], [--skip-auto-strictness] # Autocorrect strictness in gem RBIs in case of conflict with the DSL RBIs
# Default: true
--dsl-dir, [--dsl-dir=directory] # The DSL directory used to correct gems strictnesses
# Default: sorbet/rbi/dsl
[--rbi-max-line-length=N] # Set the max line length of generated RBIs. Signatures longer than the max line length will be wrapped
# Default: 120
-e, [--environment=ENVIRONMENT] # The Rack/Rails environment to use when generating RBIs
# Default: development
[--halt-upon-load-error], [--no-halt-upon-load-error], [--skip-halt-upon-load-error] # Halt upon a load error while loading the Rails application
# Default: true
-c, [--config=<config file path>] # Path to the Tapioca configuration file
# Default: sorbet/tapioca/config.yml
-V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
# Default: false
Generate RBIs from gems
By default, running tapioca gem will only generate the RBI files for gems that have been added to or removed from the project's Gemfile this means that Tapioca will not regenerate the RBI files for untouched gems. If you want to force the regeneration you can supply gem names to the tapioca gem command. When supplying gem names if you want to generate RBI files for their dependencies as well, you can use the --include-dependencies option. When changing Tapioca configuration or bumping its version, it may be useful to force the regeneration of all the RBI files previously generated. This can be done with the --all option:
bin/tapioca gems --all
Are you coming from srb rbi? See how tapioca gem compares to srb rbi.
Manually requiring parts of a gem
It may happen that the RBI file generated for a gem listed inside your Gemfile.lock is missing some definitions that you would expect it to be exporting.
For gems that have a normal default require and that load all of their constants through that, everything should work seamlessly. However, for gems that are marked as require: false in the Gemfile