Skip to content

Commit

Permalink
Generic/IncrementDecrementSpacing: fix post-decrement error message
Browse files Browse the repository at this point in the history
This commit fixes the post-decrement error message when there is one or
more newlines between the variable and the post-decrement operator.

The wrong variable was being used to check whether the post-decrement
and the variable were not on the same line, resulting in an incorrect
error message. The error message should explicitly say that a newline
was found.

Before this commit the error message was:

```
Expected no spaces between $i and the decrement operator; 0 found
```

Now it is:

```
Expected no spaces between the decrement operator and $i; newline found
```

(`newline` instead of `0`)

This commit also includes a test that exercises the modified line.
  • Loading branch information
rodrigoprimo authored and jrfnl committed Jan 22, 2024
1 parent b03d10f commit a30addb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function process(File $phpcsFile, $stackPtr)
$fixable = false;
$spaces = 'comment';
} else {
if ($tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']) {
if ($tokens[$stackPtr]['line'] !== $tokens[$prevNonEmpty]['line']) {
$spaces = 'newline';
} else {
$spaces = $tokens[($stackPtr - 1)]['length'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ $obj->prop['key'] ++;

--ClassName::$prop;
-- ClassName::$prop;

getObject()->count
++;
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ $obj->prop['key']++;

--ClassName::$prop;
--ClassName::$prop;

getObject()->count++;
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getErrorList($testFile='')
$errors[31] = 1;
$errors[34] = 1;
$errors[37] = 1;
$errors[40] = 1;

return $errors;

Expand Down

0 comments on commit a30addb

Please sign in to comment.