From 33027785f2a0dd2666856d086f34b1cf3a69b3f5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 12 Aug 2022 16:54:56 +0200 Subject: [PATCH] Generic/SpreadOperatorSpacingAfter: minor message readability improvement Use `space`/`spaces` depending on the value of the `$spacing` property instead of using `space(s)` in the error message. --- .../SpreadOperatorSpacingAfterSniff.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.php b/src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.php index 9479dd9bdb..44a05036d6 100644 --- a/src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.php +++ b/src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.php @@ -54,8 +54,12 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); - $this->spacing = (int) $this->spacing; + $tokens = $phpcsFile->getTokens(); + $this->spacing = (int) $this->spacing; + $pluralizeSpace = 's'; + if ($this->spacing === 1) { + $pluralizeSpace = ''; + } $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); if ($nextNonEmpty === false) { @@ -81,8 +85,11 @@ public function process(File $phpcsFile, $stackPtr) $nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); if ($nextNonEmpty !== $nextNonWhitespace) { - $error = 'Expected %s space(s) after the spread operator; comment found'; - $data = [$this->spacing]; + $error = 'Expected %s space%s after the spread operator; comment found'; + $data = [ + $this->spacing, + $pluralizeSpace, + ]; $phpcsFile->addError($error, $stackPtr, 'CommentFound', $data); if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { @@ -107,9 +114,10 @@ public function process(File $phpcsFile, $stackPtr) return; } - $error = 'Expected %s space(s) after the spread operator; %s found'; + $error = 'Expected %s space%s after the spread operator; %s found'; $data = [ $this->spacing, + $pluralizeSpace, $found, ];