Skip to content

Commit f2ed951

Browse files
committed
Feat: Reconfigure TrailingCommaInMultilineFixer in accordance with PER2.0 (part of #94)
1 parent 4b8c51a commit f2ed951

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

ecs.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@
149149
use SlevomatCodingStandard\Sniffs\ControlStructures\RequireNullSafeObjectOperatorSniff;
150150
use SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff;
151151
use SlevomatCodingStandard\Sniffs\Functions\RequireTrailingCommaInCallSniff;
152-
use SlevomatCodingStandard\Sniffs\Functions\RequireTrailingCommaInDeclarationSniff;
153152
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
154153
use SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff;
155154
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff;
@@ -234,8 +233,6 @@
234233
SingleLineEmptyBodyFixer::class, // Defined in PER 2.0
235234
// Values separated by a comma on a single line should not have a trailing comma.
236235
NoTrailingCommaInSinglelineFixer::class,
237-
// Multi-line arrays, arguments list and parameters list must have a trailing comma
238-
TrailingCommaInMultilineFixer::class,
239236
// Arrays should be formatted like function/method arguments
240237
TrimArraySpacesFixer::class,
241238
// In array declaration, there MUST be a whitespace after each comma
@@ -422,10 +419,8 @@
422419
// > it may probably be a phpstan rule, more than cs rule - since it needs a class hierarchy to solve this
423420
// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/6235
424421

425-
// Multi-line arguments list in function/method declaration must have a trailing comma
426-
RequireTrailingCommaInDeclarationSniff::class,
427422
// Multi-line arguments list in function/method call must have a trailing comma
428-
RequireTrailingCommaInCallSniff::class,
423+
RequireTrailingCommaInCallSniff::class, // TODO: will be redundant after https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7989 is merged and released
429424

430425
// Use `null-safe` operator `?->` where possible
431426
RequireNullSafeObjectOperatorSniff::class,
@@ -552,6 +547,11 @@
552547
FunctionDeclarationFixer::class,
553548
['closure_fn_spacing' => 'none'], // Defined in PER 2.0
554549
)
550+
// Multi-line arrays, arguments list and parameters list must have a trailing comma
551+
->withConfiguredRule(
552+
TrailingCommaInMultilineFixer::class,
553+
['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']], // Defined in PER 2.0
554+
)
555555
->withSkip([
556556
// We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff)
557557
EmptyStatementSniff::class . '.DetectedCatch' => null,

tests/Integration/Fixtures/Basic.correct.php.inc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,29 @@ class Basic
110110
public function emptyFunction2(
111111
$arg,
112112
): void {} // SingleLineEmptyBodyFixer
113+
114+
// TrailingCommaInMultilineFixer
115+
public function multiline(
116+
$arg1,
117+
$arg2,
118+
$arg3,
119+
): void {
120+
// TrailingCommaInMultilineFixer
121+
$isSet = isset(
122+
$arg1,
123+
$arg2,
124+
$arg3,
125+
);
126+
127+
$sprintf = sprintf(
128+
'%s%s',
129+
'bar',
130+
'baz',
131+
);
132+
133+
foo(
134+
1,
135+
2,
136+
);
137+
}
113138
}

tests/Integration/Fixtures/Basic.wrong.php.inc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,30 @@ class Basic
109109
$arg
110110
): void {
111111
} // SingleLineEmptyBodyFixer
112+
113+
// TrailingCommaInMultilineFixer
114+
public function multiline(
115+
$arg1,
116+
$arg2,
117+
$arg3
118+
): void
119+
{
120+
// TrailingCommaInMultilineFixer
121+
$isSet = isset(
122+
$arg1,
123+
$arg2,
124+
$arg3
125+
);
126+
127+
$sprintf = sprintf(
128+
'%s%s',
129+
'bar',
130+
'baz'
131+
);
132+
133+
foo(
134+
1,
135+
2
136+
);
137+
}
112138
}

0 commit comments

Comments
 (0)