Sheath rule
blade-no-debug
Debug statements should not be present in Blade templates.
#Why
A dd() left in a template halts the response where it sits, and dump() prints
the variable to the page. Either one shows a visitor whatever that variable held:
model attributes, config values, the contents of a request.
#Examples
#Bad
<!-- Blade debug directives -->
@dd($user)
@dump($items)
<!-- PHP debug functions in echo -->
{{ dd($data) }}
{{ dump($variable) }}
{{ var_dump($array) }}
{{ print_r($object) }}
<!-- Debug functions in raw output -->
{!! dd($request) !!}
{!! var_dump($response) !!}
<!-- Debug in @php blocks -->
@php
dd($user);
dump($items);
@endphp
<!-- Debug calls nested in directive expressions -->
@if(dump($user))
<p>User found</p>
@endif
#Good
<!-- Use proper output for display -->
{{ $user->name }}
{{ $items->count() }}
<!-- Use logging for debugging (doesn't show to users) -->
@php
\Log::debug('User data', ['user' => $user]);
@endphp
<!-- Use proper conditional display -->
@if(config('app.debug'))
<pre>{{ json_encode($data, JSON_PRETTY_PRINT) }}</pre>
@endif
#Debug Statements Detected
The following Blade directives and PHP functions are recognized as debugging statements.
| Statement | Type | Description |
|---|---|---|
@dd() |
Blade directive | Dump and die |
@dump() |
Blade directive | Dump without dying |
dd() |
PHP function | Dump and die |
dump() |
PHP function | Dump variable |
ray() |
PHP function | Send to Ray |
var_dump() |
PHP function | Dump with types |
print_r() |
PHP function | Print readable |
var_export() |
PHP function | Export as PHP code |
debug_backtrace() |
PHP function | Capture backtrace |
debug_print_backtrace() |
PHP function | Print backtrace |
Function calls are checked in directive arguments, echoes ({{ }}, {!! !!}),
@php ... @endphp blocks, and raw <?php ?> tags. A debug name inside a string
literal or comment, such as $mode = 'dd';, does not count as a call.
#Options
Use these options to change the recognized directive and function names.
| Option | Type | Default | Description |
|---|---|---|---|
directives |
array | ['dd', 'dump'] |
Blade directive names to report |
functions |
array | ['dd', 'dump', 'ray', 'var_dump', 'print_r', 'var_export', 'debug_print_backtrace', 'debug_backtrace'] |
Global PHP function names to report |
Each configured list replaces its default, so projects can add their own debug
helpers or set a list to []:
<?php
'blade-no-debug' => ['error', [
'directives' => ['dd', 'dump'],
'functions' => ['dd', 'dump', 'inspect'],
]],
#Alternatives
Instead of debug statements:
- Logging: Use
\Log::debug()to log data without displaying it - Laravel Debugbar: Install for development debugging
- Telescope: Use Laravel Telescope for request inspection
- IDE Debugging: Use Xdebug with your IDE
#Notes
- These are almost always statements someone meant to remove
- The
recommendedpreset reports these statements as errors, so a leftoverdd()fails a CI run without extra configuration
#Related Rules
- blade-no-php-tag - Prefer @php over raw PHP tags