Skip to content

Commit

Permalink
DuplicateSpacesSniff: Improved detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Mar 28, 2020
1 parent faf6fd2 commit c4bf9ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use function str_replace;
use function strlen;
use const PREG_OFFSET_CAPTURE;
use const T_DOC_COMMENT_CLOSE_TAG;
use const T_DOC_COMMENT_OPEN_TAG;
use const T_DOC_COMMENT_STAR;
use const T_DOC_COMMENT_STRING;
Expand Down Expand Up @@ -81,7 +82,11 @@ public function process(File $phpcsFile, $whitespacePointer): void

if ($this->ignoreSpacesInAnnotation) {
$pointerBefore = TokenHelper::findPrevious($phpcsFile, [T_DOC_COMMENT_OPEN_TAG, T_DOC_COMMENT_TAG], $whitespacePointer - 1);
if ($pointerBefore !== null && $tokens[$pointerBefore]['code'] === T_DOC_COMMENT_TAG) {
if (
$pointerBefore !== null
&& $tokens[$pointerBefore]['code'] === T_DOC_COMMENT_TAG
&& $tokens[$whitespacePointer + 1]['code'] !== T_DOC_COMMENT_CLOSE_TAG
) {
return;
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Sniffs/Whitespaces/DuplicateSpacesSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,17 @@ public function testIgnoreSpacesInAnnotationNoErrors(): void
self::assertNoSniffErrorInFile($report);
}

public function testIgnoreSpacesInAnnotationErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/duplicateSpacesIgnoreSpacesInAnnotationErrors.php', [
'ignoreSpacesInAnnotation' => true,
]);

self::assertSame(1, $report->getErrorCount());

self::assertSniffError($report, 3, DuplicateSpacesSniff::CODE_DUPLICATE_SPACES, 'Duplicate spaces at position 21.');

self::assertAllFixedInFile($report);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

/** @param string $a */
function doSomething($a) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

/** @param string $a */
function doSomething($a) {

}

0 comments on commit c4bf9ca

Please sign in to comment.