Skip to content

Commit

Permalink
SlevomatCodingStandard.Functions.RequireTrailingCommaInCall: Fixed mi…
Browse files Browse the repository at this point in the history
…ssing report for missing trailing comma after arrow function
  • Loading branch information
kukulich committed Mar 9, 2024
1 parent ea3ff00 commit 8d0f603
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use function in_array;
use const T_CLOSE_PARENTHESIS;
use const T_COMMA;
use const T_FN;
use const T_ISSET;
use const T_OPEN_PARENTHESIS;
use const T_PARENT;
Expand Down Expand Up @@ -83,13 +82,6 @@ public function process(File $phpcsFile, $parenthesisOpenerPointer): void
return;
}

if (
array_key_exists('scope_condition', $tokens[$pointerBeforeParenthesisCloser])
&& $tokens[$tokens[$pointerBeforeParenthesisCloser]['scope_condition']]['code'] === T_FN
) {
return;
}

if ($tokens[$pointerBeforeParenthesisCloser]['code'] === T_COMMA) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testErrors(): void
'enable' => true,
]);

self::assertSame(16, $report->getErrorCount());
self::assertSame(18, $report->getErrorCount());

self::assertSniffError($report, 5, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);
self::assertSniffError($report, 12, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);
Expand All @@ -38,7 +38,9 @@ public function testErrors(): void
self::assertSniffError($report, 83, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);
self::assertSniffError($report, 91, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);
self::assertSniffError($report, 99, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);
self::assertSniffError($report, 106, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);
self::assertSniffError($report, 103, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);
self::assertSniffError($report, 107, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);
self::assertSniffError($report, 114, RequireTrailingCommaInCallSniff::CODE_MISSING_TRAILING_COMMA);

self::assertAllFixedInFile($report);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // lint >= 7.3
<?php // lint >= 7.4

max(
0,
Expand Down Expand Up @@ -99,6 +99,14 @@ function () {
},
);

call(
fn () => 1,
);

call(
fn (array $array) => $array['key'],
);

call(
OPTION_TASK_BUILD_YVES,
OPTION_TASK_BUILD_YVES_SHORT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // lint >= 7.3
<?php // lint >= 7.4

max(
0,
Expand Down Expand Up @@ -99,6 +99,14 @@ function () {
}
);

call(
fn () => 1
);

call(
fn (array $array) => $array['key']
);

call(
OPTION_TASK_BUILD_YVES,
OPTION_TASK_BUILD_YVES_SHORT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ public function __construct(
$foo,
) );

doSomething(
fn () => 1,
);

$array = [];
usort($array, static fn ($a, $b): int
=> (int) $b->getType() <=> (int) $a->getType()
?: $a->getId() <=> $b->getId()
?: $a->getId() <=> $b->getId(),
);

0 comments on commit 8d0f603

Please sign in to comment.