Skip to content

Commit

Permalink
Feat: Reconfigure TrailingCommaInMultilineFixer in accordance with PE…
Browse files Browse the repository at this point in the history
…R2.0 (part of #94)
  • Loading branch information
OndraM committed May 7, 2024
1 parent 652527e commit 9c59246
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@
SingleLineEmptyBodyFixer::class, // Defined in PER 2.0
// Values separated by a comma on a single line should not have a trailing comma.
NoTrailingCommaInSinglelineFixer::class,
// Multi-line arrays, arguments list and parameters list must have a trailing comma
TrailingCommaInMultilineFixer::class,
// Arrays should be formatted like function/method arguments
TrimArraySpacesFixer::class,
// In array declaration, there MUST be a whitespace after each comma
Expand Down Expand Up @@ -420,10 +418,8 @@
ParameterTypeHintSniff::class,
ReturnTypeHintSniff::class,

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

// Use `null-safe` operator `?->` where possible
RequireNullSafeObjectOperatorSniff::class,
Expand Down Expand Up @@ -550,6 +546,11 @@
FunctionDeclarationFixer::class,
['closure_fn_spacing' => 'none'], // Defined in PER 2.0
)
// Multi-line arrays, arguments list and parameters list must have a trailing comma
->withConfiguredRule(
TrailingCommaInMultilineFixer::class,
['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']], // Defined in PER 2.0
)
->withSkip([
// We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff)
EmptyStatementSniff::class . '.DetectedCatch' => null,
Expand Down
25 changes: 25 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,29 @@ class Basic
public function emptyFunction2(
$arg,
): void {} // SingleLineEmptyBodyFixer

// TrailingCommaInMultilineFixer
public function multiline(
$arg1,
$arg2,
$arg3,
): void {
// TrailingCommaInMultilineFixer
$isSet = isset(
$arg1,
$arg2,
$arg3,
);

$sprintf = sprintf(
'%s%s',
'bar',
'baz',
);

foo(
1,
2,
);
}
}
26 changes: 26 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,30 @@ class Basic
$arg
): void {
} // SingleLineEmptyBodyFixer

// TrailingCommaInMultilineFixer
public function multiline(
$arg1,
$arg2,
$arg3
): void
{
// TrailingCommaInMultilineFixer
$isSet = isset(
$arg1,
$arg2,
$arg3
);

$sprintf = sprintf(
'%s%s',
'bar',
'baz'
);

foo(
1,
2
);
}
}

0 comments on commit 9c59246

Please sign in to comment.