diff --git a/src/Standards/Generic/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php b/src/Standards/Generic/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php index 42fd6573ab..5970431142 100644 --- a/src/Standards/Generic/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php +++ b/src/Standards/Generic/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php @@ -113,7 +113,7 @@ public function process(File $phpcsFile, int $stackPtr) } $error = 'Language constructs must be followed by a single space; expected 1 space between YIELD FROM found "%s"'; - $data = [Common::prepareForOutput($found)]; + $data = [Common::prepareForOutput($found, [' '])]; if ($hasComment === true) { $phpcsFile->addError($error, $stackPtr, 'IncorrectYieldFromWithComment', $data); @@ -139,8 +139,16 @@ public function process(File $phpcsFile, int $stackPtr) if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { $content = $tokens[($stackPtr + 1)]['content']; if ($content !== ' ') { - $error = 'Language constructs must be followed by a single space; expected 1 space but found "%s"'; - $data = [Common::prepareForOutput($content)]; + if (trim($content, ' ') === '') { + // Only space characters: report the count. + $found = $tokens[($stackPtr + 1)]['length'] . ' spaces'; + } else { + // Contains tabs or newlines: make them visible. + $found = '"' . Common::prepareForOutput($content, [' ']) . '"'; + } + + $error = 'Language constructs must be followed by a single space; expected 1 space but found %s'; + $data = [$found]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'IncorrectSingle', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); diff --git a/src/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php b/src/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php index 6143b0972f..cb0e492332 100644 --- a/src/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php @@ -280,7 +280,7 @@ public function processBracket(File $phpcsFile, int $openBracket) $data[] = strlen($gap); } else { // Gap contains more than just spaces: render these for better clarity. - $data[] = '"' . Common::prepareForOutput($gap) . '"'; + $data[] = '"' . Common::prepareForOutput($gap, [' ']) . '"'; } $fix = $phpcsFile->addFixableError($error, $typeHintToken, 'SpacingAfterHint', $data);