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

  2. 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
    
  3. 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"
        ]
    }
    

Implementation Patterns

Workflow Integration

  1. Team Onboarding

    • Include Pint and PHP-CS-Fixer in your README.md:
      ## Code Style
      - Run `composer pint` for standard formatting.
      - For WordPress projects, use `composer fix-cs`:
        ```bash
        composer fix-cs
      
    • Pair with artisanpack-ui/code-style PHPCS for linting:
      composer test:phpcs
      
  2. CI/CD Pipeline

    • Add Pint and PHP-CS-Fixer as build steps (e.g., GitHub Actions):
      - name: Format code (Standard)
        run: composer pint --test
      - name: Format code (WordPress)
        run: composer fix-cs -- --dry-run
      
    • Fail the build if formatting changes are detected (--test/--dry-run flags).
  3. IDE Configuration

    • PHPStorm: Configure actions on save for both Pint and PHP-CS-Fixer.
    • VSCode: Add to 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"
      
  4. Partial Formatting

    • Use --path to target specific directories:
      ./vendor/bin/pint app/Http/Controllers --path
      
    • Exclude files/folders with --ignore-path (create .pintignore or .php-cs-fixer.dist.php):
      storage/
      tests/Feature/
      
  5. Custom Rules Extension

    • Override the preset by extending 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
        }
      }
      
    • For WordPress-style spacing, extend .php-cs-fixer.dist.php:
      return (new PhpCsFixerConfig())
          ->setRules([
              '@artisanpack-ui-wordpress' => true,
              'SpacesInsideParenthesis' => true,
              'SpacesInsideBrackets' => true,
          ]);
      
  6. Laravel 13 Compatibility

    • This package now supports Laravel 13 (^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"
      }
      
    • Verify compatibility by running:
      composer validate
      

Gotchas and Tips

Pitfalls

  1. Preset Overrides

    • Avoid modifying published config files directly. Extend them instead to prevent updates from overwriting changes.
    • For WordPress spacing, ensure .php-cs-fixer.dist.php is not overwritten by re-publishing with --force:
      php artisan artisanpack:publish-pint-config --wordpress --force
      
  2. PHP Version Mismatch

    • Pint and PHP-CS-Fixer require PHP 8.1+. Verify compatibility:
      php -v
      
    • Pin versions in composer.json if needed:
      "require-dev": {
          "laravel/pint": "^1.0",
          "friendsofphp/php-cs-fixer": "^3.0"
      }
      
  3. Caching Issues

    • Clear caches if rules seem ignored:
      ./vendor/bin/pint --no-cache
      ./vendor/bin/php-cs-fixer fix --cache=false
      
    • Delete ~/.cache/pint and ~/.cache/php-cs-fixer manually if needed.
  4. Line Endings and WordPress Spacing

    • Pint normalizes line endings to LF. For WordPress projects, ensure .gitattributes respects CRLF if needed:
      *.php text diff=crlf smudge -crlf
      
    • Exclude WordPress spacing rules from Pint by adding to pint.json:
      "rules": {
        "SpacesInsideParenthesis": false,
        "SpacesInsideBrackets": false
      }
      
  5. Performance

    • Large projects may slow down Pint/PHP-CS-Fixer. Use parallel processing:
      ./vendor/bin/pint --parallel
      ./vendor/bin/php-cs-fixer fix --parallel
      
    • Exclude generated files (e.g., bootstrap/cache/) from formatting.

Debugging

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

Extension Points

  1. WordPress-Specific Rules

    • Use the --wordpress flag to publish WordPress-style spacing configs:
      php artisan artisanpack:publish-pint-config --wordpress
      
    • Key rules:
      • 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).
  2. Custom PHPCS Integration Sync Pint/PHP-CS-Fixer rules with artisanpack-ui/code-style PHPCS by cross-referencing their documentation. Example:

    • PHPCS enforces PSR12 array syntax (short).
    • Ensure Pint’s array_syntax and PHP-CS-Fixer’s array_syntax rules match:
      // .php-cs-fixer.dist.php
      return (new PhpCsFixerConfig())
          ->setRules([
              'array_syntax' => ['syntax' => 'short'],
          ]);
      
  3. Pre-Commit Hooks Combine Pint and PHP-CS-Fixer in a single hook:

    # .git/hooks/pre-commit
    #!/bin/sh
    composer pint --test ||
    
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony