Skip to content

Commit 3abedb7

Browse files
committed
PHPCSDebug/TokenList: always show original content when available
When the `tab-width` configuration variable has been set for PHPCS - either via the config, via a ruleset or via the command-line -, PHPCS will replace tabs with spaces in the `'content'` and retain the original content in a `'orig_content'` key. Previously, this "original content" would only be shown for whitespace tokens. However, tab replacement can also happen in other tokens. Typically tabs may also be found in text strings and comments contents. This commit adjusts the sniff to _always_ show the "original content" if that array key has been set in the token array. Whitespace visualization will be enabled in that case for both the `'content'` as well as the `'orig_content'` so the "tabs vs spaces" difference can be clearly seen.
1 parent 79a70d6 commit 3abedb7

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

PHPCSDebug/Sniffs/Debug/TokenListSniff.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,12 @@ public function process(File $phpcsFile, $stackPtr)
106106
}
107107
}
108108

109-
if ($token['code'] === \T_WHITESPACE
110-
|| (\defined('T_DOC_COMMENT_WHITESPACE')
111-
&& $token['code'] === \T_DOC_COMMENT_WHITESPACE)
112-
) {
109+
if (isset($token['orig_content'])) {
110+
$content = $this->visualizeWhitespace($content);
111+
$content .= $sep . 'Orig: ' . $this->visualizeWhitespace($token['orig_content']);
112+
} elseif ($token['code'] === \T_WHITESPACE) {
113113
$content = $this->visualizeWhitespace($content);
114-
115-
if (isset($token['orig_content'])) {
116-
$content .= $sep . 'Orig: ' . $this->visualizeWhitespace($token['orig_content']);
117-
}
118-
}
119-
120-
if (isset(Tokens::$commentTokens[$token['code']]) === true) {
114+
} elseif (isset(Tokens::$commentTokens[$token['code']]) === true) {
121115
/*
122116
* Comment tokens followed by a new line, will have trailing whitespace
123117
* included in the token, so visualize it.

0 commit comments

Comments
 (0)