From 3f0bf3b3bac9926da91308ad0c51aacb10d2d3e6 Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Thu, 20 Mar 2025 16:28:10 +0000 Subject: [PATCH] Add an option to disable prettier-handled rules --- src/Config.php | 24 +++++++++++++++++------- tests/ConfigTest.php | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Config.php b/src/Config.php index ec78d5c..a67de9e 100644 --- a/src/Config.php +++ b/src/Config.php @@ -11,7 +11,9 @@ final class Config extends CsFixerConfig private $extraRules; - public function __construct($useRisky = true, array $extraRules = []) + private bool $disablePrettierRules; + + public function __construct($useRisky = true, array $extraRules = [], bool $disablePrettierRules = false) { parent::__construct('Mapado'); @@ -20,6 +22,7 @@ public function __construct($useRisky = true, array $extraRules = []) $this->setRiskyAllowed(true); $this->useRisky = $useRisky; $this->extraRules = $extraRules; + $this->disablePrettierRules = $disablePrettierRules; } public function getRules(): array @@ -89,7 +92,6 @@ public function getRules(): array // https://cs.symfony.com/doc/rules/return_notation/simplified_null_return.html 'simplified_null_return' => true, - // List (array destructuring) assignment should be declared using the configured syntax. // https://cs.symfony.com/doc/rules/list_notation/list_syntax.html 'list_syntax' => ['syntax' => 'short'], @@ -134,13 +136,9 @@ public function getRules(): array // Comparing to Symfony let prettier handle `as` like it wants // https://cs.symfony.com/doc/rules/language_construct/single_space_around_construct.html 'single_space_around_construct' => [ - 'constructs_preceded_by_a_single_space' => ['use_lambda'] - + 'constructs_preceded_by_a_single_space' => ['use_lambda'], ], - // until prettier fixes https://github.com/prettier/plugin-php/issues/2400 - 'single_line_empty_body' => false, - // === Doctrine === // Rules covering Doctrine annotations with configuration based on examples found in Doctrine Annotation documentation and Symfony documentation. @@ -170,6 +168,18 @@ public function getRules(): array ]; } + if ($this->disablePrettierRules) { + $out = array_merge($out, [ + 'class_definition' => false, + 'statement_indentation' => false, + 'no_unneeded_control_parentheses' => false, + 'no_multiline_whitespace_around_double_arrow' => false, + 'types_spaces' => false, // not that clear in PER + 'single_space_around_construct' => false, + 'method_argument_space' => false, + ]); + } + // do not use array_merge or `+` to put new key at the end foreach ($this->extraRules as $key => $value) { $out[$key] = $value; diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 1e8ecf8..5c8e2d4 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -48,6 +48,6 @@ public function testExtraRulesPosition() $symfonyPosition = array_search('@Symfony', array_keys($rules)); $this->assertEquals(0, $symfonyPosition); $visiPosition = array_search('visibility_required', array_keys($rules)); - $this->assertEquals(32, $visiPosition); + $this->assertEquals(31, $visiPosition); } }