Skip to content

Commit d21ef17

Browse files
authored
fix: UseArrowFunctionsFixer - do not produce two consecutive whitespace tokens (#9151)
1 parent 8e84abc commit d21ef17

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ private function transform(Tokens $tokens, int $index, ?int $useStart, ?int $use
169169
$tokensToInsert[] = new Token([\T_STRING, 'null']);
170170
}
171171

172-
$tokens->clearRange($semicolon, $braceClose);
172+
$tokens->clearRange($semicolon, $braceClose - 1);
173+
$tokens->clearTokenAndMergeSurroundingWhitespace($braceClose);
174+
173175
$tokens->clearRange($braceOpen + 1, $return);
174176
$tokens->overrideRange($braceOpen, $braceOpen, $tokensToInsert);
175177

tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,20 @@ public static function provideFixCases(): iterable
229229
};
230230
PHP,
231231
];
232+
233+
yield [
234+
'<?php
235+
foo(
236+
fn () => 42
237+
'.'
238+
);',
239+
'<?php
240+
foo(
241+
function () {
242+
return 42
243+
;
244+
}
245+
);',
246+
];
232247
}
233248
}

0 commit comments

Comments
 (0)