Skip to content

Commit

Permalink
feat: Add trailing comma in multiline to PER-CS 2.0 (#7916)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelvickersuk committed Apr 4, 2024
1 parent 9782155 commit 0e69940
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/ruleSets/PER-CS2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ Rules

- `method_argument_space <./../rules/function_notation/method_argument_space.rst>`_
- `single_line_empty_body <./../rules/basic/single_line_empty_body.rst>`_
- `trailing_comma_in_multiline <./../rules/control_structure/trailing_comma_in_multiline.rst>`_ with config:

``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``

12 changes: 12 additions & 0 deletions doc/rules/control_structure/trailing_comma_in_multiline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ Rule sets

The rule is part of the following rule sets:

- `@PER <./../../ruleSets/PER.rst>`_ with config:

``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``

- `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:

``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``

- `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:

``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``

- `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ with config:

``['after_heredoc' => true]``
Expand Down
13 changes: 12 additions & 1 deletion src/RuleSet/Sets/PERCS2x0Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getName(): string

public function getRules(): array
{
return [
$rules = [
'@PER-CS1.0' => true,
'array_indentation' => true,
'cast_spaces' => true,
Expand All @@ -42,7 +42,18 @@ public function getRules(): array
],
'method_argument_space' => true,
'single_line_empty_body' => true,
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
'elements' => ['arguments', 'arrays'],
],
];

if (\PHP_VERSION_ID >= 8_00_00) {
$rules['trailing_comma_in_multiline']['elements'][] = 'match';
$rules['trailing_comma_in_multiline']['elements'][] = 'parameters';
}

return $rules;
}

public function getDescription(): string
Expand Down
15 changes: 15 additions & 0 deletions tests/Fixtures/Integration/set/@PER-CS2.0.test-in.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ class Aaa implements
'foo2' => 'bar',
];

$arrayMultilineWithoutComma = [
'foo' => 'bar',
'foo2' => 'bar'
];
$heredocMultilineWithoutComma = [
'foo',
<<<EOD
bar
EOD
];
argumentsMultilineWithoutComma(
1,
2
);

?>
15 changes: 15 additions & 0 deletions tests/Fixtures/Integration/set/@PER-CS2.0.test-out.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,18 @@ class Aaa implements
'foo' => 'bar',
'foo2' => 'bar',
];

$arrayMultilineWithoutComma = [
'foo' => 'bar',
'foo2' => 'bar',
];
$heredocMultilineWithoutComma = [
'foo',
<<<EOD
bar
EOD,
];
argumentsMultilineWithoutComma(
1,
2,
);
6 changes: 6 additions & 0 deletions tests/Fixtures/Integration/set/@PER-CS2.0_php80.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--TEST--
Integration of @PER-CS2.0 [PHP 8.0 version].
--RULESET--
{"@PER-CS2.0": true}
--REQUIREMENTS--
{"php": 80000}
10 changes: 10 additions & 0 deletions tests/Fixtures/Integration/set/@PER-CS2.0_php80.test-in.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

function parametersMultilineWithoutComma(
$x,
$y
) {}
$matchMultilineWithoutComma = match ($a) {
1 => 0,
2 => 1
};
10 changes: 10 additions & 0 deletions tests/Fixtures/Integration/set/@PER-CS2.0_php80.test-out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

function parametersMultilineWithoutComma(
$x,
$y,
) {}
$matchMultilineWithoutComma = match ($a) {
1 => 0,
2 => 1,
};

0 comments on commit 0e69940

Please sign in to comment.