erbfmt

ERB formatter and linter

erbfmt

A fast, Prettier/Biome-like formatter and linter for Rails ERB and HTML+ERB templates.

-<div><% if user.admin? %><span>Admin</span><% end %></div>
+<div>
+  <% if user.admin? %>
+    <span>Admin</span>
+  <% end %>
+</div>

One structure

Formats HTML nesting and ERB control flow together instead of treating them as unrelated text.

Safe by default

Preserves Ruby expressions when they cannot be recognized and rewritten safely.

Formatter + linter

Use the same Rust CLI locally, in CI, and through the first-party VS Code extension.

Install

For Rails projects, install erbfmt through Bundler so every developer and CI job uses the same pinned version.

bundle add erbfmt --group development --require false
bundle exec erbfmt --version

For a global local command, install the RubyGem directly.

gem install erbfmt -v 0.1.5
erbfmt --version

Bundler is preferred for projects because it pins the formatter version. Standalone binaries are also available from the v0.1.5 release.

Quick start

Create erbfmt.json in the Rails project, then format or lint templates.

cd your-rails-project
erbfmt init
erbfmt --write app/views/users/show.html.erb
erbfmt --check app/views/users/show.html.erb
erbfmt --lint app/views/users/show.html.erb

--write, --check, and --lint are mutually exclusive. Check mode fails when formatting would change a file. Lint mode fails when it finds an error-level diagnostic.

Standalone ERB trim, escaped, and raw-output markers such as <%-, -%>, <%%, and <%== are currently rejected. erbfmt fails without writing the file rather than changing their semantics.

Continue with the configuration reference to choose indentation, line width, and lint severities.

Principles

HTML and ERB belong together

erbfmt understands HTML elements and ERB control-flow markers such as if, case, do, branches, and end. Long HTML tags and safely recognized standalone ERB calls can be wrapped to the configured line width.

Ambiguous Ruby stays intact

erbfmt does not build a full Ruby AST or analyze Rails application semantics. Complex expressions are preserved rather than aggressively rewritten.

One CLI everywhere

The VS Code extension is a thin wrapper around the same CLI used in a terminal and CI, keeping formatting and diagnostics consistent.