From eca1b6ad4edbbdffa408430db3c39b28447a7ac3 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Thu, 19 Nov 2026 01:50:35 +0900 Subject: [PATCH] fix(benchmark): fit a last array of exactly 80 columns on one line formatJson counted a trailing comma after every array, so an array that ends its object and fills exactly 80 columns was split over lines while Prettier keeps it on one. main's refresh wrote such a row (devup-ui-large-turbo-wasm), and `bun run lint` rejects history.json again. The comma now counts only when one follows, and history.json is rewritten. Co-Authored-By: Claude Opus 5.5 --- benchmark-record.js | 5 +++-- benchmark/history.json | 4 +--- .../src/__tests__/benchmark-record.test.ts | 12 ++++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/benchmark-record.js b/benchmark-record.js index 2a25c9309..7e5f1e776 100644 --- a/benchmark-record.js +++ b/benchmark-record.js @@ -188,10 +188,11 @@ export function formatJson(value) { return ( JSON.stringify(value, null, 2).replace( /^( *)(.*)\[\n((?:\1 {2}(?:-?[\d.e+-]+|"[^"\n]*"|null),?\n)+)\1\]/gm, - (whole, indent, key, items) => { + (whole, indent, key, items, offset, json) => { const values = items.trim().split(/,\n */) const line = `${indent}${key}[${values.join(', ')}]` - if (line.length + 1 <= PRINT_WIDTH) return line + const comma = json[offset + whole.length] === ',' ? 1 : 0 + if (line.length + comma <= PRINT_WIDTH) return line return values.every((item) => /^-?[\d.e+-]+$/.test(item)) ? fillNumbers(indent, key, values) : whole diff --git a/benchmark/history.json b/benchmark/history.json index db1fcffce..79cc5f333 100644 --- a/benchmark/history.json +++ b/benchmark/history.json @@ -292,9 +292,7 @@ "devup-ui-large": [15.099, 15.029, 15.117, 88882994, 1388, 934329], "devup-ui-large-wasm": [16.233, 16.017, 16.28, 89000421, 1388, 934329], "devup-ui-large-turbo": [6.037, 5.938, 6.244, 38676786, 1512, 571629], - "devup-ui-large-turbo-wasm": [ - 6.5, 6.483, 6.542, 38662174, 1512, 571629 - ] + "devup-ui-large-turbo-wasm": [6.5, 6.483, 6.542, 38662174, 1512, 571629] } }, { diff --git a/packages/plugin-utils/src/__tests__/benchmark-record.test.ts b/packages/plugin-utils/src/__tests__/benchmark-record.test.ts index e7075a0e5..42d011ee8 100644 --- a/packages/plugin-utils/src/__tests__/benchmark-record.test.ts +++ b/packages/plugin-utils/src/__tests__/benchmark-record.test.ts @@ -411,6 +411,18 @@ describe('benchmark JSON', () => { ) }) + it('fits a last array of 80 columns on one line, as it takes no comma', () => { + // Exactly 80 columns, 81 when a comma follows + const values = [1.5, 2.25, 3.125, 38662174, 1512, 571629, 12345678, 1234] + const fits = { aaaaaaaaaaaaaaaa: values } + const split = { aaaaaaaaaaaaaaaa: values, b: 1 } + const line = ` "aaaaaaaaaaaaaaaa": [${values.join(', ')}]` + + expect(line).toHaveLength(80) + expect(formatJson(fits)).toBe(`{\n${line}\n}\n`) + expect(formatJson(split).split('\n')[1]).toBe(' "aaaaaaaaaaaaaaaa": [') + }) + it('formats the checked files exactly as it writes them', () => { for (const file of ['benchmark-results.json', 'benchmark/history.json']) { const text = readFileSync(join(ROOT, file), 'utf8').replaceAll(