Skip to content

Commit

Permalink
minor #5302 SingleLineCommentStyleFixer - do not fix possible attribu…
Browse files Browse the repository at this point in the history
…tes (PHP8) (SpacePossum)

This PR was merged into the 2.16 branch.

Discussion
----------

SingleLineCommentStyleFixer - do not fix possible attributes (PHP8)

closes #5144

Commits
-------

89d95e8 SingleLineCommentStyleFixer - do not fix possible attributes (PHP8)
  • Loading branch information
SpacePossum committed Dec 4, 2020
2 parents 694dfb7 + 89d95e8 commit 91b146a
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 91b146a

Please sign in to comment.