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 for minimalists. Built on PHP-CS-Fixer, it makes it easy to keep your Laravel and PHP projects clean and consistent with a simple, standardized formatting workflow.

View on GitHub
Deep Wiki
Context7
## Getting Started

### Minimal Setup
1. **Installation**:
   ```bash
   composer require --dev laravel/pint

Pint is automatically registered as a dev dependency and adds a pint command to your project.

  1. First Run:

    php artisan pint
    

    This runs Pint with the default Laravel preset, formatting all PHP files in your project.

  2. Key Files to Know:

    • Default Config: Located at vendor/laravel/pint/src/Preset.php (Laravel preset).
    • Custom Config: Create pint.json in your project root to override defaults (see Laravel Docs).
  3. First Use Case: Run Pint in a CI pipeline (e.g., GitHub Actions) to enforce consistent code style before merging:

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

Implementation Patterns

Daily Workflows

  1. Pre-Commit Hook: Integrate Pint with pre-commit (e.g., using Laravel Git Hooks) to auto-format staged files:

    php artisan pint --dirty
    
    • --dirty: Only formats files modified in the current Git working directory.
  2. VS Code Integration: Add Pint to your editor for real-time feedback:

    // .vscode/settings.json
    {
      "editor.formatOnSave": true,
      "editor.defaultFormatter": "bmewburn.vscode-intelephense",
      "intelephense.format.enable": false,
      "[php]": {
        "editor.formatOnSave": false
      }
    }
    

    Use the PHP Intelephense extension with Pint via a custom task.

  3. Parallel Processing: Speed up large codebases with parallel execution (Windows/Linux/macOS):

    php artisan pint --parallel --jobs=4  # 4 parallel processes
    
    • Shortcut: php artisan pint -p --jobs=4.
  4. Custom Presets: Extend the default preset in pint.json:

    {
      "preset": "laravel",
      "rules": {
        "@PER-CS": true,
        "fully_qualified_strict_types": true,
        "no_unneeded_import_alias": true
      }
    }
    
  5. CI Feedback: Use --test to exit with non-zero status if changes are needed:

    php artisan pint --test
    
    • Combine with --diff to show changes without applying them:
      php artisan pint --diff
      

Integration Tips

  • Composer Scripts: Add Pint to composer.json scripts for one-liners:

    "scripts": {
      "lint": "pint",
      "lint:fix": "pint --diff"
    }
    

    Run with:

    composer lint
    
  • GitHub Actions: Cache Pint’s PHAR to avoid re-downloading:

    - name: Cache Pint
      uses: actions/cache@v3
      with:
        path: ~/.cache/pint
        key: ${{ runner.os }}-pint
    
  • Monorepos: Use --path-mode=relative to format files outside the project root:

    php artisan pint --path-mode=relative --path=../monorepo/packages/*
    

Gotchas and Tips

Pitfalls

  1. Performance:

    • Parallel Mode on Windows: Ensure --jobs is set to 1 or omit --parallel if encountering hangs (see #272).
    • Large Files: Pint may struggle with files >10MB. Exclude them via .pintignore:
      # .pintignore
      storage/logs/*.log
      
  2. Configuration Conflicts:

    • Empty Preset: If preset: "empty", Pint applies no rules. Override explicitly:
      {
        "preset": "empty",
        "rules": {
          "phpdoc_align": false,
          "single_line_comment_spacing": true
        }
      }
      
    • Insecure Config Loading: Pint rejects HTTP-based config paths (fixed in v1.29.2).
  3. Rule Interactions:

    • fully_qualified_strict_types: May conflict with no_unused_imports. Test with:
      php artisan pint --dry-run
      
    • yoda_style: Disables when null comparisons are involved (see #213).
  4. Edge Cases:

    • Stdin Support: Requires explicit --stdin flag (added in v1.26.0):
      echo "<?php echo 'test';" | php artisan pint --stdin
      
    • PHP 8.5: Partial support exists, but test custom rules (see #411).

Debugging

  1. Verbose Output: Use -v or --verbose to diagnose issues:

    php artisan pint -v
    
    • Shows processed files and rule applications.
  2. Cache Issues: Clear Pint’s cache if rules seem ignored:

    php artisan cache:clear
    rm -rf ~/.cache/pint
    
  3. Rule Validation: Validate your pint.json with:

    php artisan pint --validate
    

Extension Points

  1. Custom Rules: Extend Pint’s rules by modifying the underlying PHP-CS-Fixer config. Example:

    {
      "rules": {
        "Pint/phpdoc_type_annotations_only": true,
        "custom_rule": {
          "path": "./CustomRule.php",
          "parameters": {}
        }
      }
    }
    
  2. Preset Inheritance: Extend existing presets (e.g., Laravel + PER-CS):

    {
      "extends": ["laravel", "@PER-CS"],
      "rules": {
        "cast_spaces": false
      }
    }
    
  3. Agent Format: Use the agent format for IDE integration (auto-detected in Claude Code/OpenCode):

    php artisan pint --format=agent
    
  4. Exit Status: Use --with-exit-status to fail builds when changes are needed:

    php artisan pint --test --with-exit-status
    

Pro Tips

  • Selective Formatting: Target specific files/directories:
    php artisan pint app/Http/Controllers/
    
  • Dry Runs: Preview changes without modifying files:
    php artisan pint --dry-run
    
  • Summary Output: Write a summary to a file:
    php artisan pint --summary-file=pint-summary.txt
    
  • Bail on First Error: Stop after the first error with --bail:
    php artisan pint --bail
    
  • Ignore Changes: Skip --dirty checks with --ignore-no-changes:
    php artisan pint --dirty --ignore-no-changes
    

```markdown
### Laravel-Specific Tips
1. **Laravel Preset Quirks**:
   - The Laravel preset enforces `snake_case` for PHPUnit test methods. Override in `pint.json` if needed:
     ```json
     {
       "rules": {
         "phpunit_method_casing": false
       }
     }
     ```

2. **Artisan Command Alias**:
   Add an alias to your `~/.bashrc` or `~/.zshrc`:
   ```bash
   alias pint='php artisan pint'
  1. Laravel Mix/Webpack: Integrate Pint with Laravel Mix for frontend + backend formatting:

    // webpack.mix.js
    mix.postCss('resources/css/app.css', 'public/css', [
      // ...
    ])
    .then(() => {
      require('child_process').execSync('php artisan pint', { stdio: 'inherit' });
    });
    
  2. Laravel Forge/Envoyer: Add Pint to deployment scripts:

    # envoyer/deploy.php
    $tasks->add('composer
    
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony