Skip to content

Commit de2ac26

Browse files
committed
Squiz/ForLoopDeclaration: fix semicolon spacing issues in one loop
Fix the `SpaceBeforeFirst/Second` and `SpaceAfterFirst/Second` errors in one go instead of one whitespace token per loop.
1 parent b593a95 commit de2ac26

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ public function process(File $phpcsFile, $stackPtr)
204204
$errorCode = 'SpacingBefore'.$humanReadableCode;
205205
$fix = $phpcsFile->addFixableError($error, $semicolon, $errorCode, $data);
206206
if ($fix === true) {
207-
$phpcsFile->fixer->replaceToken(($semicolon - 1), '');
207+
$phpcsFile->fixer->beginChangeset();
208+
for ($i = ($semicolon - 1); $i > $prevNonWhiteSpace; $i--) {
209+
$phpcsFile->fixer->replaceToken($i, '');
210+
}
211+
212+
$phpcsFile->fixer->endChangeset();
208213
}
209214
}
210215
}
@@ -236,7 +241,13 @@ public function process(File $phpcsFile, $stackPtr)
236241
$data[] = $spaces;
237242
$fix = $phpcsFile->addFixableError($error, $semicolon, $errorCode, $data);
238243
if ($fix === true) {
244+
$phpcsFile->fixer->beginChangeset();
239245
$phpcsFile->fixer->replaceToken(($semicolon + 1), ' ');
246+
for ($i = ($semicolon + 2); $i < $nextNonWhiteSpace; $i++) {
247+
$phpcsFile->fixer->replaceToken($i, '');
248+
}
249+
250+
$phpcsFile->fixer->endChangeset();
240251
}
241252
}
242253
}//end if

0 commit comments

Comments
 (0)