Open
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 aebd84b
The problem:
When you run with --report=json --no-colors
the message is first JSON encoded
PHP_CodeSniffer/src/Reports/Json.php
Line 60 in aebd84b
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 279 in aebd84b
and adds colors.
Possible solutions:
Some ideas, but I'm sure someone can come up with a better one…
- 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)