From ddc25a1774228687317d5a413729ba61e4983aaf Mon Sep 17 00:00:00 2001 From: Jay McPartland Date: Fri, 26 Sep 2025 14:07:14 +0100 Subject: [PATCH] Update line length sniff to disregard lines containing specific prefixes --- .../Sniffs/Commenting/DocCommentLineLengthSniff.php | 12 ++++++++++-- .../Commenting/DocCommentLineLengthUnitTest.1.inc | 8 +------- .../DocCommentLineLengthUnitTest.1.inc.fixed | 8 +------- .../Commenting/DocCommentLineLengthUnitTest.php | 4 ++-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/BigBite/Sniffs/Commenting/DocCommentLineLengthSniff.php b/BigBite/Sniffs/Commenting/DocCommentLineLengthSniff.php index 522eee9..8317022 100644 --- a/BigBite/Sniffs/Commenting/DocCommentLineLengthSniff.php +++ b/BigBite/Sniffs/Commenting/DocCommentLineLengthSniff.php @@ -52,11 +52,13 @@ final class DocCommentLineLengthSniff implements Sniff { /** * Specific comment prefixes to ignore. * + * If a comment line begins with any of these prefixes, + * the line length calculations should be skipped for that line. + * * @var array */ public $descriptorsToIgnore = array( - 'Plugin Name:', - 'Theme Name:', + 'Description:', ); /** @@ -118,6 +120,12 @@ public function process( File $phpcsFile, $stackPtr ) { continue; } + foreach ( $this->descriptorsToIgnore as $ignoreThisPrefix ) { + if ( 0 === strpos( $tokens[ $i ]['content'], $ignoreThisPrefix ) ) { + continue 2; + } + } + $isAParameterDescription = false; $lineLength = $tokens[ $i ]['length']; diff --git a/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.1.inc b/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.1.inc index 3f1700e..153e052 100644 --- a/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.1.inc +++ b/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.1.inc @@ -17,13 +17,7 @@ */ /** - * Plugin Name: Line lengths - * Description: WordPress plugin/theme comment line lengths are excluded from this sniff. - */ - -/** - * Theme Name: Line lengths - * Description: WordPress plugin/theme comment line lengths are excluded from this sniff, both soft limit and hard limit. + * Description: comment lines that begin with the "Description:" prefix are excluded from this sniff, both soft limit and hard limit. */ /** diff --git a/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.1.inc.fixed b/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.1.inc.fixed index 0da500e..279ce57 100644 --- a/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.1.inc.fixed +++ b/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.1.inc.fixed @@ -19,13 +19,7 @@ */ /** - * Plugin Name: Line lengths - * Description: WordPress plugin/theme comment line lengths are excluded from this sniff. - */ - -/** - * Theme Name: Line lengths - * Description: WordPress plugin/theme comment line lengths are excluded from this sniff, both soft limit and hard limit. + * Description: comment lines that begin with the "Description:" prefix are excluded from this sniff, both soft limit and hard limit. */ /** diff --git a/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.php b/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.php index 5f80be0..08ddef9 100644 --- a/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.php +++ b/BigBite/Tests/Commenting/DocCommentLineLengthUnitTest.php @@ -45,7 +45,7 @@ public function getErrorList( $testFile = '' ) { case 'DocCommentLineLengthUnitTest.1.inc': return array( 8 => 1, - 45 => 1, + 39 => 1, ); case 'DocCommentLineLengthUnitTest.2.inc': return array( @@ -75,7 +75,7 @@ public function getWarningList( $testFile = '' ) { case 'DocCommentLineLengthUnitTest.1.inc': return array( 4 => 1, - 38 => 1, + 32 => 1, ); case 'DocCommentLineLengthUnitTest.2.inc': return array(