Skip to content

Commit 6639d2c

Browse files
committed
trailing_comma_in_multiline following PER-CS2.0 spec
1 parent 35dbd64 commit 6639d2c

File tree

7 files changed

+85
-14
lines changed

7 files changed

+85
-14
lines changed

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function create($ruleSet = null)
4747
{
4848
if (! $ruleSet instanceof RuleSetInterface && ! is_string($ruleSet) && $ruleSet !== null) {
4949
throw new \InvalidArgumentException(
50-
'Ruleset must be of type Relax RuleSetInterface, string or null'
50+
'Ruleset must be of type Relax RuleSetInterface, string or null',
5151
);
5252
}
5353

src/RuleSet/Sets/Relax.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function mainRules(): array
7171
],
7272
],
7373
'space_after_semicolon' => ['remove_in_empty_for_expressions' => true],
74+
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']],
7475
'unary_operator_spaces' => ['only_dec_inc' => true],
7576
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
7677
'phpdoc_align' => ['tags' => ['method', 'param', 'property', 'throws', 'type', 'var']],

tests/Fixtures/Ruleset/relax_actual.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ public function control_structure__no_useless_else()
234234
public function control_structure__switch_case_semicolon_to_colon()
235235
{
236236
switch (true) {
237-
case 1;
237+
case 1:
238238
break;
239-
default;
239+
default:
240240
break;
241241
}
242242
}
@@ -710,6 +710,41 @@ public function array_notation__whitespace_after_comma_in_array()
710710
$sample = [1,2, 3, 4, 5];
711711
}
712712

713+
public function control_structure__trailing_comma_in_multiline()
714+
{
715+
// array
716+
[
717+
1,
718+
2
719+
];
720+
721+
// arguments
722+
foo(
723+
1,
724+
2
725+
);
726+
727+
// parameters
728+
bar(
729+
1,
730+
2
731+
);
732+
733+
// match
734+
match (true) {
735+
1 => '1',
736+
2 => '2'
737+
};
738+
739+
// after_heredoc
740+
[
741+
'foo',
742+
<<<'EOD'
743+
bar
744+
EOD
745+
];
746+
}
747+
713748
public function function_notation__function_declaration()
714749
{
715750
// closure_fn_spacing

tests/Fixtures/Ruleset/relax_expected.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class relax_actual extends Config
2222
public function __invoke(array $type_declaration_spaces) {}
2323

2424
public function __construct(
25-
?RuleSetInterface $ruleSet
25+
?RuleSetInterface $ruleSet,
2626
) {}
2727

2828
/**
@@ -648,7 +648,7 @@ public function whitespace__no_extra_blank_lines_2()
648648

649649
// parenthesis_brace_block
650650
$foo = is_string(
651-
'foo'
651+
'foo',
652652
);
653653

654654
// square_brace_block
@@ -688,6 +688,41 @@ public function array_notation__whitespace_after_comma_in_array()
688688
$sample = [1, 2, 3, 4, 5];
689689
}
690690

691+
public function control_structure__trailing_comma_in_multiline()
692+
{
693+
// array
694+
[
695+
1,
696+
2,
697+
];
698+
699+
// arguments
700+
foo(
701+
1,
702+
2,
703+
);
704+
705+
// parameters
706+
bar(
707+
1,
708+
2,
709+
);
710+
711+
// match
712+
match (true) {
713+
1 => '1',
714+
2 => '2',
715+
};
716+
717+
// after_heredoc
718+
[
719+
'foo',
720+
<<<'EOD'
721+
bar
722+
EOD,
723+
];
724+
}
725+
691726
public function function_notation__function_declaration()
692727
{
693728
// closure_fn_spacing
@@ -709,19 +744,19 @@ function sample($a = 10,
709744
function sample2(
710745
$a = 10,
711746
$b = 20,
712-
$c = 30
747+
$c = 30,
713748
) {}
714749
sample2(
715750
1,
716-
2
751+
2,
717752
);
718753

719754
// 'after_heredoc' => true
720755
sample(
721756
<<<'EOD'
722757
foo
723758
EOD,
724-
'bar'
759+
'bar',
725760
);
726761

727762
// Default value

tests/Integration/IntegrationTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function runFixer(string $name): bool
5353
$config = "tests/Integration/Config/config_{$name}.php";
5454
$result = $application->run(
5555
new StringInput("fix --config={$config} --quiet"),
56-
new \Symfony\Component\Console\Output\BufferedOutput
56+
new \Symfony\Component\Console\Output\BufferedOutput,
5757
);
5858

5959
return $result === 0;

tests/Unit/ConfigTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testSetRuleset(): void
1919
$localRules = ['foo' => 'bar'];
2020
$this->assertSame(
2121
count($ruleset->rules()) + count($localRules),
22-
count($config->setRules($localRules)->getRules())
22+
count($config->setRules($localRules)->getRules()),
2323
);
2424
}
2525

@@ -34,7 +34,7 @@ public function testSetRulesetWithStringInput(): void
3434
$localRules = ['foo' => 'bar'];
3535
$this->assertSame(
3636
count($ruleset->rules()) + count($localRules),
37-
count($config->setRules($localRules)->getRules())
37+
count($config->setRules($localRules)->getRules()),
3838
);
3939
}
4040

@@ -54,8 +54,8 @@ public function testAddLocalRules(): void
5454
count($rules1) + count($rules2),
5555
count(
5656
Config::create(new RuleSetFile)
57-
->setRules($rules2)->getRules()
58-
)
57+
->setRules($rules2)->getRules(),
58+
),
5959
);
6060
}
6161

tests/Unit/ValidRulesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testThatThereIsNoDeprecatedFixerInRuleSet($setName, $ruleName):
4242
$this->assertNotInstanceOf(
4343
\PhpCsFixer\Fixer\DeprecatedFixerInterface::class,
4444
$fixer,
45-
\sprintf('RuleSet "%s" contains deprecated rule "%s".', $setName, $ruleName)
45+
\sprintf('RuleSet "%s" contains deprecated rule "%s".', $setName, $ruleName),
4646
);
4747
}
4848

0 commit comments

Comments
 (0)