Skip to content

Commit

Permalink
trailing_comma_in_multiline follow PER-CS2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Jul 28, 2024
1 parent 35dbd64 commit 2abf4d5
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function create($ruleSet = null)
{
if (! $ruleSet instanceof RuleSetInterface && ! is_string($ruleSet) && $ruleSet !== null) {
throw new \InvalidArgumentException(
'Ruleset must be of type Relax RuleSetInterface, string or null'
'Ruleset must be of type Relax RuleSetInterface, string or null',
);
}

Expand Down
1 change: 1 addition & 0 deletions src/RuleSet/Sets/Relax.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function mainRules(): array
],
],
'space_after_semicolon' => ['remove_in_empty_for_expressions' => true],
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']],
'unary_operator_spaces' => ['only_dec_inc' => true],
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
'phpdoc_align' => ['tags' => ['method', 'param', 'property', 'throws', 'type', 'var']],
Expand Down
39 changes: 37 additions & 2 deletions tests/Fixtures/Ruleset/relax_actual.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ public function control_structure__no_useless_else()
public function control_structure__switch_case_semicolon_to_colon()
{
switch (true) {
case 1;
case 1:
break;
default;
default:
break;
}
}
Expand Down Expand Up @@ -710,6 +710,41 @@ public function array_notation__whitespace_after_comma_in_array()
$sample = [1,2, 3, 4, 5];
}

public function control_structure__trailing_comma_in_multiline()
{
// array
[
1,
2
];

// arguments
foo(
1,
2
);

// parameters
bar(
1,
2
);

// match
match (true) {
1 => '1',
2 => '2'
};

// after_heredoc
[
'foo',
<<<'EOD'
bar
EOD
];
}

public function function_notation__function_declaration()
{
// closure_fn_spacing
Expand Down
45 changes: 40 additions & 5 deletions tests/Fixtures/Ruleset/relax_expected.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class relax_actual extends Config
public function __invoke(array $type_declaration_spaces) {}

public function __construct(
?RuleSetInterface $ruleSet
?RuleSetInterface $ruleSet,
) {}

/**
Expand Down Expand Up @@ -648,7 +648,7 @@ public function whitespace__no_extra_blank_lines_2()

// parenthesis_brace_block
$foo = is_string(
'foo'
'foo',
);

// square_brace_block
Expand Down Expand Up @@ -688,6 +688,41 @@ public function array_notation__whitespace_after_comma_in_array()
$sample = [1, 2, 3, 4, 5];
}

public function control_structure__trailing_comma_in_multiline()
{
// array
[
1,
2,
];

// arguments
foo(
1,
2,
);

// parameters
bar(
1,
2,
);

// match
match (true) {
1 => '1',
2 => '2',
};

// after_heredoc
[
'foo',
<<<'EOD'
bar
EOD,
];
}

public function function_notation__function_declaration()
{
// closure_fn_spacing
Expand All @@ -709,19 +744,19 @@ function sample($a = 10,
function sample2(
$a = 10,
$b = 20,
$c = 30
$c = 30,
) {}
sample2(
1,
2
2,
);

// 'after_heredoc' => true
sample(
<<<'EOD'
foo
EOD,
'bar'
'bar',
);

// Default value
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function runFixer(string $name): bool
$config = "tests/Integration/Config/config_{$name}.php";
$result = $application->run(
new StringInput("fix --config={$config} --quiet"),
new \Symfony\Component\Console\Output\BufferedOutput
new \Symfony\Component\Console\Output\BufferedOutput,
);

return $result === 0;
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testSetRuleset(): void
$localRules = ['foo' => 'bar'];
$this->assertSame(
count($ruleset->rules()) + count($localRules),
count($config->setRules($localRules)->getRules())
count($config->setRules($localRules)->getRules()),
);
}

Expand All @@ -34,7 +34,7 @@ public function testSetRulesetWithStringInput(): void
$localRules = ['foo' => 'bar'];
$this->assertSame(
count($ruleset->rules()) + count($localRules),
count($config->setRules($localRules)->getRules())
count($config->setRules($localRules)->getRules()),
);
}

Expand All @@ -54,8 +54,8 @@ public function testAddLocalRules(): void
count($rules1) + count($rules2),
count(
Config::create(new RuleSetFile)
->setRules($rules2)->getRules()
)
->setRules($rules2)->getRules(),
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ValidRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testThatThereIsNoDeprecatedFixerInRuleSet($setName, $ruleName):
$this->assertNotInstanceOf(
\PhpCsFixer\Fixer\DeprecatedFixerInterface::class,
$fixer,
\sprintf('RuleSet "%s" contains deprecated rule "%s".', $setName, $ruleName)
\sprintf('RuleSet "%s" contains deprecated rule "%s".', $setName, $ruleName),
);
}

Expand Down

0 comments on commit 2abf4d5

Please sign in to comment.