Skip to content

Commit 892b1a5

Browse files
committed
Fixed annotation parsing in UnusedUsesSniff
1 parent fbac165 commit 892b1a5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

SlevomatCodingStandard/Sniffs/Namespaces/UnusedUsesSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function process(\PHP_CodeSniffer_File $phpcsFile, $openTagPointer)
7474
$nameAsReferencedInFile = $useStatement->getNameAsReferencedInFile();
7575
if (
7676
preg_match('~^@' . preg_quote($nameAsReferencedInFile, '~') . '(?=[^a-z\\d]|$)~i', $tokens[$docCommentPointer]['content'])
77-
|| preg_match('~(?<=^|[^a-z\\d\\\\])' . preg_quote($nameAsReferencedInFile, '~') . '(?=[^a-z\\d\\\\]|$)~i', $tokens[$docCommentPointer]['content'])
77+
|| preg_match('~(?<=^|[^a-z\\d\\\\])' . preg_quote($nameAsReferencedInFile, '~') . '(?=\\\\|[^a-z\\d]|$)~i', $tokens[$docCommentPointer]['content'])
7878
) {
7979
unset($unusedNames[$i]);
8080
}

tests/Sniffs/Namespaces/UnusedUsesSniffTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function testPartialUses()
9393
$this->assertNoSniffError($this->getFileReport(), 20);
9494
$this->assertNoSniffError($this->getFileReport(), 21);
9595
$this->assertNoSniffError($this->getFileReport(), 22);
96+
$this->assertNoSniffError($this->getFileReport(), 23);
9697
}
9798

9899
public function testUsedUseInAnnotationWithDisabledSearchAnnotations()
@@ -101,7 +102,7 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations()
101102
'searchAnnotations' => false,
102103
]);
103104

104-
$this->assertSame(5, $report->getErrorCount());
105+
$this->assertSame(6, $report->getErrorCount());
105106

106107
$this->assertSniffError(
107108
$report,
@@ -127,6 +128,12 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations()
127128
UnusedUsesSniff::CODE_UNUSED_USE,
128129
'Type XX is not used in this file.'
129130
);
131+
$this->assertSniffError(
132+
$report,
133+
10,
134+
UnusedUsesSniff::CODE_UNUSED_USE,
135+
'Type XXX is not used in this file.'
136+
);
130137
}
131138

132139
public function testUsedUseInAnnotationWithEnabledSearchAnnotations()

0 commit comments

Comments
 (0)