From 5881633287c0cc0c58330dd522414722daf4e233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Wed, 24 Jun 2020 18:40:12 +0200 Subject: [PATCH] SingleLineAfterImportsFixer - fix for line after import already added using CRLF --- src/Fixer/Import/SingleLineAfterImportsFixer.php | 3 +++ tests/Fixer/Import/SingleLineAfterImportsFixerTest.php | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/Fixer/Import/SingleLineAfterImportsFixer.php b/src/Fixer/Import/SingleLineAfterImportsFixer.php index 739ab7ed0b2..b32fca3e5eb 100644 --- a/src/Fixer/Import/SingleLineAfterImportsFixer.php +++ b/src/Fixer/Import/SingleLineAfterImportsFixer.php @@ -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) { diff --git a/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php b/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php index c8cc8d68d70..fe9ed3f7086 100644 --- a/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php +++ b/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php @@ -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", '