artisanpack-ui/code-style-pint
最新稳定版本:1.1.0
Composer 安装命令:
composer require artisanpack-ui/code-style-pint
包简介
Laravel Pint preset for ArtisanPack UI code standards
README 文档
README
Laravel Pint preset for ArtisanPack UI code standards. This package provides a pre-configured pint.json file that enforces coding standards matching the artisanpack-ui/code-style PHPCS package.
Installation
Install the package via Composer:
composer require artisanpack-ui/code-style-pint --dev Usage
For Laravel Applications
Publish the pint.json configuration file to your project root:
php artisan artisanpack:publish-pint-config Use --force to overwrite an existing pint.json:
php artisan artisanpack:publish-pint-config --force Alternatively, use Laravel's standard publish command:
php artisan vendor:publish --tag=artisanpack-pint-config For Laravel Packages
When developing a Laravel package, use PintConfigBuilder directly since php artisan isn't available:
Standard Pint Configuration:
<?php // pint-setup.php require __DIR__ . '/vendor/autoload.php'; use ArtisanPackUI\CodeStylePint\Config\PintConfigBuilder; PintConfigBuilder::create() ->withArtisanPackUIPreset() ->save(__DIR__ . '/pint.json'); Run it once to generate your config:
php pint-setup.php Or copy the stub directly:
cp vendor/artisanpack-ui/code-style-pint/stubs/pint.json.stub pint.json WordPress-Style Spacing (PHP-CS-Fixer):
For WordPress-style spacing in packages, copy the PHP-CS-Fixer configuration stub:
cp vendor/artisanpack-ui/code-style-pint/stubs/.php-cs-fixer.dist.php.stub .php-cs-fixer.dist.php Then install PHP-CS-Fixer:
composer require --dev friendsofphp/php-cs-fixer WordPress-Style Spacing (Laravel Applications)
If you need WordPress-style spacing (spaces inside parentheses and brackets) in a Laravel application, use the --wordpress flag:
php artisan artisanpack:publish-pint-config --wordpress This will create .php-cs-fixer.dist.php with custom fixers that enforce:
- Spaces inside parentheses:
if ( $var )instead ofif ($var) - Spaces inside brackets (variable indices only):
$array[ $key ]instead of$array[$key] - Spaces around concatenation:
$a . $binstead of$a.$b
Note: WordPress spacing requires PHP-CS-Fixer instead of Pint:
# Install PHP-CS-Fixer composer require --dev friendsofphp/php-cs-fixer # Run code formatting ./vendor/bin/php-cs-fixer fix Running Pint
Once the Pint configuration is in place, run Pint to format your code:
./vendor/bin/pint To test without making changes:
./vendor/bin/pint --test Running PHP-CS-Fixer (WordPress Spacing)
If you're using WordPress-style spacing, run PHP-CS-Fixer instead:
./vendor/bin/php-cs-fixer fix To test without making changes:
./vendor/bin/php-cs-fixer fix --dry-run --diff Programmatic Configuration
For advanced use cases, you can build configurations programmatically:
use ArtisanPackUI\CodeStylePint\Config\PintConfigBuilder; // Full preset (use base_path() in Laravel apps, __DIR__ in packages) PintConfigBuilder::create() ->withArtisanPackUIPreset() ->save(__DIR__ . '/pint.json'); // Customize rule groups PintConfigBuilder::create() ->withFormattingRules(true) ->withCodeStructureRules(true) ->withBestPracticeRules(false) // Disable strict types, yoda style, etc. ->withArtisanPackUIPreset() ->addRule('concat_space', ['spacing' => 'one']) ->removeRule('yoda_style') ->exclude('tests/fixtures') ->save(__DIR__ . '/pint.json'); See docs/customization.md for detailed customization options.
Rules Included
This preset enforces the following code style rules:
- Array Syntax: Short array syntax (
[]instead ofarray()) - Binary Operator Spaces: Single space around operators, aligned assignments
- Brace Position: Same line for control structures, next line for functions
- Class Structure: Ordered class elements (traits, constants, properties, methods)
- Concatenation Spacing: Single space around concatenation operator (
.) - Import Ordering: Alphabetically sorted imports (classes, functions, constants)
- Single Quotes: Single quotes for strings without variables
- Trailing Commas: In multiline arrays, arguments, and parameters
- Visibility Required: All properties, methods, and constants must have visibility
- Yoda Style: Literals on the left side of comparisons
For WordPress-style spacing (spaces inside parentheses and brackets), see the WordPress-Style Spacing section.
Complementary PHPCS Usage
Some rules cannot be enforced by Pint (security checks, naming conventions, line length). For complete code style enforcement, use both packages:
{ "require-dev": { "artisanpack-ui/code-style": "^1.0", "artisanpack-ui/code-style-pint": "^1.0" } } Recommended Workflow
Run Pint first to auto-fix formatting:
./vendor/bin/pintRun PHPCS to catch remaining issues:
./vendor/bin/phpcs --standard=ArtisanPackUIStandard .
Laravel Boost AI Guidelines
This package includes AI guidelines for Laravel Boost, which will automatically be available when users run php artisan boost:install.
Overriding Default Pint Guidelines
To have AI assistants use ArtisanPack UI standards instead of Laravel's default Pint guidelines, publish the Boost override:
php artisan vendor:publish --tag=artisanpack-boost-override This creates .ai/guidelines/laravel/pint.blade.php, which overrides Boost's default Pint guidelines with ArtisanPack UI specific guidance.
Documentation
- Customization Guide - Customize rules and configuration
- Rules Mapping - PHPCS to Pint rule mapping
- IDE Integration - PhpStorm, VS Code, Vim, and more
- CI/CD Integration - GitHub Actions, GitLab CI, and more
- Migration Guide - Migrate from other tools
Contributing
As an open source project, this package is open to contributions from anyone. Please read through the contributing guidelines to learn more about how you can contribute to this project.
License
This package is open-sourced software licensed under the GPL-3.0-or-later license.
统计信息
- 总下载量: 243
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2026-01-04