Sheath rule
blade-compiler-valid-output
- Package
- Blade Compiler
- Category
- Blade
- Default severity
- error by default
- Auto-fix
- Manual fix
#Why
Laravel compiles directives, components, echoes, precompilers, and preparation callbacks into PHP. A template can parse as Blade but still produce PHP that fails before the view renders.
Sheath compiles the template with the application's configured compiler and validates the generated PHP without rendering the view or executing the output.
#Examples
#Bad
{{-- "break" is outside a loop or switch, so the compiled PHP is invalid. --}}
@php
break;
@endphp
#Good
{{-- The continue directive remains inside the foreach loop. --}}
@foreach ($articles as $article)
@if ($article->isHidden())
@continue
@endif
<h2>{{ $article->title }}</h2>
@endforeach
The rule also reports malformed directives, component compilation failures,
early echo delimiters, invalid custom directive output, duplicate declarations,
duplicate import aliases, and invalid goto targets.
#PHP Validation
The phpValidation option controls how compiled PHP is checked. process is
the default and runs the local PHP binary in lint-only mode:
<?php
return [
'rules' => [
'blade-compiler-valid-output' => ['error', [
'phpValidation' => 'process',
]],
],
];
Use parser when the runtime cannot create subprocesses:
<?php
return [
'rules' => [
'blade-compiler-valid-output' => ['error', [
'phpValidation' => 'parser',
]],
],
];
Parser validation detects PHP syntax errors but cannot detect every compile-time
fatal that php -l reports, including an illegal break, duplicate import,
duplicate declaration, or invalid goto.
#Persistent Cache
Persistent cache reuse is disabled for this rule unless you provide a
cacheIdentity. Use a deployment or build revision that changes whenever
compiler callbacks, components, component discovery, views, or compiler
configuration change:
<?php
return [
'rules' => [
'blade-compiler-valid-output' => ['error', [
'cacheIdentity' => env('APP_BUILD_ID', ''),
]],
],
];
#Notes
Compiler callbacks and component discovery run during linting because they affect the generated PHP. An invalid template may invoke a callback twice while Sheath locates the failure, so callbacks should be deterministic and avoid external side effects.
Process validation requires a local PHP binary and proc_open. It runs in
lint-only mode without writing a compiled view. If either requirement is
unavailable, Sheath reports the validation failure instead of treating the
template as valid.
Authored PHP regions can still produce findings when an earlier compiler error prevents full-template validation.
#See Also
Related documentation describes the plugin and the Core syntax checks:
- Blade Compiler Plugin: Install the package and enable its preset
- blade-valid-php-syntax: Validate authored raw PHP without the application compiler
- Configuration: Override rule severity and options