Sniffs: exclude space from prepareForOutput() in error messages#1389
Merged
jrfnl merged 2 commits intoPHPCSStandards:4.xfrom Mar 18, 2026
Merged
Conversation
…orOutput() The `SpacingAfterHint` error uses `Common::prepareForOutput()` to make whitespace characters visible in the error message when the gap between a type hint and argument contains tabs or newlines. Among other things, the method replaces spaces with a UTF-8 middot character. This commit changes the call to `Common::prepareForOutput()`, to pass `[' ']` as the `$exclude` parameter so that spaces are displayed as-is while tabs and newlines continue to be rendered as `\t` and `\n`. This change is necessary because the middot character in the output can break tools that pipe PHPCS output through non-UTF-8 environments (see squizlabs/PHP_CodeSniffer 2652). `Common::prepareForOutput()` was added to this sniff in PR 620.
jrfnl
reviewed
Mar 18, 2026
Member
jrfnl
left a comment
There was a problem hiding this comment.
@rodrigoprimo Thanks for setting this up. Just one minor tweak suggestion, but not a blocker.
src/Standards/Generic/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php
Outdated
Show resolved
Hide resolved
This sniff uses `Common::prepareForOutput()` in two places to make whitespace visible in error messages. Among other things, the method replaces spaces with a UTF-8 middot character. The middot character in the output can break tools that pipe PHPCS output through non-UTF-8 environments (see squizlabs/PHP_CodeSniffer 2652). For the `IncorrectSingle` error, the spaces-only case now reports a descriptive count like "found 2 spaces" instead of displaying middot characters. For tabs or newlines, `prepareForOutput()` is kept but with `[' ']` as the `$exclude` parameter, so that any spaces in the content are displayed as-is. For the `IncorrectYieldFrom` and `IncorrectYieldFromWithComment` errors, the same `$exclude` parameter is passed, so that spaces between `yield` and `from` are no longer replaced with middots.
c6b8515 to
7c86cae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
As suggested in squizlabs/PHP_CodeSniffer#2652 (comment), this PR updates the
Generic.WhiteSpace.LanguageConstructSpacingandSquiz.Functions.FunctionDeclarationArgumentSpacingsniffs to pass[' ']as the$excludeparameter toCommon::prepareForOutput(), so that spaces are no longer replaced with UTF-8 middot characters (·) in error messages. Tabs and newlines continue to be rendered as\tand\n.Additionally, for the
IncorrectSingleerror inGeneric.WhiteSpace.LanguageConstructSpacing, the spaces-only case now reports a descriptive count like "found 2 spaces" instead of displaying middot characters.The middot character in the output can break tools that pipe PHPCS output through non-UTF-8 environments.
This is a follow-up to #1379, which addressed the same issue in
Generic.PHP.LowerCaseKeyword.Suggested changelog entry
Changed:
Generic.WhiteSpace.LanguageConstructSpacingandSquiz.Functions.FunctionDeclarationArgumentSpacingno longer embed UTF-8 middot characters for spaces in error messages.Related issues/external references
Fixes squizlabs/PHP_CodeSniffer#2652
Types of changes
PR checklist