Skip to content

Commit

Permalink
fix: remove risky own fixers if non-risky is asked
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Aug 23, 2023
1 parent 206ffee commit 87a6c1c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 18 additions & 1 deletion spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,24 @@ function it_adds_my_own_fixer_set()

ksort($rules);

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

function it_adds_my_own_fixer_set_except_privates()
{
$rules = [];

foreach (new Fixers() as $fixer) {
if ($fixer->isDeprecated() || $fixer->isRisky()) {
continue;
}

$rules[$fixer->getName()] = true;
}

ksort($rules);

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

function it_enables_a_rule()
Expand Down
5 changes: 5 additions & 0 deletions src/PedroTroller/CS/Fixer/RuleSetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function php($version, $risky = false)
switch (true) {
case $version >= 7.1:
$config = array_merge(['list_syntax' => ['syntax' => 'short']], $config);

// no break
case $version >= 5.4:
$config = array_merge(['array_syntax' => ['syntax' => 'short']], $config);
Expand Down Expand Up @@ -183,6 +184,10 @@ public function pedrotroller($risky = false)
continue;
}

if (false === $risky && $fixer->isRisky()) {
continue;
}

$rules[$fixer->getName()] = true;
}

Expand Down

0 comments on commit 87a6c1c

Please sign in to comment.