Skip to content

Commit 955f7a6

Browse files
committed
PHPCSDebug/TokenList: minor tweak for testability
When a token only contains new line characters, a trailing space would be included on the line. This makes testing the sniff harder as trailing whitespace is typically trimmed from a file, including in the expectations set in the tests. This minor tweak ensures that the output for "new line only" tokens won't have trailing whitespace in the output line for the token.
1 parent 8e57c25 commit 955f7a6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

PHPCSDebug/Sniffs/Debug/TokenListSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function process(File $phpcsFile, $stackPtr)
9999
foreach ($tokens as $ptr => $token) {
100100
$token += $this->tokenDefaults;
101101
$content = $token['content'];
102+
$onlyEol = false;
102103

103104
if (isset($token['orig_content'])) {
104105
$content = $this->visualizeWhitespace($content);
@@ -121,13 +122,16 @@ public function process(File $phpcsFile, $stackPtr)
121122
$parenthesesCount = \count($token['nested_parenthesis']);
122123
}
123124

125+
$onlyEol = (\trim($content, "\n\r") === '');
126+
124127
echo \str_pad($ptr, $ptrPadding, ' ', \STR_PAD_LEFT),
125128
$sep, 'L', \str_pad($token['line'], $linePadding, '0', \STR_PAD_LEFT),
126129
$sep, 'C', \str_pad($token['column'], 3, ' ', \STR_PAD_LEFT),
127130
$sep, 'CC', \str_pad($token['level'], 2, ' ', \STR_PAD_LEFT),
128131
$sep, '(', \str_pad($parenthesesCount, 2, ' ', \STR_PAD_LEFT), ')',
129132
$sep, \str_pad($token['type'], 26), // Longest token type name is 26 chars.
130-
$sep, '[', \str_pad($token['length'], 3, ' ', \STR_PAD_LEFT), ']: ', $content, \PHP_EOL;
133+
$sep, '[', \str_pad($token['length'], 3, ' ', \STR_PAD_LEFT), ']:',
134+
($onlyEol === false ? ' ' : ''), $content, \PHP_EOL;
131135
}
132136

133137
// Only do this once per file.

0 commit comments

Comments
 (0)