build: switch to --use-color flag for clang-tidy (#34457)

chore: switch to --use-color flag for clang-tidy
This commit is contained in:
David Sanders 2022-06-07 00:49:52 -07:00 коммит произвёл GitHub
Родитель 882fa36940
Коммит 30d15715a9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 2 добавлений и 34 удалений

Просмотреть файл

@ -1,4 +1,3 @@
import chalk from 'chalk';
import * as childProcess from 'child_process';
import * as fs from 'fs';
import * as klaw from 'klaw';
@ -143,7 +142,7 @@ async function runClangTidy (
jobs: number = 1
): Promise<boolean> {
const cmd = path.resolve(LLVM_BIN, 'clang-tidy');
const args = [`-p=${outDir}`];
const args = [`-p=${outDir}`, '--use-color'];
if (checks) args.push(`--checks=${checks}`);
@ -202,38 +201,7 @@ async function runClangTidy (
while (filenames) {
results.push(
await spawnAsync(cmd, [...args, ...filenames], {}).then((result) => {
// We lost color, so recolorize because it's much more legible
// There's a --use-color flag for clang-tidy but it has no effect
// on Windows at the moment, so just recolor for everyone
let state = null;
for (const line of result.stdout.split('\n')) {
if (line.includes(' warning: ')) {
console.log(
line
.split(' warning: ')
.map((part) => chalk.whiteBright(part))
.join(chalk.magentaBright(' warning: '))
);
state = 'code-line';
} else if (line.includes(' note: ')) {
const lineParts = line.split(' note: ');
lineParts[0] = chalk.whiteBright(lineParts[0]);
console.log(lineParts.join(chalk.grey(' note: ')));
state = 'code-line';
} else if (line.startsWith('error:')) {
console.log(
chalk.redBright('error: ') + line.split(' ').slice(1).join(' ')
);
} else if (state === 'code-line') {
console.log(line);
state = 'post-code-line';
} else if (state === 'post-code-line') {
console.log(chalk.greenBright(line));
} else {
console.log(line);
}
}
console.log(result.stdout);
if (result.status !== 0) {
console.error(result.stderr);