Skip to content

Commit

Permalink
feat: allow to enable @per* rulesets with ruleset builder (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller authored Sep 25, 2023
1 parent 8aedba7 commit a0c9d6d
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 116 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
->setRiskyAllowed(true)
->setRules(
RuleSetFactory::create()
->per(2, true)
->phpCsFixer(true)
->php(8.0, true)
->pedrotroller(true)
Expand Down
6 changes: 5 additions & 1 deletion doc/rule-set-factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ return PhpCsFixer\Config::create()
->setRules(RuleSetFactory::create()
->symfony() // Activate the @Symfony ruleset
->phpCsFixer() // Activate the @PhpCsFixer ruleset
->php(5.6, true) // Activate php 5.6 risky rules
->php(8.2, true) // Activate php 8.2 risky rules
->pedrotroller(true) // Activate my own ruleset (with risky rules)
->enable('ordered_imports') // Add an other rule
->disable('yoda_style') // Disable a rule
Expand All @@ -26,6 +26,10 @@ return PhpCsFixer\Config::create()

## Methods

### `->per([int|float $version = null, [bool $risky = false]])`

Activate the `@PER` (`@PER-CS1.0`, `@PER-CS1.0:risky`, `@PER-CS2.0`, `@PER-CS2.0:risky`, ...) rule.

### `->psr0()`

Activate the `@psr0` rule.
Expand Down
48 changes: 35 additions & 13 deletions spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,46 @@

final class RuleSetFactorySpec extends ObjectBehavior
{
function let()
{
$this->beConstructedThrough('create');
}

function it_is_initializable()
{
$this->shouldHaveType(RuleSetFactory::class);
}

function it_adds_a_per_set()
{
$this->per()->getRules()->shouldReturn(['@PER' => true]);
}

function it_adds_a_per_risky_set()
{
$this->per(risky: true)->getRules()->shouldReturn(['@PER:risky' => true]);
}

function it_adds_a_per1_0_set()
{
$this->per(1)->getRules()->shouldReturn(['@PER-CS1.0' => true]);
}

function it_adds_a_per1_0_risky_set()
{
$this->per(1, true)->getRules()->shouldReturn(['@PER-CS1.0:risky' => true]);
}

function it_adds_a_per2_0_set()
{
$this->per(2)->getRules()->shouldReturn(['@PER-CS2.0' => true]);
}

function it_adds_a_per2_0_risky_set()
{
$this->per(2, true)->getRules()->shouldReturn(['@PER-CS2.0:risky' => true]);
}

function it_adds_a_psr0_set()
{
$this->psr0()->getRules()->shouldReturn(['@psr0' => true]);
Expand Down Expand Up @@ -144,15 +179,6 @@ function it_adds_a_php_version_support()
]);
}

function it_can_also_parse_versions_as_string()
{
$this->php('5.6.2')->getRules()->shouldReturn([
'@PHP54Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'list_syntax' => ['syntax' => 'long'],
]);
}

function it_adds_a_phpunit_version_support()
{
$this->phpUnit(2.0, false)->getRules()->shouldReturn([]);
Expand Down Expand Up @@ -310,8 +336,6 @@ function it_adds_my_own_fixer_set()
$rules[$fixer->getName()] = true;
}

ksort($rules);

$this->pedrotroller(true)->getRules()->shouldReturn($rules);
}

Expand All @@ -327,8 +351,6 @@ function it_adds_my_own_fixer_set_except_privates()
$rules[$fixer->getName()] = true;
}

ksort($rules);

$this->pedrotroller(false)->getRules()->shouldReturn($rules);
}

Expand Down
Loading

0 comments on commit a0c9d6d

Please sign in to comment.