From aaf8ca94b2bb6763622f5f6ef61fcdbd95cf05d6 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 2 May 2019 19:08:07 +0100 Subject: [PATCH] Comment Placement sniff - allow comments in the first column after PHP opening tag --- .../Sniffs/Commenting/PlacementSniff.php | 3 ++- test/Sniffs/Commenting/PlacementUnitTest.inc | 1 + test/Sniffs/Commenting/PlacementUnitTest.inc.fixed | 1 + test/Sniffs/Commenting/PlacementUnitTest.php | 6 +++--- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/WebimpressCodingStandard/Sniffs/Commenting/PlacementSniff.php b/src/WebimpressCodingStandard/Sniffs/Commenting/PlacementSniff.php index 178fe132..913696e2 100644 --- a/src/WebimpressCodingStandard/Sniffs/Commenting/PlacementSniff.php +++ b/src/WebimpressCodingStandard/Sniffs/Commenting/PlacementSniff.php @@ -30,7 +30,8 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if ($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE + if ($tokens[$stackPtr]['column'] !== 1 + && $tokens[$stackPtr - 1]['code'] !== T_WHITESPACE && ($tokens[$stackPtr - 1]['code'] !== T_COMMENT || $tokens[$stackPtr - 1]['line'] === $tokens[$stackPtr]['line']) ) { diff --git a/test/Sniffs/Commenting/PlacementUnitTest.inc b/test/Sniffs/Commenting/PlacementUnitTest.inc index 74d902fe..429db392 100644 --- a/test/Sniffs/Commenting/PlacementUnitTest.inc +++ b/test/Sniffs/Commenting/PlacementUnitTest.inc @@ -1,4 +1,5 @@ 1, 4 => 1, - 6 => 3, - 8 => 3, + 5 => 1, + 7 => 3, + 9 => 3, ]; }