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

Remove color code from super-linter stdout and logfile when not needed #5540

Open
1 task done
ChaosEternal opened this issue Apr 18, 2024 · 11 comments
Open
1 task done
Labels
enhancement New feature or request O: backlog 🤖 Backlog, stale ignores this label

Comments

@ChaosEternal
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The current output from shellcheck has ansi color codes, which makes the output difficult to read if not from a terminal.

Expected Behavior

Ability to remove the ansi-color code.

A flag or a config is good.

Anything else?

No response

@ChaosEternal ChaosEternal added the enhancement New feature or request label Apr 18, 2024
@ferrarimarco ferrarimarco added the O: backlog 🤖 Backlog, stale ignores this label label Apr 18, 2024
@ferrarimarco
Copy link
Collaborator

Hi @ChaosEternal !

I think this is applicable not just for ShellCheck output, but to the whole output.

Example:

�[0m2024-04-18 04:06:21 �[0;34m[INFO]�[0m   Linting BASH items...�[0m
�[0m2024-04-18 04:06:21 �[0;31m[ERROR]�[0m   Found errors when linting BASH. Exit code: 1.�[0m
�[0m2024-04-18 04:06:21 �[0;34m[INFO]�[0m   Command output for BASH:
------

�[1mIn /blahline 24:�[0m
�[0mtrap "rm -rf '$TEMP'" EXIT�[0m
�[33m.           ^---^ SC2064 (warning): Use single quotes, otherwise this expands now rather than when signalled.�[0m
signalled.�[0m

For more information:
  https://www.shellcheck.net/wiki/SC2064 -- Use single quotes, otherwise this...
------�[0m

Anyway, you have a point.

@ferrarimarco
Copy link
Collaborator

We may start with checking if we have a terminal: if [ -t 0 ]; then ...

@ferrarimarco
Copy link
Collaborator

A complementary feature may be that the log file should respect the log level, instead of defaulting to DEBUG, but this is for another feature request :)

@alexanderbazhenoff
Copy link

alexanderbazhenoff commented Apr 23, 2024

Hi @ChaosEternal

to read if not from a terminal.

Where to read for example? :)

FYI: if you read a raw output from GitLab CI (for example) you may use some additional browser plugins like RetroTxt for Google Chrome. Full ASCII support on specified URLs available. This plugin is especially useful when you open huge colored ansible logs in raw.

As about shellcheck in Super-linter, in previous super-linter versions I used .shellcheckrc file to set output format:

# <your_settings_folder>/.shellcheckrc
# You can set this path via `LINTER_RULES_PATH` env variable:
# https://github.com/super-linter/super-linter#configure-super-linter

format=gcc # Output format (checkstyle, diff, gcc, json, json1, quiet, tty)

PS: Hmmm... I have comment here, but it was asked :)

@ChaosEternal
Copy link
Author

ChaosEternal commented Apr 23, 2024 via email

@ferrarimarco
Copy link
Collaborator

@ChaosEternal v6.4.1 implements part of what you're asking, I think. See #5546 for details. Now, super-linter adds color codes to stdout only if there's a tty, and never does that in the super-linter log file. This is a step in the right direction because:

  • You can enable color codes when super-linter emits logs on stdout as needed (just allocate a tty).
  • The super-linter log file doesn't have color codes for super-linter log messages (see below for details)

The issue that's left to address is that we use what each linter emits to stdout and stderr as part of the super-linter stdout and the super-linter log file. Each linter has its own way to deal with emitting (or not) color codes: configuration, command line options, presence of a tty, on unless disabled...

This might cause some color codes to be present in the super-linter stdout or in the super-linter log file when you look at each specific linter output. An example of this is Gitleaks.

(the following statements are applicable to linters that support color codes)

To address this, we would need to account for two cases to avoid getting color codes in the super-linter stdout and super-linter log file when not needed:

  • There is no tty allocated: disable color output for each individual linter. (probably doable)
  • There is a tty allocated: this is harder because we would need two outputs for each linter: one for super-linter stdout (with color codes), one for super-linter log (without color codes). I don't think many linters (if at all) support this.

@ferrarimarco ferrarimarco changed the title Remove color code from shellcheck's output Remove color code from super-linter stdout and logfile Apr 23, 2024
@ferrarimarco ferrarimarco changed the title Remove color code from super-linter stdout and logfile Remove color code from super-linter stdout and logfile when not needed Apr 23, 2024
@ferrarimarco
Copy link
Collaborator

i) we have a ci system which have (only) plain log support, those color code doesn't display correctly

See my previous reply about this.

ii) there are machines that want to read the output and make meaningful suggestions to code reviewers.

For this, parsing text logs is probably too fragile. We might want to have a look at more structured output formats, such as SARIF and JSON for linters that support that, but that's for another feature request, I suppose. :)

@alexanderbazhenoff
Copy link

Now, super-linter adds color codes to stdout only

BTW, how to force enable colors now in CI? (Not so big problem, but it's better for us :)

@ferrarimarco
Copy link
Collaborator

@alexanderbazhenoff Hi! How are you running super-linter?

@alexanderbazhenoff
Copy link

@alexanderbazhenoff Hi! How are you running super-linter?

Hi, in GitLab CI as described here.

@ferrarimarco
Copy link
Collaborator

@alexanderbazhenoff Can you try allocating a TTY (add --tty or -t option to the docker run command)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request O: backlog 🤖 Backlog, stale ignores this label
Projects
None yet
Development

No branches or pull requests

3 participants