Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Squiz InlineCommentSniff no longer requires a blank line after post-s…

…tatement comments (request #20299)
  • Loading branch information...
commit d04c71c41a4ade139e91621636450ead755ac502 1 parent aa2fe39
@gsherwood gsherwood authored
View
32 CodeSniffer/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php
@@ -124,14 +124,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
// Only error once per comment.
if (substr($tokens[$stackPtr]['content'], 0, 3) === '/**') {
- $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
+ $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
$phpcsFile->addError($error, $stackPtr, 'DocBlock');
}
}//end if
}//end if
if ($tokens[$stackPtr]['content']{0} === '#') {
- $error = 'Perl-style comments are not allowed; use "// Comment" instead';
+ $error = 'Perl-style comments are not allowed; use "// Comment" instead';
$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
}
@@ -248,25 +248,25 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->addError($error, $stackPtr, 'InvalidEndChar', $data);
}
- // Finally, the line below the last comment cannot be empty.
- $start = false;
- for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
- if ($tokens[$i]['line'] === ($tokens[$stackPtr]['line'] + 1)) {
- if ($tokens[$i]['code'] !== T_WHITESPACE) {
- return;
+ // Finally, the line below the last comment cannot be empty if this inline
+ // comment is on a line by itself.
+ if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
+ $start = false;
+ for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
+ if ($tokens[$i]['line'] === ($tokens[$stackPtr]['line'] + 1)) {
+ if ($tokens[$i]['code'] !== T_WHITESPACE) {
+ return;
+ }
+ } else if ($tokens[$i]['line'] > ($tokens[$stackPtr]['line'] + 1)) {
+ break;
}
- } else if ($tokens[$i]['line'] > ($tokens[$stackPtr]['line'] + 1)) {
- break;
}
- }
- $error = 'There must be no blank line following an inline comment';
- $phpcsFile->addError($error, $stackPtr, 'SpacingAfter');
+ $error = 'There must be no blank line following an inline comment';
+ $phpcsFile->addError($error, $stackPtr, 'SpacingAfter');
+ }
}//end process()
}//end class
-
-
-?>
View
5 CodeSniffer/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc
@@ -110,4 +110,7 @@ final class MyClass
trait MyTrait {
}
-?>
+
+$foo = 'foo'; // Var set to foo.
+
+echo $foo;
View
7 CodeSniffer/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.js
@@ -108,4 +108,9 @@ mig.Gallery.prototype = {
-> One
-> One.One
-> Two
-*/
+*/
+
+
+var foo = 'foo'; // Var set to foo.
+
+console.info(foo);
View
1  package.xml
@@ -34,6 +34,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Dawid Nowak for the patch
- Generic ForbiddenFunctionsSniff now detects calls to functions in the global namespace
-- Thanks to Ole Martin Handeland for the patch
+ - Squiz InlineCommentSniff no longer requires a blank line after post-statement comments (request #20299)
- Fixed bug #20268 : Incorrect documentation titles in PEAR documentation
- Fixed bug #20296 : new array notion in function comma check fails
- Fixed bug #20307 : PHP_CodeSniffer_Standards_AbstractVariableSniff analyze traits
Please sign in to comment.
Something went wrong with that request. Please try again.