Search by

roderio / blade-rs

roderio

Fast, Node-free linter and formatter for Laravel Blade templates. Installs the native blade binary.

Package info

github.com/roderio/blade-rs

Language:Rust

pkg:composer/roderio/blade-rs

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v0.2.0 2026-12-04 04:47 UTC

This package is auto-updated.

Last update: 2026-12-04 04:48:54 UTC


README

A fast, Node-free linter and formatter for Laravel Blade templates, and the lossless Blade parser behind them, written in Rust.

Try it in your browser: paste a template and see what blade lint finds and how blade fmt formats it.

Status: v0.2. blade lint and blade fmt are tested against 879 real-world templates from Laravel, Filament, Livewire, Breeze, Jetstream, Pulse, BookStack and laravel.io. The formatter is also checked by rendering templates with Laravel's own Blade engine before and after formatting.

Install

# Composer, for a Laravel project
composer require --dev roderio/blade-rs
vendor/bin/blade lint resources/views

# npm
npm install --save-dev blade-rs
npx blade-rs lint resources/views

# Homebrew
brew install roderio/tap/blade-cli

# Cargo
cargo install blade-cli

Or download a prebuilt binary (Linux including Alpine, macOS, Windows) from the latest release, or use the installer scripts:

# macOS, Linux
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/roderio/blade-rs/releases/latest/download/blade-cli-installer.sh | sh

# Windows (PowerShell)
powershell -ExecutionPolicy Bypass -c "irm https://github.com/roderio/blade-rs/releases/latest/download/blade-cli-installer.ps1 | iex"

The Composer package is a small PHP launcher. On first run it downloads the binary for your platform from the matching GitHub release, checks its SHA-256, and caches it in vendor/.

blade lint

$ blade lint resources/views
resources/views/posts/edit.blade.php:4:11: error[form-method]: browsers send method="PUT" as GET; use method="POST" with @method('PUT')
  |
4 |     <form method="PUT" action="{{ route('posts.update', $post) }}">
  |           ^^^^^^^^^^^^

1 error in 23 files

It finds problems Blade only reveals when a page breaks: unclosed @if/@foreach/@section, {{ }} with nothing in it, forms that browsers send with the wrong method or without a CSRF token, unescaped {!! !!} output, and more. See all rules.

  • Lints every *.blade.php under the given paths (default: .), skipping .gitignored and hidden directories.

  • --format human (default), json, or github (annotations on pull requests in GitHub Actions).

  • Exits with 0 if there are no errors (warnings are fine), 1 if there are errors, and 2 if it couldn't run (a bad blade.toml, a missing path, an unreadable file).

  • Configure rules in blade.toml:

    [lint.rules]
    raw-echo = "off"   # "error", "warning" or "off"
  • Silence one line with {{-- blade-lint-ignore-next-line raw-echo --}} above it.

blade fmt

$ blade fmt resources/views
formatted 42 files, 131 already formatted

It indents Blade blocks and HTML elements together, trims trailing whitespace and extra blank lines, writes {{ $x }} and @if ($x) consistently, and puts long tags one attribute per line. It's built not to change what a page renders: <pre>, <textarea>, <script>, <style>, whitespace-pre elements, @verbatim and @php keep every byte; Markdown mail and plain-text views keep their layout; and each result is checked against the original before it's written. Anything it can't format safely is left as it is. What it assumes.

  • blade fmt --check lists the files that would change and exits with 1 if any would (for CI).
  • blade fmt --stdin formats standard input, for VS Code, Neovim, Zed and PhpStorm.
  • Configure it in blade.toml under [fmt] (indent-width, use-tabs, line-width, wrap-attributes).

On the 879-template corpus, blade fmt --check takes 0.8 s and blade-formatter (Node) takes about 25 s. They don't make the same changes; details.

GitHub Action

- uses: actions/checkout@v4
- uses: roderio/blade-rs@v0.2.0
  with:
    version: 0.2.0
    args: lint --format github resources/views
- uses: roderio/blade-rs@v0.2.0
  with:
    version: 0.2.0
    args: fmt --check resources/views

Problems show up as annotations on the pull request. Inputs:

  • version: the blade-rs release to install. It defaults to latest, so pinning the action (@v0.2.0) alone doesn't pin the linter; set version too if you want the same results until you upgrade.
  • args: the arguments for blade, default lint --format github. They're split on spaces, so a path containing spaces needs working-directory instead.
  • working-directory: where to run blade, default the repository root.

blade-syntax

The parser is a separate crate for other tools to build on. It produces a lossless rowan tree (the same tree library as rust-analyzer) that reproduces the input byte for byte, never fails on broken input, and understands Blade's directives as well as the HTML tags, attributes and components around them. See crates/blade-syntax and how it works.

Planned

  • Formatting the PHP inside echoes and directives
  • More lint rules (ideas welcome: open a Lint rule issue)

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.