stechstudio / Laravel-PHP-CS-Fixer

Artisan Command for FriendsOfPHP/PHP-CS_Fixer
MIT License
147 stars 28 forks source link

Custom fixer.php completely ignored #32

Open Krunch opened 3 years ago

Krunch commented 3 years ago

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:

stefandoorn commented 2 years ago

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.

emyasnikov commented 2 years ago

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

MrMarci666 commented 1 year ago

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'));
bubba-h57 commented 1 year ago

Thanks!