From 981df181c13170627f8ed272f71e072730d3b9bf Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 9 Jan 2026 14:43:00 -0600 Subject: [PATCH] chore: improvements to script/run-clang-tidy.ts (#49341) * chore: disable color output for clang-tidy in CI Co-authored-by: David Sanders * chore: small QoL improvements to run-clang-tidy.ts Co-authored-by: David Sanders * chore: add --fix option to script/run-clang-tidy.ts Co-authored-by: David Sanders --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: David Sanders --- script/run-clang-tidy.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/script/run-clang-tidy.ts b/script/run-clang-tidy.ts index b4a544da2e..ea8a0a0bf7 100644 --- a/script/run-clang-tidy.ts +++ b/script/run-clang-tidy.ts @@ -114,11 +114,14 @@ async function runClangTidy ( outDir: string, filenames: string[], checks: string = '', - jobs: number = 1 + jobs: number = 1, + fix: boolean = false ): Promise { const cmd = path.resolve(LLVM_BIN, 'clang-tidy'); - const args = [`-p=${outDir}`, '--use-color']; + const args = [`-p=${outDir}`]; + if (!process.env.CI) args.push('--use-color'); + if (fix) args.push('--fix'); if (checks) args.push(`--checks=${checks}`); // Remove any files that aren't in the compilation database to prevent @@ -209,7 +212,7 @@ function parseCommandLine () { if (!arg || arg.startsWith('-')) { console.log( 'Usage: script/run-clang-tidy.ts [-h|--help] [--jobs|-j] ' + - '[--checks] --out-dir OUTDIR [file1 file2]' + '[--fix] [--checks] --out-dir OUTDIR [file1 file2]' ); process.exit(0); } @@ -218,7 +221,7 @@ function parseCommandLine () { }; const opts = minimist(process.argv.slice(2), { - boolean: ['help'], + boolean: ['fix', 'help'], string: ['checks', 'out-dir'], default: { jobs: 1 }, alias: { help: 'h', jobs: 'j' }, @@ -270,17 +273,23 @@ async function main (): Promise { const filenames = []; if (opts._.length > 0) { + if (opts._.some((filename) => filename.endsWith('.h'))) { + throw new ErrorWithExitCode( + 'Filenames must be for translation units, not headers', 3 + ); + } + filenames.push(...opts._.map((filename) => path.resolve(filename))); } else { filenames.push( ...(await findMatchingFiles( path.resolve(SOURCE_ROOT, 'shell'), - (filename: string) => /.*\.(?:cc|h|mm)$/.test(filename) + (filename: string) => /.*\.(?:cc|mm)$/.test(filename) )) ); } - return runClangTidy(outDir, filenames, opts.checks, opts.jobs); + return runClangTidy(outDir, filenames, opts.checks, opts.jobs, opts.fix); } if (require.main === module) {