laravel / pint

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

Home Page:https://laravel.com/docs/pint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

binary_operator_spaces issue with laravel/pint v1.3.0

Gavrisimo opened this issue · comments

  • Pint Version: 1.3.0
  • PHP Version: 8.0.26

Description:

I noticed that our CI action which runs pint started reporting 100s of files need updating. First I looked into friendsofphp/php-cs-fixer and found this issue: PHP-CS-Fixer/PHP-CS-Fixer#6716

But I couldn't reproduce it simply by downgrading cs-fixer, I tried 3.13.0, 3.12.0, 3.11.0 but that didn't help.

Then I noticed that there was a 1.3.0 release of laravel/pint and I checked out that single commit and nothing really pointed towards this binary_operator_spaces issue I am seeing. I tried downgrading laravel/pint just for fun of it but sure enough, when I downgraded it to 1.2.1 it started to work same as before. I then upgraded it back to 1.3.0 and boom - issues again.

The friendsofphp/php-cs-fixer is 3.13.1 in both of my tests, which is the latest version, the only change I am making is the version change of laravel/pint.

Steps To Reproduce:

Forcing pint to be 1.3.0:

composer require laravel/pint 1.3.0 --dev
./composer.json has been updated
Running composer update laravel/pint
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
  - Upgrading laravel/pint (v1.2.1 => v1.3.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading laravel/pint (v1.3.0)
  - Upgrading laravel/pint (v1.2.1 => v1.3.0): Extracting archive
Package spatie/data-transfer-object is abandoned, you should avoid using it. Use spatie/laravel-data instead.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files

...

No security vulnerability advisories found

Running pint:

./vendor/bin/pint --test

  ................................................................................................................................................................................................................
  ................................................................................................................................................................................................................
  ..............................................⨯.⨯.....⨯...⨯...⨯.................⨯.......⨯........⨯................................................................⨯.............................................
  ............⨯..........⨯.........................................................................................................................................................⨯..........................⨯...
  ................................⨯.....⨯⨯⨯⨯⨯⨯⨯........⨯.......................................⨯.⨯⨯.⨯⨯.⨯..⨯.⨯⨯⨯⨯⨯..⨯⨯⨯⨯⨯.⨯⨯⨯⨯⨯.⨯⨯⨯⨯⨯⨯.⨯⨯⨯⨯⨯...⨯⨯......⨯..⨯⨯⨯..⨯..⨯⨯....⨯.................⨯.⨯..⨯⨯⨯..⨯.⨯.⨯⨯.⨯⨯⨯⨯..⨯.
  ⨯⨯..⨯⨯⨯⨯⨯⨯.⨯.⨯.⨯.⨯⨯...⨯⨯⨯.....⨯.⨯..⨯.⨯⨯⨯⨯.......................⨯.........⨯.......⨯...⨯.....⨯⨯..........⨯.........................⨯........⨯......⨯........................⨯.⨯...............⨯...............⨯..
  ........⨯.⨯..⨯....⨯..⨯..........⨯......................⨯⨯...................................................................................⨯.............⨯.....................................................
  .......⨯.........⨯..............................................⨯.⨯.....⨯....⨯...............⨯.........................⨯....⨯⨯....⨯...................⨯..........⨯...⨯.......................................⨯.⨯
  ⨯⨯⨯⨯⨯⨯⨯⨯.⨯⨯⨯⨯⨯⨯.⨯⨯⨯.⨯⨯⨯⨯⨯⨯.⨯⨯................⨯.....⨯...........................................................................

  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── PSR 12  
    FAIL   .......................................................................................................................................................................... 1791 files, 169 style issues

Forcing pint to be 1.2.1:

composer require laravel/pint 1.2.1 --dev
./composer.json has been updated
Running composer update laravel/pint
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
  - Downgrading laravel/pint (v1.3.0 => v1.2.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading laravel/pint (v1.2.1)
  - Downgrading laravel/pint (v1.3.0 => v1.2.1): Extracting archive
Package spatie/data-transfer-object is abandoned, you should avoid using it. Use spatie/laravel-data instead.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files

...

No security vulnerability advisories found

Running pint again:

./vendor/bin/pint --test

  ................................................................................................................................................................................................................
  ................................................................................................................................................................................................................
  ................................................................................................................................................................................................................
  ................................................................................................................................................................................................................
  ................................................................................................................................................................................................................
  ................................................................................................................................................................................................................
  ................................................................................................................................................................................................................
  ................................................................................................................................................................................................................
  ...............................................................................................................................

  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── PSR 12  
    PASS   ............................................................................................................................................................................................ 1791 files

Showing that friendsofphp/php-cs-fixer is at 3.13.1:

composer show friendsofphp/php-cs-fixer
name     : friendsofphp/php-cs-fixer
descrip. : A tool to automatically fix PHP code style
keywords : 
versions : * v3.13.1
...

Here is an example file config/passport.php with the changes:

CleanShot 2022-12-21 at 10 20 09@2x

For now I will just force laravel/pint to stay at version 1.2.1

@Gavrisimo Can you share your "pint.json" if any?

@nunomaduro absolutely, here it is:

{
    "preset": "psr12",
    "exclude": [
        ".github",
        "bootstrap",
        "public",
        "resources",
        "storage",
        "vendor",
        "node_modules"
    ],
    "rules": {
        "single_trait_insert_per_statement": false,
        "visibility_required": false,
        "blank_line_between_import_groups": false,
        "ordered_class_elements": false,
        "binary_operator_spaces": {
            "operators": {
                "=>": "align_single_space_minimal"
            }
        },
        "array_syntax": {
            "syntax": "short"
        },
        "multiline_whitespace_before_semicolons": {
            "strategy": "no_multi_line"
        },
        "echo_tag_syntax": {
            "format": "long"
        },
        "no_unused_imports": true,
        "trailing_comma_in_multiline": {
            "elements": [
                "arrays"
            ]
        },
        "phpdoc_indent": true,
        "phpdoc_align": true,
        "phpdoc_order": true,
        "phpdoc_separation": true,
        "phpdoc_scalar": true,
        "phpdoc_trim": true,
        "return_type_declaration": true,
        "single_quote": true,
        "ordered_imports": {
            "sort_algorithm": "alpha"
        }
    }
}

Yeah - as you specified, the issue is related to PHP-CS-Fixer/PHP-CS-Fixer#6716. As workaround, you can remove the option from your pint.json or stick for now, to the previous version of Pint.

@nunomaduro what's weird to me is that everything works with the latest version of cs-fixer and that I had to downgrade pint to get this to work... ¯\_(ツ)_/¯