Laravel-PHP-CS-Fixer icon indicating copy to clipboard operation
Laravel-PHP-CS-Fixer copied to clipboard

Custom fixer.php completely ignored

Open Krunch opened this issue 4 years ago • 4 comments

I am trying to customize the config/fixer.php that this package generates to tweak some of the rules, but they are completely ignored. No matter what I change in that file, none of the changes get picked up. Also, the fixer.php still uses rule names from the old php-cs-fixer version 2. For example lowercase_constants should now be constant_case.

If I reimplement the rules as-is (no changes) inside a .php-cs-fixer.dist.php file and then run this command php artisan fixer:fix --config=.php-cs-fixer.dist.php then it clearly errors out with this error:

The rules contain unknown fixers: "lowercase_constants" (did you mean "lowercase_cast"?), "phpdoc_inline_tag" (did you mean "phpdoc_line_span"?), "psr4", "trailing_comma_in_multiline_array" (did you mean "trailing_comma_in_multiline"?).

So there seems to be 2 issues currently:

  • The optional config/fixer.php that can be generated through the package is completely ignored.
  • The rules used inside the fixer.php file haven't been updated to use the new php-cs-fixer version 3 names.

Krunch avatar Jul 28 '21 21:07 Krunch

It's not 100% ignored, because when I change the name in fixer.php I see that change. But it fully ignores the rules, always resorting to the default rules of PHP-CS-Fixer: ['@PSR12' => true];.

Inside the Resolver I added after this line:

$config = $config ?: new Config(config('fixer.config_name', 'Laravel'));

The following line:

$config->setRules($options['rules'] ?: config('fixer.rules'));

That loads the rules from fixer.rules but then indeed I run into issues with the naming of several rules as you also mentioned.

Then afterwards I have to rewrite about 10 rules to match the v3 syntax indeed.

@bubba-h57 Is this something you are working on? I'm not using this package very heavily so I'm not sure if submitting a PR without internal knowledge would be the best way of solving this.

stefandoorn avatar Jan 28 '22 14:01 stefandoorn

Can somebody look after this issue, I tried to add some rules but it didn't work as expected.

emyasnikov avatar Apr 13 '22 08:04 emyasnikov

The new config file in the PR looks good, however, it won't solve the main issue.

Adding the line what @stefandoorn provided will solve the main issue.

Inside the Resolver I added after this line:

$config = $config ?: new Config(config('fixer.config_name', 'Laravel'));

The following line:

$config->setRules($options['rules'] ?: config('fixer.rules'));

MrMarci666 avatar Feb 09 '23 08:02 MrMarci666

Thanks!

bubba-h57 avatar Feb 09 '23 13:02 bubba-h57