0.0
The project is in a healthy, maintained state
Extracts Ruby code from view templates (ERB, etc.) for Sorbet type-checking, with LSP support
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 0
~> 3.0
>= 0
~> 0.3.0
 Project Readme

SorbetView

Sorbet type-checking for Rails view templates (ERB). Extracts Ruby code from templates, generates typed Ruby files, and provides LSP support for editor integration.

Features

  • Type-check Ruby code inside ERB templates with Sorbet
  • LSP proxy server for hover, completion, go-to-definition in .erb files
  • ViewComponent erb_template heredoc support
  • Source mapping between templates and generated Ruby for accurate error reporting
  • Tapioca DSL compiler for helper method RBI generation

Installation

Add to your Gemfile:

gem 'sorbet_view'

Then run:

bundle install

Setup

Generate a config file:

bundle exec sv init

This creates .sorbet_view.yml:

input_dirs:
  - app/views

exclude_paths: []

output_dir: sorbet/templates

extra_includes: []

skip_missing_locals: true

Configuration Options

Option Default Description
input_dirs ['app/views'] Directories to scan for .erb templates
exclude_paths [] Paths to exclude from scanning
output_dir 'sorbet/templates' Where generated Ruby files are written
extra_includes [] Additional modules to include in generated classes
extra_body '' Additional code to include in generated classes
skip_missing_locals true Skip partials without locals: declaration
sorbet_path 'srb' Path to the Sorbet binary
typed_level 'true' Sorbet typed level for generated files
component_dirs [] Directories to scan for ViewComponent files

Usage

Compile templates

bundle exec sv compile

Compile and type-check

bundle exec sv tc

Pass extra arguments to Sorbet after --:

bundle exec sv tc -- --error-url-base=https://srb.help/

LSP server

bundle exec sv lsp

Used by the VSCode extension for editor integration.

Clean generated files

bundle exec sv clean

Declaring locals in partials

Use magic comments to declare partial locals and their types:

<%# locals: (user:, admin: false) %>
<%# locals_sig: sig { params(user: User, admin: T::Boolean).void } %>

<h1><%= user.name %></h1>
<% if admin %>
  <p>Admin</p>
<% end %>

ViewComponent support

Add component_dirs to your config:

component_dirs:
  - app/components

Components using erb_template heredocs are automatically detected and compiled.

Tapioca integration

SorbetView includes a Tapioca DSL compiler that generates RBI files for controller helper methods. Run:

bundle exec tapioca dsl

Requirements

License

MIT License. See LICENSE for details.