Skip to content

Commit

Permalink
Generic/SpreadOperatorSpacingAfter: minor message readability improve…
Browse files Browse the repository at this point in the history
…ment

Use `space`/`spaces` depending on the value of the `$spacing` property instead of using `space(s)` in the error message.
  • Loading branch information
jrfnl committed Nov 9, 2023
1 parent 4ac5785 commit 3302778
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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,
];

Expand Down

0 comments on commit 3302778

Please sign in to comment.