From 87a6c1ce65471307939d9be1b7ae8ed150f6f94c Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Wed, 23 Aug 2023 17:58:46 +0200 Subject: [PATCH] fix: remove risky own fixers if non-risky is asked --- .../CS/Fixer/RuleSetFactorySpec.php | 19 ++++++++++++++++++- src/PedroTroller/CS/Fixer/RuleSetFactory.php | 5 +++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php b/spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php index 2324e0d..7dfedb2 100644 --- a/spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php +++ b/spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php @@ -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() diff --git a/src/PedroTroller/CS/Fixer/RuleSetFactory.php b/src/PedroTroller/CS/Fixer/RuleSetFactory.php index 5631a1f..66b5f52 100644 --- a/src/PedroTroller/CS/Fixer/RuleSetFactory.php +++ b/src/PedroTroller/CS/Fixer/RuleSetFactory.php @@ -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); @@ -183,6 +184,10 @@ public function pedrotroller($risky = false) continue; } + if (false === $risky && $fixer->isRisky()) { + continue; + } + $rules[$fixer->getName()] = true; }