tightenco/duster
Duster automatically applies Tighten’s Laravel code style by running TLint, PHP_CodeSniffer, PHP CS Fixer, and Laravel Pint. Lint or fix the whole project (or only dirty files), and generate GitHub Actions or Husky hooks with optional container env support.
Installation:
composer require tightenco/duster --dev
devDependencies.First Run (Linting):
./vendor/bin/duster lint
First Fix:
./vendor/bin/duster fix
Check Available Commands:
./vendor/bin/duster commands
lint, fix, github-actions, husky-hooks).Configuration Files:
duster.json: Customize file inclusion/exclusion or add scripts (e.g., PHPStan).tlint.json: TLint-specific rules (if extending defaults)..phpcs.xml.dist: PHP_CodeSniffer rules (Tighten preset is pre-configured)..php-cs-fixer.dist.php: PHP CS Fixer rules (includes Tighten’s CustomOrderedClassElementsFixer).pint.json: Pint configuration (Laravel preset with Tighten tweaks).Style Guide:
GitHub Action:
./vendor/bin/duster github-actions
Set Up Local Hooks (optional but recommended):
./vendor/bin/duster husky-hooks --env=ddev # For containerized environments
duster lint on staged changes.Run a Full Check:
./vendor/bin/duster lint --dirty
Fix Issues:
./vendor/bin/duster fix --dirty
Pattern: Run Duster on staged changes before committing.
Implementation:
./vendor/bin/duster husky-hooks
duster lint --dirty on git add.Why:
Customization:
duster.json to exclude test files or include scripts/:
{
"exclude": ["tests/**"],
"include": ["scripts/**"]
}
Pattern: Enforce standards on every push/PR.
Implementation:
./vendor/bin/duster github-actions
/.github/workflows/duster.yml).Example Workflow:
name: Duster Fix
on: [push, pull_request]
jobs:
fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install --dev
- run: ./vendor/bin/duster fix
- run: git config --global user.name "Duster Bot"
- run: git config --global user.email "duster@example.com"
- run: git add .
- run: git commit -m "Apply Duster fixes" || echo "No changes to commit"
- run: git push
Why:
Gotcha:
workflow_run to chain jobs:
on:
workflow_run:
workflows: ["Duster Fix"]
types: [completed]
./vendor/bin/duster lint --using="tlint,pint"
duster.json for static analysis:
{
"scripts": {
"lint": {
"phpstan": ["./vendor/bin/phpstan", "analyse"]
}
}
}
duster.json:
{
"scripts": {
"lint": {
"infection": ["./vendor/bin/infection", "--threads=4", "--show-mutations"]
},
"fix": {
"pint": ["./vendor/bin/pint"]
}
}
}
./vendor/bin/duster lint --using="phpstan,infection"
./vendor/bin/sail bin duster lint
./vendor/bin/duster --env=sail lint
./vendor/bin/duster fix app/Http/Controllers/
./vendor/bin/duster lint --dirty --dry-run
--using to control order:
./vendor/bin/duster lint --using="pint,tlint,phpcs"
Blade File Exclusions:
.phpcs.xml.dist:
<arg name="exclude" value="resources/views"/>
TLint Fix Failures:
duster fix may fail if TLint finds non-fixable issues.--using="pint,php-cs-fixer" to skip TLint fixes:
./vendor/bin/duster fix --using="pint,php-cs-fixer"
Git Hook Conflicts:
laravel-pint).npx husky add .husky/pre-commit "..." to merge hooks manually.Performance with Large Codebases:
--dirty for local work.vendor/, storage/) in duster.json:
{
"exclude": ["vendor/**", "storage/**"]
}
Custom Config Overrides:
.php-cs-fixer.dist.php may break Duster’s defaults.return (new PhpCsFixer\Config())
->set
How can I help you explore Laravel packages today?