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 Dec 4, 2023
1 parent 45d33e0 commit 511b877
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 511b877

Please sign in to comment.