artisanpack-ui/code-style-pint
Laravel Pint preset matching ArtisanPack UI coding standards. Publishes a ready-made pint.json for apps or generates it via builder for packages. Optional WordPress-style spacing support via PHP-CS-Fixer stubs and commands.
composer require artisanpack-ui/code-style-pint --dev
php artisan artisanpack:publish-pint-config
./vendor/bin/pint
Use this package to enforce consistent code formatting across your Laravel project. It aligns with artisanpack-ui/code-style PHPCS rules, ensuring:
[] instead of array())if ( $var ) vs. if ($var))pint.json: The published config file (auto-generated by the package).docs/customization.md: For rule customization and advanced usage.docs/rules-mapping.md: To understand how PHPCS rules map to Pint.Pre-commit Hook:
Add Pint to your pre-commit hook (e.g., using husky or laravel-pint extension) to auto-format code before commits.
./vendor/bin/pint --test # Dry run to catch issues
CI/CD Integration: Run Pint in your CI pipeline (e.g., GitHub Actions) to enforce formatting:
# .github/workflows/pint.yml
- name: Run Pint
run: ./vendor/bin/pint --test
IDE Integration:
laravel-pint extension with your pint.json.Combine with PHPCS: Use both Pint (for auto-fixable formatting) and PHPCS (for non-auto-fixable rules like naming conventions):
./vendor/bin/pint && ./vendor/bin/phpcs --standard=ArtisanPackUIStandard .
Laravel Packages:
Use PintConfigBuilder in pint-setup.php (no php artisan access):
PintConfigBuilder::create()
->withArtisanPackUIPreset()
->exclude(['vendor', 'tests/fixtures'])
->save(__DIR__ . '/pint.json');
WordPress-Style Spacing:
For WordPress-style spacing (e.g., if ( $var )), publish the PHP-CS-Fixer config:
php artisan artisanpack:publish-pint-config --wordpress
Then run:
./vendor/bin/php-cs-fixer fix
Use PintConfigBuilder to dynamically generate configs:
$config = PintConfigBuilder::create()
->withArtisanPackUIPreset()
->removeRule('yoda_style') // Disable Yoda style
->addRule('concat_space', ['spacing' => 'one']) // Customize concatenation
->exclude('app/Legacy') // Exclude directories
->toJson();
file_put_contents('pint.json', $config);
WordPress Spacing Requires PHP-CS-Fixer:
Pint cannot handle WordPress-style spacing (e.g., if ( $var )). Use PHP-CS-Fixer instead:
composer require --dev friendsofphp/php-cs-fixer
./vendor/bin/php-cs-fixer fix
Strict Types Conflicts:
If your project uses declare(strict_types=1) inconsistently, Pint’s declare_strict_types rule may cause conflicts. Disable it:
{
"rules": {
"declare_strict_types": false
}
}
Exclusion Overrides:
If you exclude directories (e.g., tests/fixtures), ensure they’re not accidentally included in other tools (e.g., PHPCS).
IDE Caching:
After updating pint.json, restart your IDE to avoid cached rule conflicts.
Dry Run First:
Always test Pint with --test before committing:
./vendor/bin/pint --test
This shows changes without modifying files.
Rule-Specific Issues: If Pint fails on a specific file, check the rule causing the issue:
./vendor/bin/pint --test --verbose
PHPCS vs. Pint: Some rules (e.g., naming conventions) are only enforced by PHPCS. Run both tools to catch all issues:
./vendor/bin/pint && ./vendor/bin/phpcs .
Custom Rule Groups: Extend the preset by adding custom rules:
PintConfigBuilder::create()
->withArtisanPackUIPreset()
->addRule('no_unused_imports', true) // Enable unused import removal
->addRule('phpdoc_to_param_type', true) // Add PHPDoc type hints
->save('pint.json');
Override Laravel Boost AI Guidelines: Publish the Boost override to align AI-generated code with your Pint rules:
php artisan vendor:publish --tag=artisanpack-boost-override
Composer Scripts:
Add Pint to your composer.json for easy access:
{
"scripts": {
"pint": "pint",
"pint:test": "pint --test",
"pint:fix": "pint --test && pint"
}
}
Now run with:
composer pint:fix
Default Excludes:
The preset excludes vendor/, node_modules/, and storage/. Add more in PintConfigBuilder:
->exclude(['app/Legacy', 'tests/old-tests'])
WordPress Spacing Flag:
The --wordpress flag generates a .php-cs-fixer.dist.php file. Ensure PHP-CS-Fixer is installed:
composer require --dev friendsofphp/php-cs-fixer
Laravel Boost Compatibility: The package includes AI guidelines for Laravel Boost. If you don’t use Boost, the override is harmless but unnecessary.
How can I help you explore Laravel packages today?