Skip to content

Commit 92c0600

Browse files
authored
bug: NoMultilineWhitespaceAroundDoubleArrowFixer - fix for single line comment (#6589)
1 parent 52dc232 commit 92c0600

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixer.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
6767
continue;
6868
}
6969

70-
$this->fixWhitespace($tokens, $index - 1);
70+
if (!$tokens[$index - 2]->isComment() || str_starts_with($tokens[$index - 2]->getContent(), '/*')) {
71+
$this->fixWhitespace($tokens, $index - 1);
72+
}
73+
7174
// do not move anything about if there is a comment following the whitespace
7275
if (!$tokens[$index + 2]->isComment()) {
7376
$this->fixWhitespace($tokens, $index + 1);

tests/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixerTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,39 @@ public function provideFixCases(): array
100100
=>
101101
null;',
102102
],
103+
[
104+
'<?php
105+
$foo = [
106+
1 /* foo */ => $one,
107+
2 => $two
108+
];',
109+
'<?php
110+
$foo = [
111+
1 /* foo */
112+
=>
113+
$one,
114+
2
115+
=>
116+
$two
117+
];',
118+
],
119+
[
120+
'<?php
121+
$foo = [
122+
1 // foo
123+
=> $one,
124+
2 => $two,
125+
];',
126+
'<?php
127+
$foo = [
128+
1 // foo
129+
=>
130+
$one,
131+
2
132+
=>
133+
$two,
134+
];',
135+
],
103136
];
104137
}
105138
}

0 commit comments

Comments
 (0)