talira

sorbet_erb

Extracts Ruby code from ERB files so you can run Sorbet over them

open sourceMITself-hostablefree

sorbet_erb is a small Ruby gem that parses a Rails app's ERB templates and writes the Ruby code inside them to plain Ruby files, wrapped in a class scoped to the app's ApplicationController, so that Sorbet can type-check what the views call. You run bin/sorbet_erb ./app ./sorbet/erb, keep the output directory out of git, and run Sorbet as usual; it assumes the app already uses Sorbet with Tapioca for RBIs. Partials and Turbo Streams need strict locals, and an experimental locals_sig magic comment gives their locals Sorbet types. It is one developer's project (Franklin Hu), with nine releases since September 2024, the latest in July 2026.

Problems it solves

  • Sorbet doesn't check the Ruby inside our Rails ERB views, so typos in helper calls only fail at runtime
  • type-check Rails view templates in CI along with the rest of our Sorbet-typed app
  • give partial locals real types so a view gets a type error when a caller passes the wrong object
  • catch a renamed model method that a view template still calls before it reaches production
  • extract the Ruby code from ERB files into plain Ruby files that a static analyzer can read

Features

  • extracts Ruby from Rails ERB templates into Ruby files Sorbet can check
  • generated code is scoped to the app's ApplicationController
  • locals_sig magic comment gives partial locals Sorbet signatures (experimental)
  • skips partials without strict locals unless skip_missing_locals is set
  • YAML configuration with extra_includes for modules Tapioca doesn't cover
  • nominal ViewComponent support

Limitations

  • Works only with Rails applications: generated code is scoped to a Rails ApplicationController1
  • Partials and Turbo Streams without strict locals are skipped unless skip_missing_locals is set1
  • No real type checking of ViewComponent instance variables: ViewComponents are only nominally supported1

Capabilities

Has a command line toolplan not known
Has official SDKsplan not known

Alternatives

The same job

These do what sorbet_erb does.

  1. Sorbet for Rails A Sorbet build for Rails apps that type-checks specs, factories, and ERB views
  2. sorbet_view Extracts Ruby code from view templates (ERB, etc.) for Sorbet type-checking, with LSP support

Compare sorbet_erb with the top 3