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

Pint Laravel Package

laravel/pint

Laravel Pint is an opinionated PHP code style fixer built on PHP-CS-Fixer. It helps keep Laravel and PHP projects clean and consistent with minimal configuration, making it easy to enforce a unified coding style across your codebase.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require --dev laravel/pint
    

    Pint is automatically registered as a dev command (pint).

  2. First Run:

    php artisan pint
    

    This applies the default Laravel preset to all PHP files in the project.

  3. Key Files:

    • pint.json (auto-generated config file)
    • .pint.json (optional custom config)

First Use Case

Run Pint as a pre-commit hook to ensure consistent code style before merging:

php artisan pint --test  # Dry run to check for changes
git add .
git commit -m "Fixed code style with Pint"

Implementation Patterns

Core Workflows

  1. Daily Code Formatting:

    php artisan pint  # Auto-fixes files in-place
    
    • Integrate into IDE (e.g., VS Code) via tasks.json:
      {
        "label": "Run Pint",
        "type": "shell",
        "command": "php artisan pint",
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
      
  2. Custom Presets: Extend the default preset in .pint.json:

    {
      "preset": "laravel",
      "rules": {
        "@PHPUnit": true,
        "yoda_style": ["always"]
      }
    }
    
    • Run with:
      php artisan pint --preset=custom
      
  3. CI/CD Integration:

    # .github/workflows/pint.yml
    jobs:
      lint:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - run: composer install
          - run: php artisan pint --test
            # Fails if changes detected
    

Advanced Patterns

  • Parallel Execution (for large codebases):
    php artisan pint --parallel
    
  • Target Specific Files/Directories:
    php artisan pint app/Http/Controllers  # Format only controllers
    php artisan pint --path=tests/Unit    # Format unit tests
    
  • Cache Optimization:
    php artisan pint --cache-file=/tmp/pint.cache
    

Gotchas and Tips

Pitfalls

  1. False Positives in --test Mode:

    • Pint may flag intentional style deviations (e.g., legacy code).
    • Fix: Exclude files in .pint.json:
      {
        "ignore": ["legacy/**"]
      }
      
  2. Performance with Large Projects:

    • Disable parallel mode for small projects:
      php artisan pint --no-parallel
      
  3. Config Overrides:

    • Command-line flags override pint.json:
      php artisan pint --preset=psr12 --rules=@Symfony  # Overrides preset
      

Debugging

  • Verbose Output:
    php artisan pint -v  # Shows applied rules
    
  • Dry Run with Diff:
    php artisan pint --test --diff  # Shows changes without applying
    

Extension Points

  1. Custom Rules: Extend the Laravel preset in .pint.json:

    {
      "preset": "laravel",
      "rules": {
        "no_unused_imports": true,
        "ordered_imports": ["sort_algorithm" => "alpha"]
      }
    }
    
  2. Preset Management:

    • List available presets:
      php artisan pint --list-presets
      
    • Use built-in presets:
      php artisan pint --preset=psr12
      
  3. IDE Integration:

    • PHPStorm: Add php artisan pint to "Before Commit" hooks.
    • VS Code: Use the PHP CS Fixer extension with Pint’s config.

Pro Tips

  • Atomic Commits: Run Pint before committing to avoid noisy diffs:
    git add .
    php artisan pint
    git commit -m "feat: implement X" --no-verify
    
  • Team Onboarding: Add Pint to composer.json scripts:
    "scripts": {
      "post-install-cmd": [
        "@php artisan pint --no-interaction"
      ]
    }
    
  • Windows Paths: Use --dirty with caution on Windows:
    php artisan pint --dirty --ignore="C:\\path\\to\\exclude"
    
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport