Skip to content

Generic/LowerCaseKeyword: remove unnecessary use of prepareForOutput()#1379

Merged
jrfnl merged 1 commit intoPHPCSStandards:4.xfrom
rodrigoprimo:remove-prepare-output-from-lowercase-keyword-sniff
Mar 5, 2026
Merged

Generic/LowerCaseKeyword: remove unnecessary use of prepareForOutput()#1379
jrfnl merged 1 commit intoPHPCSStandards:4.xfrom
rodrigoprimo:remove-prepare-output-from-lowercase-keyword-sniff

Conversation

@rodrigoprimo
Copy link
Copy Markdown
Contributor

Description

As suggested in squizlabs/PHP_CodeSniffer#2652 (comment), this PR removes an unnecessary use of Common::prepareForOutput() in the Generic.PHP.LowerCaseKeyword sniff.

Common::prepareForOutput() replaces spaces with a middle dot character to make whitespace visible in error messages. It was added to this sniff in commit 6ef2856 ("Better support for showing spaces and newlines"), probably as a follow-up to the multi-line yield from support added in squizlabs/PHP_CodeSniffer#1337 (commits ce60083 and d1a9163) as all three commits are by the same author on the same day.

For most PHP keywords, Common::prepareForOutput() has no effect since they don't contain whitespace. The one exception is yield from (T_YIELD_FROM), which, in some cases, is tokenized as a single token containing a space. In that case, Common::prepareForOutput() would display yield·from, but I would argue that showing the keyword as-is is preferable even in this case.

This changes the error output for Yield From from:

expected "yield·from" but found "Yield·From"

To:

expected "yield from" but found "Yield From"

Suggested changelog entry

Changed: Generic.PHP.LowerCaseKeyword no longer embeds UTF-8 middle dot characters in error messages for the yield from keyword.

Related issues/external references

Related squizlabs/PHP_CodeSniffer#2652 (comment)

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.
  • I have opened a sister-PR in the documentation repository to update the Wiki.

Common::prepareForOutput() replaces spaces with a middle dot character
to make whitespace visible in error messages. It was added to this sniff
in commit 6ef2856 ("Better support for showing spaces and newlines"),
probably as a follow-up to the multi-line `yield from` support added in
squizlabs/PHP_CodeSniffer 1337 (commits ce60083 and d1a9163) as all
three commits are by the same author on the same day.

For most PHP keywords prepareForOutput() has no effect since they don't
contain whitespace. The one exception is `yield from` (T_YIELD_FROM),
which, in some cases, is tokenized as a single token containing a space.
In that case, prepareForOutput() would display `yield·from`, but I would
argue that showing the keyword as-is is preferable even in this case.

This changes the error output for `yield from` from:

```
expected "yield·from" but found "Yield·From"
```

To:

```
expected "yield from" but found "Yield From"
```

Suggested in: squizlabs/PHP_CodeSniffer 2652
Copy link
Copy Markdown
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.

but I would argue that showing the keyword as-is is preferable even in this case.

Agreed. Thanks for making this change. LGTM!

@jrfnl jrfnl merged commit 631b16a into PHPCSStandards:4.x Mar 5, 2026
55 checks passed
@jrfnl jrfnl deleted the remove-prepare-output-from-lowercase-keyword-sniff branch March 5, 2026 19:53
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.

2 participants