laravel / pint

Laravel Pint is an opinionated PHP code style fixer for minimalists.
https://laravel.com/docs/pint
MIT License
2.75k stars 138 forks source link

[1.x] Replace custom phpdoc_align rule with php-cs-fixer option #242

Closed Jubeki closed 7 months ago

Jubeki commented 7 months ago
github-actions[bot] commented 7 months ago

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

eusonlito commented 7 months ago

php-cs-fixer phpdoc_align docs: https://cs.symfony.com/doc/rules/phpdoc/phpdoc_align.html

Jubeki commented 7 months ago

@eusonlito What exactly is your comment about?

eusonlito commented 7 months ago

@Jubeki after updating to the latest release I got an error The rules contain unknown fixers: "Laravel/laravel_phpdoc_aligment".

I had this rule as false so I leave the link to the php-cs-fixer rule as reference if anyone wants information on how to customize it.

phh commented 7 months ago

Well, since updating from 1.13.8 to 1.13.9 I've been having issues with pint no being able to fix my issues.

sail pint app/Models/ -v

.....!.............!..!.........!.......

  ! app/Models/A.php                                                                      syntax error, unexpected token ">"
  ! app/Models/B.php                                                                       syntax error, unexpected token ">"
  ! app/Models/C.php                                                                      syntax error, unexpected token ">"
  ! app/Models/D.php                                                 syntax error, unexpected token "=", expecting "=>"

An error from one of the files are:

 ! app/Models/A.php                                                                      syntax error, unexpected token ">"
     85▕             get: function () {
     86▕                 $disk = Storage::disk('images');
     87▕
     88▕                 return [
  ➜  89▕                     'logo'     => isset($this->images['logo']) ? $disk->url($this->images['logo']) : null,

Only change I did to my files was to remove the "Laravel/laravel_phpdoc_alignment": false rule from pint.json, since after this PR it no longer exists.

Other who has issues with this?

Jubeki commented 7 months ago

@phh probably something with another php-cs-fixer rule. I will send another PR, which bumps the php-cs-fixer version to the patch which was released.

Jubeki commented 7 months ago

@phh can you send a code snippet, so that I can confirm if the new patch version would work?

phh commented 7 months ago

@Jubeki Could reproduce on a fresh laravel app with:

pint.json:

{
  "preset": "laravel",
  "rules": {
    "binary_operator_spaces": {
      "default": "align_single_space_minimal"
    }
  }
}

app/Models/TestModel.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class TestModel extends Model
{
    public function imageUrls()
    {
        $disk = Storage::disk('test');

        return [
            'a' => $disk->url($this->images['a']),
            'aa' => $disk->url($this->images['aa']),
        ];
    }

    protected function someMethod($items = []): void
    {
        if (count($items) > 0) {}
    }
}