From 5fff209600ef72fc74de851de321353e12184c03 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Mon, 19 Jul 2021 08:53:06 +1000 Subject: [PATCH] Fixed bug #3384 : Squiz.Commenting.FileComment.SpacingAfterComment false positive on empty file --- package.xml | 2 ++ .../Squiz/Sniffs/Commenting/FileCommentSniff.php | 2 +- .../Squiz/Tests/Commenting/FileCommentUnitTest.8.inc | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.8.inc diff --git a/package.xml b/package.xml index f4244c4442..17d2782b40 100644 --- a/package.xml +++ b/package.xml @@ -72,6 +72,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #3357 : Generic.Functions.OpeningFunctionBraceBsdAllman removes return type when additional lines are present -- Thanks to Juliette Reinders Folmer for the patch - Fixed bug #3362 : Generic.WhiteSpace.ScopeIndent false positive for arrow functions inside arrays + - Fixed bug #3384 : Squiz.Commenting.FileComment.SpacingAfterComment false positive on empty file @@ -1640,6 +1641,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php index 73eb31b71f..2685854769 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php @@ -127,7 +127,7 @@ public function process(File $phpcsFile, $stackPtr) // Exactly one blank line after the file comment. $next = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), null, true); - if ($tokens[$next]['line'] !== ($tokens[$commentEnd]['line'] + 2)) { + if ($next !== false && $tokens[$next]['line'] !== ($tokens[$commentEnd]['line'] + 2)) { $error = 'There must be exactly one blank line after the file comment'; $phpcsFile->addError($error, $commentEnd, 'SpacingAfterComment'); } diff --git a/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.8.inc b/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.8.inc new file mode 100644 index 0000000000..5ef90f2ad1 --- /dev/null +++ b/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.8.inc @@ -0,0 +1,9 @@ + + * @copyright 2010-2014 Squiz Pty Ltd (ABN 77 084 670 600) + */