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

Unable to modify no_extra_blank_lines tokens via pint.json

lada opened this issue · comments

commented
  • Pint Version: 1.2.0
  • PHP Version: 8.1.9

Description:

I was trying to overwrite the laravel preset so that extra blank lines after class methods don't get removed. But overwriting the no_extra_blank_lines rule in pint.json does not have any effect (while overwriting other rules works as expected).

Steps To Reproduce:

Create pint.json file in project root with the following content:

{
    "preset": "laravel",
    "rules": {
        "no_extra_blank_lines": {
            "tokens": [
                "throw",
                "use"
            ]
        }
    }
}

Extra blank lines after class methods are still removed.

commented

Here are more detailed steps to reproduce the issue:

  1. Create a new laravel project
composer create-project laravel/laravel pint-blank-lines-issue
  1. Create pint.json file in the project root with the following content:
{
  "preset": "laravel",
  "rules": {
      "no_extra_blank_lines": {
          "tokens": [
              "throw",
              "use"
          ]
      }
  }
}
  1. Open app/Providers/AppServiceProvider.php and insert one more blank line after the register method
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
  /**
   * Register any application services.
   *
   * @return void
   */
  public function register()
  {
      //
  }


  /**
   * Bootstrap any application services.
   *
   * @return void
   */
  public function boot()
  {
      //
  }
}
  1. Run pint
./vendor/bin/pint

The extra blank line will be removed. But it should not be, because the pint.json file specifies only "throws" and "use" tokens.

commented

Sorry guys, I have just seen that the single blank line after class method is enforces by the class_attributes_separation rule. Modifying the pint.json as follows solves the issue:

{
    "preset": "laravel",
    "rules": {
        "class_attributes_separation": false,
        "no_extra_blank_lines": {
            "tokens": [
                "throw",
                "use"
            ]
        }
    }
}