Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Code Style Pint Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Install the package in your Laravel project:
    composer require artisanpack-ui/code-style-pint --dev
    
  2. Publish the Pint config to your project root:
    php artisan artisanpack:publish-pint-config
    
  3. Run Pint to format your code:
    ./vendor/bin/pint
    

First Use Case

Use this package to enforce consistent code formatting across your Laravel project. It aligns with artisanpack-ui/code-style PHPCS rules, ensuring:

  • Short array syntax ([] instead of array())
  • Consistent spacing (e.g., if ( $var ) vs. if ($var))
  • Ordered imports and class elements
  • Strict type declarations

Where to Look First

  • 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.

Implementation Patterns

Daily Workflow

  1. 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
    
  2. 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
    
  3. IDE Integration:

    • PhpStorm: Configure an external tool to run Pint on save.
    • VS Code: Use the laravel-pint extension with your pint.json.

Integration Tips

  • 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
    

Programmatic Customization

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);

Gotchas and Tips

Pitfalls

  1. 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
    
  2. 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
      }
    }
    
  3. Exclusion Overrides: If you exclude directories (e.g., tests/fixtures), ensure they’re not accidentally included in other tools (e.g., PHPCS).

  4. IDE Caching: After updating pint.json, restart your IDE to avoid cached rule conflicts.

Debugging

  • 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 .
    

Extension Points

  1. 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');
    
  2. 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
    
  3. 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
    

Configuration Quirks

  • 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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky