From ea334284aacfc00507224069a72e5b11b7014b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Lajtman?= Date: Wed, 2 Mar 2022 16:57:08 +0100 Subject: [PATCH] fix(misc): format:check not checking all affected files (#9152) --- packages/workspace/src/command-line/format.ts | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/workspace/src/command-line/format.ts b/packages/workspace/src/command-line/format.ts index 5060b3cb6467b..4295104bf29e9 100644 --- a/packages/workspace/src/command-line/format.ts +++ b/packages/workspace/src/command-line/format.ts @@ -49,7 +49,13 @@ export async function format( chunkList.forEach((chunk) => write(chunk)); break; case 'check': - chunkList.forEach((chunk) => check(chunk)); + const pass = chunkList.reduce( + (pass, chunk) => check(chunk) && pass, + true + ); + if (!pass) { + process.exit(1); + } break; } } @@ -142,18 +148,17 @@ function write(patterns: string[]) { } } -function check(patterns: string[]) { - if (patterns.length > 0) { - try { - execSync( - `node "${PRETTIER_PATH}" --list-different ${patterns.join(' ')}`, - { - stdio: [0, 1, 2], - } - ); - } catch { - process.exit(1); - } +function check(patterns: string[]): boolean { + if (patterns.length === 0) { + return true; + } + try { + execSync(`node "${PRETTIER_PATH}" --list-different ${patterns.join(' ')}`, { + stdio: [0, 1, 2], + }); + return true; + } catch { + return false; } }