-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
If I’m right, ANSI color codes get removed here, if you e.g. supply the switch --no-colors
:
PHP_CodeSniffer/src/Reporter.php
Line 239 in c6c65ca
$generatedReport = preg_replace('`\033\[[0-9;]+m`', '', $generatedReport); |
The problem:
When you run with --report=json --no-colors
the message is first JSON encoded
PHP_CodeSniffer/src/Reports/Json.php
Line 59 in c6c65ca
$messages .= json_encode($messagesObject).","; |
so, that afterwards the color code removal fails, as the initial message is now encoded.
For example:
Before: ... "\033[30;1m·\033[0m" ...
After: ... "\u001b[30;1m\u00b7\u001b[0m\u001b[30;1m\u00b7\u001b[0m" ...
To reproduce:
It happens for example with LanguageConstructSpacingSniff
(add multiple spaces somewhere) that calls
PHP_CodeSniffer/src/Util/Common.php
Line 276 in c6c65ca
public static function prepareForOutput($content, $exclude=[]) |
and adds colors.
Possible solutions:
- Probably easiest: Colors could be removed before JSON encoding independant of the color setting.
Is there any need for colors in a JSON report?! - Don’t even add colors in the first place when no colors are demanded
- Remove encoded colors in JSON report (probably the worst solution)
Metadata
Metadata
Assignees
Labels
No labels