(ref. #3077)
What about implementing a way to specify fixer sets that depend on the path of the file currently being fixed?
For instance, we could have the following .php_cs configuration file:
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\PathAwareRules;
return Config::create()
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
)
->setRules([
'@PSR2' => true,
'psr4' => true,
])
->addPathAwareRules(
PathAwareRules::create()
->setRelativeTo(__DIR__)
->setInheritRules(true)
->setRegularExpressions([
'/^tests\//',
])
->setRules([
'psr4' => false,
])
)
->addPathAwareRules(
PathAwareRules::create()
->setRelativeTo(__DIR__)
->setInheritRules(false)
->setRegularExpressions([
'/^bin\//',
'/^dev-bin\//',
])
->setRules([
'@PSR1' => true,
])
)
;
This file:
- defines a default set of rules (
Config::setRules())
- for paths relative to
__DIR__ (PathAwareRules::setRelativeTo(__DIR__)) that match /^tests\// (PathAwareRules::setRegularExpressions()) we use the default set of rules (PathAwareRules::setInheritRules(true)) but disabling the psr4 fixer.
- for paths relative to
__DIR__ (PathAwareRules::setRelativeTo(__DIR__)) that match /^bin\//or /^dev-bin\// (PathAwareRules::setRegularExpressions()) we use only (PathAwareRules::setInheritRules(false)) the @PSR1 preset.
(ref. #3077)
What about implementing a way to specify fixer sets that depend on the path of the file currently being fixed?
For instance, we could have the following
.php_csconfiguration file:This file:
Config::setRules())__DIR__(PathAwareRules::setRelativeTo(__DIR__)) that match/^tests\//(PathAwareRules::setRegularExpressions()) we use the default set of rules (PathAwareRules::setInheritRules(true)) but disabling thepsr4fixer.__DIR__(PathAwareRules::setRelativeTo(__DIR__)) that match/^bin\//or/^dev-bin\//(PathAwareRules::setRegularExpressions()) we use only (PathAwareRules::setInheritRules(false)) the@PSR1preset.