peckphp/peck
Peck is a fast PHP CLI that spell-checks your codebase—filenames, classes, methods, properties, docs, and more—using GNU Aspell. Built to fit naturally into your workflow like Pint or Pest. Requires PHP 8.2+ and Aspell.
Install Dependencies: Ensure GNU Aspell is installed on your system (see README for OS-specific instructions).
# Debian/Ubuntu
sudo apt-get install aspell aspell-en
Install Peck: Add Peck to your project via Composer:
composer require peckphp/peck --dev
Initialize Configuration:
Generate a peck.json file with default settings (Laravel preset included):
./vendor/bin/peck --init
Run First Check: Execute Peck in your project root to scan for spelling issues:
./vendor/bin/peck
Add Peck to your pre-commit workflow to catch naming inconsistencies early:
# Example: Using Laravel Git Hooks
./vendor/bin/peck --path=app/Http/Controllers --text="Commit message here"
Daily Local Development:
app/, config/) to catch typos in class/method names:
./vendor/bin/peck --path=app/Models
--text to validate commit messages or docblocks:
./vendor/bin/peck --text="Fix the user auth flow"
CI/CD Integration:
- name: Run Peck
run: ./vendor/bin/peck --ignore-all # Temporarily ignore all to avoid false positives
--ignore-all initially to baseline your codebase, then refine peck.json to exclude false positives.Team Onboarding:
peck.json with project-specific ignores (e.g., app/Helpers, config/) and share it in your repo.{
"preset": "laravel",
"ignore": {
"words": ["laravel", "eloquent"],
"paths": ["app/Helpers/*"]
}
}
Combine with PHPStan/Pest:
Use Peck to catch lexical issues (e.g., UsrModel vs. UserModel) while PHPStan handles logical errors.
Example workflow:
./vendor/bin/peck && ./vendor/bin/phpstan analyse
Custom Dictionaries:
Extend Aspell’s dictionary by adding domain-specific terms to peck.json:
{
"ignore": {
"words": ["acme", "customer360"]
}
}
IDE Shortcuts: Create a shell alias for quick checks:
alias peck-check='./vendor/bin/peck --path=app'
False Positives in Laravel:
Route, ServiceProvider) as misspellings.laravel preset or manually ignore words in peck.json:
"ignore": { "words": ["Route", "ServiceProvider", "Eloquent"] }
GNU Aspell Dependency:
CONTRIBUTING.md or use Docker for CI:
RUN apt-get update && apt-get install -y aspell aspell-en
Performance on Large Codebases:
./vendor/bin/peck --path=app/Models # Target specific directories
Case Sensitivity:
User and user in filenames.peck.json or use --ignore-all for case variants.Verbose Output: Enable debug mode to inspect Aspell’s suggestions:
./vendor/bin/peck --verbose
Check Aspell Dictionaries: List available languages to troubleshoot language-specific issues:
aspell dump dicts
Custom Presets:
Extend the laravel preset by creating a peck-custom.json with project-specific rules:
{
"preset": "laravel",
"ignore": {
"words": ["acme", "legacy"],
"paths": ["app/OldCode/*"]
}
}
Hook into Laravel Events:
Trigger Peck automatically on artisan commands (e.g., make:model):
// app/Console/Kernel.php
protected function commands()
{
$this->commands([
\Peck\Console\PeckCommand::class,
]);
}
GitHub Actions Caching: Cache Aspell dictionaries between runs to speed up CI:
- name: Cache Aspell
uses: actions/cache@v3
with:
path: /usr/share/aspell
key: ${{ runner.os }}-aspell
Exclude Vendors:
Always ignore vendor/ in peck.json to avoid false positives:
"ignore": { "paths": ["vendor/*"] }
Pair with pint:
Run Peck after pint to ensure formatted code is also spell-checked:
./vendor/bin/pint && ./vendor/bin/peck
Document Ignored Terms:
Maintain a PECK_IGNORES.md file in your repo to explain why certain words/path are excluded (e.g., legacy terms, domain-specific abbreviations).
How can I help you explore Laravel packages today?