From d1b8dd977f7fa7cd8fe6b6289455f35f8ed636fe Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Fri, 10 Jul 2026 00:32:51 +0000 Subject: [PATCH] [Refactor] Use flatMap for flattening TOML patch entries Refactor flattenToPatchEntries in toml-file.ts to use a declarative flatMap approach instead of an imperative for...of loop with entries.push to improve code idiom and readability. --- packages/cli-kit/src/public/node/toml/toml-file.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/cli-kit/src/public/node/toml/toml-file.ts b/packages/cli-kit/src/public/node/toml/toml-file.ts index a2ee81b3236..f5a2794f7ac 100644 --- a/packages/cli-kit/src/public/node/toml/toml-file.ts +++ b/packages/cli-kit/src/public/node/toml/toml-file.ts @@ -160,14 +160,11 @@ export class TomlFile { * @returns Flattened patch entries. */ function flattenToPatchEntries(obj: {[key: string]: unknown}, prefix: string[] = []): [string[], TomlPatchValue][] { - const entries: [string[], TomlPatchValue][] = [] - for (const [key, value] of Object.entries(obj)) { + return Object.entries(obj).flatMap(([key, value]) => { const path = [...prefix, key] if (value !== null && typeof value === 'object' && !Array.isArray(value)) { - entries.push(...flattenToPatchEntries(value as {[key: string]: unknown}, path)) - } else { - entries.push([path, value as TomlPatchValue]) + return flattenToPatchEntries(value as {[key: string]: unknown}, path) } - } - return entries + return [[path, value as TomlPatchValue]] + }) }