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 #3957

Closed
rarila opened this issue Jan 18, 2025 · 1 comment
Closed

ANSI colors in JSON report #3957

rarila opened this issue Jan 18, 2025 · 1 comment

Comments

@rarila
Copy link

rarila commented Jan 18, 2025

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

$generatedReport = preg_replace('`\033\[[0-9;]+m`', '', $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:

  • 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)
@rarila
Copy link
Author

rarila commented Jan 19, 2025

Ooops, wrong repo… 😳
CU on PHPCSStandards/PHP_CodeSniffer

@rarila rarila closed this as completed Jan 19, 2025
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