From 511b8776b2e51bccd818e1dcb1d8298b46b6cb33 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. --- CHANGELOG.md | 2 ++ .../SpreadOperatorSpacingAfterSniff.php | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef89522182..37186bdbb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,8 @@ The file documents changes to the PHP_CodeSniffer project. - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch - Tests using the PHPCS native test framework with multiple test case files will now run the test case files in numeric order. - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch +- Generic/SpreadOperatorSpacingAfter: minor message readability improvement + - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch ### Removed - Removed support for installing via PEAR 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, ];