Skip to content

Commit

Permalink
fix: MethodArgumentSpaceFixer inject new line after trailing space on…
Browse files Browse the repository at this point in the history
… current line
  • Loading branch information
SpacePossum committed Sep 26, 2023
1 parent 573ab70 commit 4c8d48a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ private function fixNewline(Tokens $tokens, int $index, string $indentation, boo
if ($tokens[$index + 2]->isComment()) {
$nextMeaningfulTokenIndex = $tokens->getNextMeaningfulToken($index + 2);
if (!$this->isNewline($tokens[$nextMeaningfulTokenIndex - 1])) {
if ($tokens[$nextMeaningfulTokenIndex - 1]->isWhitespace()) {
$tokens->clearAt($nextMeaningfulTokenIndex - 1);
}

$tokens->ensureWhitespaceAtIndex($nextMeaningfulTokenIndex, 0, $this->whitespacesConfig->getLineEnding().$indentation);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,20 @@ function foo(
$f);# comment4
',
];

yield [
'<?php
foo(
/* bar */
"baz"
);
',
'<?php
foo(
/* bar */ "baz"
);
',
];
}

/**
Expand Down

0 comments on commit 4c8d48a

Please sign in to comment.