Laravel Pint is an opinionated PHP code style fixer for minimalists.

Overview

Logo Laravel Pint

Overview Laravel Pint

Build Status Total Downloads Latest Stable Version License

Introduction

Laravel Pint is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP-CS-Fixer and makes it simple to ensure that your code style stays clean and consistent.

Installation

Laravel Pint requires PHP 8.0+.

You may use Composer to install Pint into your PHP project:

composer require laravel/pint --dev

Once Pint has been installed, the pint binary will be available in your project's vendor/bin directory:

./vendor/bin/pint

Running Pint

When running Pint, it will output a list of files that have been fixed. It is possible to see the changes made in more detail using the -v option:

./vendor/bin/pint -v

In addition, if you would like Pint to simply inspect your code for style errors without actually changing the files, you may use the --test option:

./vendor/bin/pint --test

Configuring Pint

By default, Pint does not require any configuration and will fix code style issues in your code by following the opinionated coding style of Laravel.

However, if you wish to customize the presets, rules, or inspected folders, you may do so by creating a pint.json file in your project's root directory:

{
    "preset": "laravel"
}

In addition, if you wish to use a pint.json from a specific directory, you may use the --config option:

pint --config vendor/my-company/coding-style/pint.json

Presets

Presets define a set of rules that can be used to fix code style issues in your code. By default, Pint uses the laravel preset, which fixes issues by following the opinionated coding style of Laravel.

However, you can use a different preset by passing the --preset option:

pint --preset psr12

If you wish, you may also set the preset in your project's pint.json file:

{
    "preset": "psr12"
}

The currently supported presets are: laravel, psr12, and symfony.

Rules

Rules are style guidelines that Pint will use to fix code style issues in your code. As mentioned above, presets are predefined groups of rules that should be perfect for most PHP projects, so you typically will not need to worry about the individual rules they contain.

However, if you wish, you may enable or disable specific rules in your pint.json file:

{
    "preset": "laravel",
    "rules": {
        "simplified_null_return": true,
        "braces": false,
        "new_with_braces": {
            "anonymous_class": false,
            "named_class": false
        }
    }
}

Pint is built on top of PHP-CS-Fixer. Therefore, you may use any of its rules to fix code style issues in your project: PHP-CS-Fixer Configurator.

Exclude Folders

By default, Pint will inspect all .php files in your project except those in the vendor folder. If you wish to exclude more folders, you may do so by using the exclude configuration option:

{
    "exclude": [
        "my-specific/folder"
    ]
}

Exclude Files

If you wish to exclude file with specified name, you may do so by using the notName configuration option:

{
    "notName": [
        "*-my-file.php"
    ]
}

If you want to exclude file from exact path, you may do so by using the notPath configuration option:

{
    "notPath": [
        "path/to/excluded-file.php"
    ]
}

Contributing

Thank you for considering contributing to Pint! You can read the contribution guide here.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Pint is open-sourced software licensed under the MIT license.

Comments
  • ->setIndent(

    ->setIndent("\t")

    With php-cs-fixer it is possible to define an Indent and Line Ending besides to the rules:

    	->setIndent("\t")
    	->setLineEnding("\n")
    	->setRules([
         //...
    

    Dont blame me for that, but i want to have tabs instead of spaces for Indentation. Vanilla php-cs-fixer is doing that fine, but i dont see a way yet to set Indent and Line Ending in pint.json.

    opened by thyseus 25
  • Add Ability to Set Indentation Level

    Add Ability to Set Indentation Level

    This MUST have the ability to set the indentation level and type if it's to be useful at all.

    I, along with a great many others, don't use 4 spaces to indent. PHP-CS-Fixer has the ability to set the indentation as referenced in #24

    I would suggest implementing this as a rule just as StyleCI does:

    tab-width: (int)
    use-tabs: (bool)
    

    Please add this as I'm not able to use your package until you do.

    Thanks

    opened by secondmanveran 10
  • UNC paths as argument throws error

    UNC paths as argument throws error

    • Pint Version: 0.2.1
    • PHP Version: 8.0.13 (locally installed on Windows)

    Description:

    I'm using WSL2 with Sail. At this point, I'm trying to use PHPStorm to automatically run Pint on the current PHP file, which works correctly when I'm on a local path.

    The issue comes when you open a project from the WSL UNC path (network share). For instance, my project is located at \\WSL$\UBUNTU\home\morfra\code\XXX

    Here is the full error when running the following command:

    cmd.exe /D /C call C:\Users\morfra\AppData\Roaming\Composer\vendor\bin\pint.bat \\wsl$\Ubuntu\home\morfra\code\XXX\app\Http\Middleware\RecordPageViewsToActivityLog.php
    '\\wsl$\Ubuntu\home\morfra\code\XXX'
    
    In Runner.php line 242:
                                                                                                                           
      Cannot write to file "\\WSL$\UBUNTU\home\morfra\code\refonte-intranet\app\Http\Middleware\RecordPageViewsToActivity  
      Log.php" as it is not writable.
    

    That being said, Windows specifically says "UNC paths are not supported in CMD", but I've never had any issues with other scripts running like that.

    Steps To Reproduce:

    Run the pint.bat command from Windows against a UNC path: pint.bat "\\wsl$\Ubuntu\home\morfra\code\XXX\app\Http\Middleware\RecordPageViewsToActivityLog.php"

    needs more info 
    opened by Francismori7 10
  • Target class [router] does not exist

    Target class [router] does not exist

    • Pint Version: 0.1.5
    • PHP Version: 8.0.20

    Description:

    I've tried this in two local Lara projects. Running ./vendor/bin/pint results in an error shown below

    image

    Steps To Reproduce:

    composer require laravel/pint --dev

    then

    ./vendor/bin/pint

    Am I missing something?

    needs more info 
    opened by kb6673 10
  • Pint uses LF line endings in Windows when git core.autocrlf=true

    Pint uses LF line endings in Windows when git core.autocrlf=true

    • Pint Version: 1.2.1
    • PHP Version: 8.1.12

    Description:

    We have developers who use windows in local environment, so we have core.autocrlf=true in git to preserve the CRLF on windows but commit with LF.

    When running pint, it changes all the line endings from CRLF to LF causing hundreds of changed files in the source control, even when the content wasn't changed at all.

    I think the expected behaviors would be to preserve the line endings of the target OS. Or do you recomend us to switch to disable core.autocrlf?

    Steps To Reproduce:

    1. Enable core.autocrlf=true if not already enabled: git config --global core.autocrlf true
    2. Clone any laravel repository and composer install.
    3. Run Laravel pint.

    All the CRLF will be changed to LF causing hundreds of file changes.

    help wanted 
    opened by jhm-ciberman 9
  • What's the advantage over PHP-CS-Fixer

    What's the advantage over PHP-CS-Fixer

    Could there be two sentences about why to use Pint over PHP-CS-Fixer?

    I imagine the output might be more enjoyable and I imagine the installation being easier.

    Is that correct? But likely pint could get old as it comes bundled with a PHP-CS-Fixer, right?

    opened by ibes 9
  • pint.phar and Github Action

    pint.phar and Github Action

    👋 there, congrats for the release @nunomaduro

    Many code quality tools provide a phar version ( PHP-CS-Fixer, PHPMD, PHPStand, etc...) Will pint also provide a .phar file for each release ?

    Also what about having a laravel/pint-github-action, similar to https://github.com/OskarStark/php-cs-fixer-ga

    opened by lucasmichot 8
  • Latest version of pint is not taking care of CS-Fixer brace style

    Latest version of pint is not taking care of CS-Fixer brace style

    • Pint Version: 0.2.4
    • PHP Version: 8.1.8

    Description:

    Previous versions of pint worked with the following configuration, correctly placing braces where they should be (K&R Style)

    {
        "preset": "laravel",
        "rules": {
            "simplified_null_return": true,
            "braces": {
                "position_after_functions_and_oop_constructs": "same"
            },
            "new_with_braces": {
                "anonymous_class": false,
                "named_class": false
            }
        }
    }
    

    But new pint doesn't respect this position_after_functions_and_oop_constructs value and always formats using Allman style, placing brace on the next line (which is same as "position_after_functions_and_oop_constructs": "next"

    Steps To Reproduce:

    Edit your pint.json file in the root directory and add the following content, and then run ./vendor/bin/pint

    {
        "preset": "laravel",
        "rules": {
            "simplified_null_return": true,
            "braces": {
                "position_after_functions_and_oop_constructs": "same"
            },
            "new_with_braces": {
                "anonymous_class": false,
                "named_class": false
            }
        }
    }
    
    opened by hasinhayder 7
  • Shared rules across organisation

    Shared rules across organisation

    Hi,

    I have a GitHub Org that has many Laravel apps. We currently have our own private coding standards repository which applies the same PHP CS Fixer rules across the organisation.

    Is this same thing possible with Pint? We'd love to switch this over to use Pint but we don't really want to have to replicate the ruleset across all the applications, we'd rather this existed in a one centralised place across the whole organisation.

    Cheers.

    needs more info 
    opened by Jamesking56 7
  • Enum cases should not be altered

    Enum cases should not be altered

    • Pint Version: 0.1.5
    • PHP Version: 8.1.1

    Description:

    Enum cases should not be reformatted even regardless of keyword name.

    Enum class: app/Enum/SegmentCastMissingAs.php

    namespace App\Enum;
    
    enum SegmentCastMissingAs: string
    {
        case NULL = 'null';
        case FALSE = 'false';
        case TRUE = 'true';
        case EMPTY_STRING = 'empty_string';
        case ZERO = 'zero';
        case IGNORE = 'ignore';
    }
    

    Pint change this style using Laravel preset:

    -case NULL = 'null';
    -case FALSE = 'false';
    -case TRUE = 'true';
    +case null = 'null';
    +case false = 'false';
    +case true = 'true';
    case EMPTY_STRING = 'empty_string';
    case ZERO = 'zero';
    case IGNORE = 'ignore';
    

    Steps To Reproduce:

    1. create class app/Enum/SegmentCastMissingAs.php
    2. Run /vendor/bin/pint --preset laravel app/Enum/SegmentCastMissingAs.php
    bug 
    opened by Procionegobbo 7
  • Allow to format only specific files

    Allow to format only specific files

    I believe it is an important feature to allow for passing list of files which should be formatted upon run instead of formatting all files. This is usable in case formatting is happening on pre-commit hook (for example in our case we have lint-staged configured which is formatting staged PHP files before commit). I don't see this anywhere as a documented feature and the command input arguments also does not seem to allow for this.

    enhancement 
    opened by zaalbarxx 7
  • [2.x] Removes superfluous annotations

    [2.x] Removes superfluous annotations

    This pull request should ideally target an new version of Laravel Pint, that should ship by default in Laravel 10.x. Please check https://github.com/laravel/laravel/pull/6010 for details about this pull request.

    opened by nunomaduro 1
Releases(v1.3.0)
  • v1.3.0(Dec 20, 2022)

  • v1.2.1(Nov 29, 2022)

  • v1.2.0(Sep 13, 2022)

  • v1.1.3(Sep 6, 2022)

    Changed

    • Ignores build folder by default by @nunomaduro in https://github.com/laravel/pint/pull/108
    • Update to PHP-CS-Fixer v3.11 by @Jubeki in https://github.com/laravel/pint/pull/109
    Source code(tar.gz)
    Source code(zip)
  • v1.1.2(Aug 30, 2022)

  • v1.1.1(Aug 2, 2022)

  • v1.1.0(Jul 26, 2022)

  • v1.0.0(Jul 14, 2022)

  • v0.2.4(Jul 13, 2022)

  • v0.2.3(Jul 4, 2022)

    What's Changed

    • Keep {@inheritdoc} unchanged. by @lucasmichot in https://github.com/laravel/pint/pull/68
    • Also ensure that the double arrow has a single space on each side. by @lucasmichot in https://github.com/laravel/pint/pull/67

    Full Changelog: https://github.com/laravel/pint/compare/v0.2.2...v0.2.3

    Source code(tar.gz)
    Source code(zip)
    pint.phar(11.66 MB)
  • v0.2.2(Jul 1, 2022)

    What's Changed

    • Fix the tag version extraction. by @lucasmichot in https://github.com/laravel/pint/pull/57
    • List syntax rule by @brandonferens in https://github.com/laravel/pint/pull/66

    New Contributors

    • @brandonferens made their first contribution in https://github.com/laravel/pint/pull/66

    Full Changelog: https://github.com/laravel/pint/compare/v0.2.1...v0.2.2

    Source code(tar.gz)
    Source code(zip)
    pint.phar(11.66 MB)
  • v0.2.1(Jun 27, 2022)

    What's Changed

    • Fix actions versions for PHAR deployment job. by @lucasmichot in https://github.com/laravel/pint/pull/49
    • Remove unused imports by @shuvroroy in https://github.com/laravel/pint/pull/48
    • [0.x] Tests against windows by @nunomaduro in https://github.com/laravel/pint/pull/53

    New Contributors

    • @shuvroroy made their first contribution in https://github.com/laravel/pint/pull/48
    • @nunomaduro made their first contribution in https://github.com/laravel/pint/pull/53

    Full Changelog: https://github.com/laravel/pint/compare/v0.2.0...v0.2.1

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Jun 24, 2022)

    What's Changed

    • Fix readme code styling by @Jubeki in https://github.com/laravel/pint/pull/25
    • [0.x] Add Fixers for Laravel specific PHPDocs by @Jubeki in https://github.com/laravel/pint/pull/3
    • Ignore node_modules folder by @aryehraber in https://github.com/laravel/pint/pull/27
    • Adjust description by @calebporzio in https://github.com/laravel/pint/pull/33
    • [0.x] Ignore Laravel actions IDE helper file by @edwinvdpol in https://github.com/laravel/pint/pull/36
    • [0.x] Publish PHAR by @lucasmichot in https://github.com/laravel/pint/pull/34
    • [0.x] Exclude file via pint json by @michalkortas in https://github.com/laravel/pint/pull/40
    • Remove unused $path variable by @michalkortas in https://github.com/laravel/pint/pull/41

    New Contributors

    • @Jubeki made their first contribution in https://github.com/laravel/pint/pull/25
    • @aryehraber made their first contribution in https://github.com/laravel/pint/pull/27
    • @calebporzio made their first contribution in https://github.com/laravel/pint/pull/33
    • @edwinvdpol made their first contribution in https://github.com/laravel/pint/pull/36
    • @lucasmichot made their first contribution in https://github.com/laravel/pint/pull/34
    • @michalkortas made their first contribution in https://github.com/laravel/pint/pull/40

    Full Changelog: https://github.com/laravel/pint/compare/v0.1.6...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.7(Jun 23, 2022)

    What's Changed

    • Fix readme code styling by @Jubeki in https://github.com/laravel/pint/pull/25
    • [0.x] Add Fixers for Laravel specific PHPDocs by @Jubeki in https://github.com/laravel/pint/pull/3
    • Ignore node_modules folder by @aryehraber in https://github.com/laravel/pint/pull/27

    New Contributors

    • @Jubeki made their first contribution in https://github.com/laravel/pint/pull/25
    • @aryehraber made their first contribution in https://github.com/laravel/pint/pull/27

    Full Changelog: https://github.com/laravel/pint/compare/v0.1.6...v0.1.7

    Source code(tar.gz)
    Source code(zip)
  • v0.1.6(Jun 23, 2022)

    What's Changed

    • Doc: Clarifies rules documentation && add options by @julien-boudry in https://github.com/laravel/pint/pull/18

    New Contributors

    • @julien-boudry made their first contribution in https://github.com/laravel/pint/pull/18

    Full Changelog: https://github.com/laravel/pint/compare/v0.1.5...v0.1.6

    Source code(tar.gz)
    Source code(zip)
  • v0.1.5(Jun 23, 2022)

    What's Changed

    • Ignore .phpstorm.meta.php by @fieu in https://github.com/laravel/pint/pull/16

    New Contributors

    • @fieu made their first contribution in https://github.com/laravel/pint/pull/16

    Full Changelog: https://github.com/laravel/pint/compare/v0.1.4...v0.1.5

    Source code(tar.gz)
    Source code(zip)
  • v0.1.4(Jun 23, 2022)

    What's Changed

    • [0.x] Add multiple additional fixers by @claudiodekker in https://github.com/laravel/pint/pull/10

    New Contributors

    • @claudiodekker made their first contribution in https://github.com/laravel/pint/pull/10

    Full Changelog: https://github.com/laravel/pint/compare/v0.1.3...v0.1.4

    Source code(tar.gz)
    Source code(zip)
  • v0.1.3(Jun 22, 2022)

  • v0.1.2(Jun 22, 2022)

    What's Changed

    • Ignore _ide_helper_models.php by @vinkla in https://github.com/laravel/pint/pull/5

    New Contributors

    • @vinkla made their first contribution in https://github.com/laravel/pint/pull/5

    Full Changelog: https://github.com/laravel/pint/compare/v0.1.1...v0.1.2

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Jun 22, 2022)

  • v0.1.0(Jun 22, 2022)

Owner
The Laravel Framework
Laravel is a web ecosystem full of delightful tools that are supercharged for developer happiness and productivity.
The Laravel Framework
php-cs-fixer config for REDAXO

php-cs-fixer config for REDAXO Installation composer require --dev redaxo/php-cs-fixer-config Example .php-cs-fixer.dist.php: <?php $finder = (new P

REDAXO CMS c/o Yakamara Media GmbH & Co. KG 7 Aug 14, 2022
Provides a configuration factory and multiple rule sets for friendsofphp/php-cs-fixer.

php-cs-fixer-config Provides a configuration factory and multiple rule sets for friendsofphp/php-cs-fixer. Installation Run $ composer require --dev e

null 37 Jan 2, 2023
The Easiest way to start using PHP CS Fixer and PHP_CodeSniffer with 0-knowledge

The Easiest Way to Use Any Coding Standard Features Blazing fast Parallel run Use PHP_CodeSniffer || PHP-CS-Fixer - anything you like 2nd run under fe

null 1.1k Jan 6, 2023
Set of rules for PHP_CodeSniffer and PHP-CS-Fixer used by Symplify projects.

20+ Coding Standard checkers for PHP projects with focus on Clean Architecture

null 281 Dec 30, 2022
php-cs-fixer config for Yakamara projects

php-cs-fixer config for Yakamara projects Installation composer require --dev yakamara/php-cs-fixer-config Example .php-cs-fixer.dist.php: <?php $fi

Yakamara Media GmbH & Co. KG 4 Nov 29, 2022
Simple opinionated PHP 8.1 enum helper for Laravel

Laravel Enum Helper This is an extension of the datomatic/enum-helper package based on Laravel Framework. The package consists on a LaravelEnumHelper

Datomatic 17 Jan 1, 2023
An opinionated extension package for Laravel Orchid to extend its table handling capabilities, and some further useful helper methods.

OrchidTables An opinionated extension package for Laravel Orchid to extend its table handling capabilities, and some further useful helper methods. In

null 25 Dec 22, 2022
Simple opinionated framework agnostic PHP 8.1 enum helper

Enum Helper A simple and opinionated collections of PHP 8.1 enum helpers inspired by archtechx/enums and BenSampo/laravel-enum. This package is framew

Datomatic 52 Jan 1, 2023
Opinionated version of Wikimedia composer-merge-plugin to work in pair with Bamarni composer-bin-plugin.

Composer Inheritance Plugin Opinionated version of Wikimedia composer-merge-plugin to work in pair with bamarni/composer-bin-plugin. Usage If you are

Théo FIDRY 25 Dec 2, 2022
A simple twitter-feed-style RSS aggregator written in PHP, Laravel, Inertia.js, Tailwind and Vue.js

RSS A simple, opinionated, RSS feed aggregator. Features The following features are built into the application: Supports RSS and ATOM formats. Regular

Dan Brown 257 Dec 24, 2022
Laravel style FormRequests for Symfony; inspired by adamsafr/form-request-bundle

Somnambulist Form Request Bundle An implementation of form requests from Laravel for Symfony based on the original work by Adam Sapraliev. Requirement

Somnambulist Tech 1 Dec 14, 2021
Create an ip info WebPage with a style.css and an index.php

my-ip-info Create an ip info Page with a style.css and an index.php file. 支持 判断浏览器语言,非中文显示为英文。 curl指令返回ip地址 国家 城市。 在地图上显示位置 前提条件 一个已经注册了域名并在Cloudflare

null 10 May 31, 2023
Silverstripe-tinytidy - Control which styles are available in TinyMCE's style dropdown menu and what elements they can be applied to

TinyTidy for SilverStripe This module mainly serves as an example of how to customise the 'styles' dropdown menu in the TinyMCE editor to control whic

Jono Menz 30 Jul 30, 2020
Provides an object-oriented API to query in-memory collections in a SQL-style.

POQ - PHP Object Query Install composer require alexandre-daubois/poq 1.0.0-beta2 That's it, ready to go! ?? Usage Here is the set of data we're going

Alexandre Daubois 16 Nov 29, 2022
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

⚗️ About Larastan Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural, Nuno Maduro, and Vik

Nuno Maduro 4.4k Jan 4, 2023
Result of our code-along meetup writing PHP 8.1 code

PHP 8.1 Demo Code This code demonstrates various PHP 8.0 and 8.1 features in a realistic, functional (but incomplete) codebase. The code is part of so

azPHP 2 Nov 14, 2021
Dead Code Detector (DCD) for PHP code.

This project is no longer maintained and its repository is only kept for archival purposes. PHP Dead Code Detector (PHPDCD) phpdcd is a Dead Code Dete

Sebastian Bergmann 406 Dec 30, 2022
Free ZIP Code API - Free Access to Worldwide Postal Code Data

About Zipcodebase - Free Zip Code API Zipcodebase is a zip code API that was founded in 2019 to solve common issues with postal code data. As we have

SaaS Industries 2 Nov 26, 2022
Preload your sweet sweet code to opcache with a composer command, making your code faster to run.

Composer Preload Preload your sweet sweet code to opcache with a composer command, making your code run faster. Composer Preload is a composer plugin

Ayesh Karunaratne 197 Dec 6, 2022