peckphp/peck
Peck is a fast PHP CLI spell-checker for your codebase. It flags wording and spelling mistakes in filenames, classes, methods, properties, and docs, powered by GNU Aspell. Installs via Composer and fits neatly into CI and dev workflows.
Install Dependencies: Ensure GNU Aspell is installed system-wide (see README for OS-specific commands).
# Example for Ubuntu/Debian
sudo apt-get install aspell aspell-en
Add Peck to Laravel: Require the package via Composer and initialize the config:
composer require peckphp/peck --dev
./vendor/bin/peck --init
This generates peck.json with a Laravel preset (ignores common terms like config, namespace).
First Run: Scan the project for spelling issues:
./vendor/bin/peck
Use --ignore-all to skip false positives during initial setup:
./vendor/bin/peck --ignore-all
Integrate into Workflow:
Add to composer.json scripts (e.g., test:typos) or CI/CD (see CI section).
peck.json (auto-generated via --init).
Focus on the ignore.words and ignore.paths arrays to exclude false positives.preset: "laravel" to skip Laravel-specific terms../vendor/bin/peck --help for options like --text (for commit messages) or --path (custom directories).Scenario: A Laravel project with inconsistent naming (e.g., UserModel vs. User class).
Solution:
./vendor/bin/peck
peck.json under ignore.words:
{
"preset": "laravel",
"ignore": {
"words": ["UserModel", "get_data"]
}
}
# package.json
{
"scripts": {
"pre-commit": "peck && git add ."
}
}
- name: Spell Check
run: composer test:typos # Assumes `test:typos` runs `./vendor/bin/peck`
--fail-on-error (if supported in future versions) or parse output:
if ! ./vendor/bin/peck; then exit 1; fi
--text to validate commit messages:
./vendor/bin/peck --text "$(git diff --cached --name-only | head -1)"
./vendor/bin/peck --path resources/views --path docs
peck.json for project-specific terms:
{
"preset": "laravel",
"ignore": {
"words": ["AuthServiceProvider", "RouteServiceProvider"],
"paths": ["config/packages"]
}
}
peck.json in your project template with team-specific ignores../vendor/bin/peck --init && ./vendor/bin/peck
./vendor/bin/peck --ignore-all > peck-issues.txt
ignore.words to temporarily exclude non-critical issues while refactoring.composer.json:
{
"scripts": {
"docs:check": "peck --path resources/views --path docs"
}
}
composer docs:check in your CI pipeline.Artisan Command: Create a custom Artisan command to wrap Peck:
// app/Console/Commands/CheckTypos.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class CheckTypos extends Command
{
protected $signature = 'typos:check';
public function handle()
{
$this->call('vendor:publish', ['--provider' => 'Peck\PeckServiceProvider']);
$this->call('peck');
}
}
Register in app/Console/Kernel.php:
protected $commands = [
\App\Console\Commands\CheckTypos::class,
];
Pest Tests: Add a Pest test to verify Peck passes:
// tests/Feature/TyposTest.php
it('has no spelling errors', function () {
$this->artisan('typos:check')
->expectsOutputToContain('0 errors')
->assertExitCode(0);
});
symfony/process (already a dependency) to run Peck in Symfony:
use Symfony\Component\Process\Process;
$process = new Process(['./vendor/bin/peck']);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException('Peck found typos!');
}
- name: Peck (App)
run: ./vendor/bin/peck --path app
- name: Peck (Config)
run: ./vendor/bin/peck --path config
CONTRIBUTING.md:
## Local Setup
Install Aspell:
```bash
# Ubuntu/Debian
sudo apt-get install aspell aspell-en
config, namespace)."preset": "laravel") to ignore common terms.ignore.words in peck.json.ignore.paths (e.g., vendor, node_modules).scoop install main/aspell
README.md under "Windows Setup."peck.json unexpectedly.--config to ensure local overrides work:
./vendor/bin/peck --config custom/peck.json
peck.json:
{
"language": "en_GB" // Example: British English
}
aspell dump dicts
./vendor/bin/peck -v # Hypothetical verbose flag
aspell check en_US < app/Http/Controllers/UserController.php
ignore.paths to exclude files:
How can I help you explore Laravel packages today?