Skip to content

Commit

Permalink
SingleLineAfterImportsFixer - fix for line after import already added…
Browse files Browse the repository at this point in the history
… using CRLF
  • Loading branch information
kubawerlos authored and keradus committed Jun 27, 2020
1 parent c0d6a34 commit 5881633
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Fixer/Import/SingleLineAfterImportsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)

if ($tokens[$insertIndex]->isWhitespace()) {
$nextToken = $tokens[$insertIndex];
if (2 === substr_count($nextToken->getContent(), "\n")) {
continue;
}
$nextMeaningfulAfterUseIndex = $tokens->getNextMeaningfulToken($insertIndex);
if (null !== $nextMeaningfulAfterUseIndex && $tokens[$nextMeaningfulAfterUseIndex]->isGivenKind(T_USE)) {
if (substr_count($nextToken->getContent(), "\n") < 2) {
Expand Down
7 changes: 7 additions & 0 deletions tests/Fixer/Import/SingleLineAfterImportsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ class Test {}
use some\a\ClassA; use function some\a\fn_a; use const some\c;
',
],
[
str_replace("\n", "\r\n", '<?php
use Foo;
class Bar {}
'),
],
];
}

Expand Down

0 comments on commit 5881633

Please sign in to comment.