Home > Enterprise >  How do you change the ERROR output color of output created by TSLINT?
How do you change the ERROR output color of output created by TSLINT?

Time:10-08

I am using TSLINT in Angular 12 w/ the command npm run lint. The TSLINT errors are difficult for me to read.

ERROR: 12:3 variable-name variable name must be in lowerCamelCase,PascalCase of UPPER_CASE

"ERROR: 12:3" is red. I viewed $host.privatedata and I only see one option that is using Red. I changed:

$host.PrivateData.ErrorForegroundColor = 'Yellow'

And the output from TSLINT is still red using the same Powershell session.

How can I make the ERROR output yellow?

UPDATE 1

Powershell Version: 5.1.19041.1682

CodePudding user response:

I'm not sure, why $host.PrivateData.ErrorForegroundColor isn't working.

As a workaround you may merge the stderr output of npm with the stdout stream (2>&1), filter error messages by testing for the "ERROR:" prefix and colorize them as you like.

npm run lint 2>&1 | ForEach-Object { 
    $msg = "$_"
    if( $msg -like 'ERROR:*' ) {
        Write-Host -ForegroundColor Yellow $msg   # Recolorize error message
    }
    else {
        $msg   # Output as-is
    }
}
  • The ForEach-Object script block runs for each line of stdout and stderr.
  • $msg = "$_" makes sure that messages from stderr, which are actually of type System.Management.Automation.ErrorRecord, are converted to string.
  • Related