Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANSI colors in JSON report #787

Open
rarila opened this issue Jan 19, 2025 · 0 comments
Open

ANSI colors in JSON report #787

rarila opened this issue Jan 19, 2025 · 0 comments

Comments

@rarila
Copy link

rarila commented Jan 19, 2025

If I’m right, ANSI color codes get removed here, if you e.g. supply the switch --no-colors:

$generatedReport = Common::stripColors($generatedReport);

The problem:

When you run with --report=json --no-colors the message is first JSON encoded

$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

public static function prepareForOutput($content, $exclude=[])

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant