Skip to content

Conversation

@rodrigoprimo
Copy link
Contributor

@rodrigoprimo rodrigoprimo commented Jan 19, 2024

Description

This PR 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 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)

Suggested changelog entry

Generic/IncrementDecrementSpacing: fix error message when one or more newlines are found between the variable and the post-decrement operator

Related issues/external references

Fixes #288

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigoprimo Approval on the fix.

However, even though the error message itself is not tested by the test suite as-is, this is a situation which was not covered by the pre-existing tests, so a test should be added to cover this.

Having a test in the test case file for this situation also makes it easier to validate the issue and review the change.

@rodrigoprimo rodrigoprimo force-pushed the fix-increment-decrement-spacing-error-message branch from 4d0f580 to 6ba6a91 Compare January 22, 2024 13:13
@rodrigoprimo
Copy link
Contributor Author

Thanks for the review, @jrfnl.

I added a commit with four new tests. They use a syntax that was not used in previous tests, and one of them has a newline between the object property accessed through a method call and the post-incrementor to test the fix added in this PR.

@jrfnl
Copy link
Member

jrfnl commented Jan 22, 2024

Thanks for the review, @jrfnl.

I added a commit with four new tests. They use a syntax that was not used in previous tests, and one of them has a newline between the object property accessed through a method call and the post-incrementor to test the fix added in this PR.

While I can see the usefulness of the extra tests, they don't belong in this PR/commit - save for the one with the new line.

@jrfnl
Copy link
Member

jrfnl commented Jan 22, 2024

While I can see the usefulness of the extra tests, they don't belong in this PR/commit - save for the one with the new line.

If you'd move the test with the new line to the first commit and leave the other tests in the second commit, I can accept the PR.

@rodrigoprimo rodrigoprimo force-pushed the fix-increment-decrement-spacing-error-message branch from 6ba6a91 to 781d9c2 Compare January 22, 2024 17:22
@rodrigoprimo
Copy link
Contributor Author

If you'd move the test with the new line to the first commit and leave the other tests in the second commit, I can accept the PR.

Done

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.
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making that tweak @rodrigoprimo !

I'll rebase without changes & merge the PR once the build has gone through.

Adds tests using pre/post-incrementors with an object
property accessed through a method call.
@jrfnl jrfnl force-pushed the fix-increment-decrement-spacing-error-message branch from 781d9c2 to 4607a26 Compare January 22, 2024 23:05
@jrfnl jrfnl merged commit 7a7cd6b into PHPCSStandards:master Jan 22, 2024
@rodrigoprimo rodrigoprimo deleted the fix-increment-decrement-spacing-error-message branch March 26, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generic/IncrementDecrementSpacing: inconsistent error message

2 participants