Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}