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

Preset not being overridden by rules list

guiribmedeiros opened this issue · comments

  • Pint Version: v1.2.0
  • PHP Version: v8.0.24

Description:

  • The laravel preset rules are not being overridden by the rules list;
  • Other presets like symfony are allowing that;
  • I believe that the last input rule should be the one to be used, so rules > preset;

Steps To Reproduce:

  • When the rules are present on rules property is present the preset's rules already, they won't work (or overridden);
  • This is a guess;
{
    "preset": "laravel",
    "rules": {
        "concat_space": {
            "spacing": "one"
        }
    }
}
  • But, when they are not present the preset's rules, they will work (or be overridden);
  • This is a guess;
{
    "preset": "symfony",
    "rules": {
        "concat_space": {
            "spacing": "one"
        }
    }
}

Looking through the code, I've found this logic on the preset method at App\Factories\ConfigurationFactory class:

return (new Config())
            ->setFinder($finder)
            ->setRules(array_merge($localConfiguration->rules(), $rules))
            ->setRiskyAllowed(true)
            ->setUsingCache(true)
            ->registerCustomFixers([
                // Laravel...
                new LaravelPhpdocOrderFixer(),
                new LaravelPhpdocSeparationFixer(),
                new LaravelPhpdocAlignmentFixer(),
            ]);

And the array_merge($localConfiguration->rules(), $rules) logic on the setRules method is keeping the preset's rules over the received rules (through the configuration), so inverting the order of the parameters will fix the issue - tried to push a PR myself but I had no access 😅

I've managed to send a PR: #125 ✌️
I'll take advantage (to avoid creating another issue), and ask if:

  1. There is any reason not to add the @PhpCsFixer ruleset as a preset (can I add it?)
  2. And, why is the no_unused_imports rule present on both symfony and psr12 presets? (can I remove it?)

Looks like you already sent in a PR. Let's see what Nuno says.