Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a custom rule set for php-cs-fixer?

How to create custom ruleset to be run by fix command with option --rules=@custom?

Like @PSR1, @PSR2, @Symfony, @PHP56Migration, @PHP70Migration, @PHP71Migration are made.

Php-cs-fixer version: 2.2.3

Only by inserting into vendor code -vendor/friendsofphp/php-cs-fixer/src/RuleSet.php:

private $setDefinitions = array(
        '@custom' => [
        'some_custom_fixer` => true,
        ]
)

Works as I expect, but RuleSet is final class. Is there a way to override or extend the setDefinitions when using custom config .php_cs?

like image 279
J. Doe Avatar asked Jun 23 '17 07:06

J. Doe


2 Answers

Currently, there is no way to register custom ruleset how you register custom fixer. Although that, we were already thinking that it would be nice to introduce it, yet it is not a prio on our todo list. Feel free to write proposal how it shall be handled, and PR after initial discussion. https://github.com/FriendsOfPHP/PHP-CS-Fixer/

like image 63
keradus Avatar answered Oct 19 '22 18:10

keradus


In the meanwhile, create your own configuration instead and share it across projects.

For example:

  • refinery29/php-cs-fixer-config
  • ergebnis/php-cs-fixer-config
like image 27
localheinz Avatar answered Oct 19 '22 17:10

localheinz