TL;DR
From inside your Laravel project, do:
composer require bdelespierre/laravel-blade-linter
php artisan blade:lint
Example output:
PHP Parse error: syntax error, unexpected ')' in resources/views/_form_errors.blade.php on line 19
Add it to your pre-commit hook so you never commit an invalid file
Open
.git/hooks/pre-commit
Add the following:
#!/bin/bash
output=$(git diff --name-only --diff-filter=d --cached | grep ".blade.php$" | xargs -r php artisan blade:lint)
exitcode=$?
C_RESET='\e[0m'
C_RED='\e[31m'
C_GREEN='\e[32m'
if [[ 0 == $exitcode || 130 == $exitcode ]]; then
echo -e "${C_GREEN}BLADE OK!${C_RESET}"
else
echo -e "${C_RED}BLADE NOK!${C_RESET}\n\n$output"
exit 1
fi
- ???
- PROFIT!!!
As usual, leave a like and a comment. Don't hesitate to reach out if you have issues with this script.
Top comments (0)