Skip to content

Commit

Permalink
SingleLineCommentStyleFixer - do not fix possible attributes (PHP8)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Nov 30, 2020
1 parent 7a1641e commit 89d95e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Fixer/Comment/SingleLineCommentStyleFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$commentContent = substr($content, 2, -2) ?: '';

if ($this->hashEnabled && '#' === $content[0]) {
if (isset($content[1]) && '[' === $content[1]) {
continue; // This might be attribute on PHP8, do not change
}

$tokens[$index] = new Token([$token->getId(), '//'.substr($content, 1)]);

continue;
Expand Down
10 changes: 9 additions & 1 deletion tests/Fixer/Comment/SingleLineCommentStyleFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ public function provideHashCases()
# test 4
',
],

[
'<?php //',
'<?php #',
],
// Untouched cases
[
'<?php
Expand All @@ -279,6 +282,11 @@ public function provideHashCases()
[
'<?php /* start-end */',
],
[
'<?php function foo(
#[MyAttr([1, 2])] Type $myParam,
) {} // foo',
],
];
}

Expand Down

0 comments on commit 89d95e8

Please sign in to comment.