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.
## Getting Started
### Minimal Setup
1. **Install the Package**
```bash
composer require artisanpack-ui/code-style-pint --dev
Ensure pint and php-cs-fixer are installed globally or as dev dependencies:
composer require laravel/pint --dev
composer require friendsofphp/php-cs-fixer --dev
Publish the Preset
Run the publisher to copy the pre-configured pint.json and optionally the WordPress-style .php-cs-fixer.dist.php:
php artisan vendor:publish --provider="ArtisanPack\CodeStylePint\CodeStylePintServiceProvider" --tag="pint-config"
For WordPress-style spacing, use:
php artisan artisanpack:publish-pint-config --wordpress
This generates both pint.json and .php-cs-fixer.dist.php with WordPress-specific rules.
First Use Case: Formatting a File
Run Pint on a single file (e.g., app/Models/User.php):
./vendor/bin/pint app/Models/User.php
Or format the entire project:
./vendor/bin/pint
For WordPress-style spacing, use:
./vendor/bin/php-cs-fixer fix --rules=@artisanpack-ui-wordpress
Integrate with Git Hooks (Optional)
Add Pint and PHP-CS-Fixer to your composer.json scripts:
"scripts": {
"post-autoload-dump": [
"@pint",
"@php-cs-fixer fix --rules=@artisanpack-ui-wordpress --dry-run"
]
}
Team Onboarding
README.md:
## Code Style
- Run `composer pint` for standard formatting.
- For WordPress projects, use `composer fix-cs`:
```bash
composer fix-cs
artisanpack-ui/code-style PHPCS for linting:
composer test:phpcs
CI/CD Pipeline
- name: Format code (Standard)
run: composer pint --test
- name: Format code (WordPress)
run: composer fix-cs -- --dry-run
--test/--dry-run flags).IDE Configuration
settings.json:
"editor.formatOnSave": true,
"editor.defaultFormatter": "bmewburn.vscode-intelephense",
"intelephense.format.enable": false,
"php-cs-fixer.executablePath": "${workspaceFolder}/vendor/bin/php-cs-fixer",
"php-cs-fixer.rules": "@artisanpack-ui-wordpress"
Partial Formatting
--path to target specific directories:
./vendor/bin/pint app/Http/Controllers --path
--ignore-path (create .pintignore or .php-cs-fixer.dist.php):
storage/
tests/Feature/
Custom Rules Extension
pint.json or .php-cs-fixer.dist.php:
// pint.json
{
"$schema": "https://json.schemastore.org/pint.json",
"extends": "./vendor/artisanpack-ui/code-style-pint/pint.json",
"rules": {
"array_syntax": ["syntax" => "short"],
"concat_space": true
}
}
.php-cs-fixer.dist.php:
return (new PhpCsFixerConfig())
->setRules([
'@artisanpack-ui-wordpress' => true,
'SpacesInsideParenthesis' => true,
'SpacesInsideBrackets' => true,
]);
Laravel 13 Compatibility
^13.0) alongside Laravel 10-12. Ensure downstream packages depending on artisanpack-ui/code-style-pint also update their illuminate/support constraints to:
"require": {
"illuminate/support": "^10.0|^11.0|^12.0|^13.0"
}
composer validate
Preset Overrides
.php-cs-fixer.dist.php is not overwritten by re-publishing with --force:
php artisan artisanpack:publish-pint-config --wordpress --force
PHP Version Mismatch
php -v
composer.json if needed:
"require-dev": {
"laravel/pint": "^1.0",
"friendsofphp/php-cs-fixer": "^3.0"
}
Caching Issues
./vendor/bin/pint --no-cache
./vendor/bin/php-cs-fixer fix --cache=false
~/.cache/pint and ~/.cache/php-cs-fixer manually if needed.Line Endings and WordPress Spacing
.gitattributes respects CRLF if needed:
*.php text diff=crlf smudge -crlf
pint.json:
"rules": {
"SpacesInsideParenthesis": false,
"SpacesInsideBrackets": false
}
Performance
./vendor/bin/pint --parallel
./vendor/bin/php-cs-fixer fix --parallel
bootstrap/cache/) from formatting.Dry Run Preview changes without modifying files:
./vendor/bin/pint --test
./vendor/bin/php-cs-fixer fix --dry-run
Verbose Mode Enable debug output:
./vendor/bin/pint -v
./vendor/bin/php-cs-fixer fix -v
Rule-Specific Debugging Isolate rule issues:
./vendor/bin/pint --rules="concat_space"
./vendor/bin/php-cs-fixer fix --rules="SpacesInsideParenthesis"
WordPress-Specific Rules
--wordpress flag to publish WordPress-style spacing configs:
php artisan artisanpack:publish-pint-config --wordpress
SpacesInsideParenthesis: Adds spaces inside parentheses (e.g., if ( )).SpacesInsideBrackets: Adds spaces inside brackets for variable indices (e.g., $array[ ]).concat_space: Ensures spacing around concatenation operators (e.g., $str . $str).Custom PHPCS Integration
Sync Pint/PHP-CS-Fixer rules with artisanpack-ui/code-style PHPCS by cross-referencing their documentation. Example:
PSR12 array syntax (short).array_syntax and PHP-CS-Fixer’s array_syntax rules match:
// .php-cs-fixer.dist.php
return (new PhpCsFixerConfig())
->setRules([
'array_syntax' => ['syntax' => 'short'],
]);
Pre-Commit Hooks Combine Pint and PHP-CS-Fixer in a single hook:
# .git/hooks/pre-commit
#!/bin/sh
composer pint --test ||
How can I help you explore Laravel packages today?