Skip to content

Commit 22db13c

Browse files
committed
Merge branch 'feature/various-comment-sniffs-fixer-conflicts' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 9f56110 + a77d1ca commit 22db13c

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
12081208
<file baseinstalldir="PHP/CodeSniffer" name="EmptyCatchCommentUnitTest.php" role="test" />
12091209
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.inc" role="test" />
12101210
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.inc" role="test" />
1211+
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.2.inc" role="test" />
12111212
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.js" role="test" />
12121213
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js" role="test" />
12131214
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.php" role="test" />

src/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ public function register()
4949
*/
5050
public function process(File $phpcsFile, $stackPtr)
5151
{
52-
$tokens = $phpcsFile->getTokens();
52+
$tokens = $phpcsFile->getTokens();
53+
54+
if (isset($tokens[$stackPtr]['comment_closer']) === false
55+
|| ($tokens[$tokens[$stackPtr]['comment_closer']]['content'] === ''
56+
&& $tokens[$stackPtr]['comment_closer'] === ($phpcsFile->numTokens - 1))
57+
) {
58+
// Don't process an unfinished comment during live coding.
59+
return;
60+
}
61+
5362
$commentStart = $stackPtr;
5463
$commentEnd = $tokens[$stackPtr]['comment_closer'];
5564

src/Standards/Generic/Tests/Commenting/DocCommentUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,5 @@
192192
*/
193193

194194
/**doc comment */
195+
196+
/** No docblock close tag. Must be last test without new line.

src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function process(File $phpcsFile, $stackPtr)
7676
T_VAR => true,
7777
];
7878

79-
if (isset($ignore[$tokens[$nextToken]['code']]) === false) {
79+
if ($nextToken === false || isset($ignore[$tokens[$nextToken]['code']]) === false) {
8080
// Could be a file comment.
8181
$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
8282
if ($tokens[$prevToken]['code'] !== T_OPEN_TAG) {
@@ -96,6 +96,11 @@ public function process(File $phpcsFile, $stackPtr)
9696
}
9797

9898
if ($tokens[$i]['code'] === T_DOC_COMMENT_CLOSE_TAG) {
99+
if (trim($tokens[$i]['content']) === '') {
100+
// Don't process an unfinished docblock close tag during live coding.
101+
continue;
102+
}
103+
99104
// Can't process the close tag if it is not the first thing on the line.
100105
$prev = $phpcsFile->findPrevious(T_DOC_COMMENT_WHITESPACE, ($i - 1), $stackPtr, true);
101106
if ($tokens[$prev]['line'] === $tokens[$i]['line']) {

src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public function process(File $phpcsFile, $stackPtr)
6464
return ($phpcsFile->numTokens + 1);
6565
}
6666

67+
if (isset($tokens[$commentStart]['comment_closer']) === false
68+
|| ($tokens[$tokens[$commentStart]['comment_closer']]['content'] === ''
69+
&& $tokens[$commentStart]['comment_closer'] === ($phpcsFile->numTokens - 1))
70+
) {
71+
// Don't process an unfinished file comment during live coding.
72+
return ($phpcsFile->numTokens + 1);
73+
}
74+
6775
$commentEnd = $tokens[$commentStart]['comment_closer'];
6876

6977
$nextToken = $phpcsFile->findNext(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* File comment.
4+
*
5+
* @package Package
6+
* @subpackage Subpackage
7+
* @author Squiz Pty Ltd <[email protected]>
8+
* @copyright 2010-2014 Squiz Pty Ltd (ABN 77 084 670 600)
9+
*

0 commit comments

Comments
 (0)