Skip to content

Commit f0aa114

Browse files
committed
chore(config): add biome lint tooling
1 parent 15ea7b0 commit f0aa114

6 files changed

Lines changed: 71 additions & 9 deletions

File tree

biome.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.4.7/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"formatter": {
9+
"enabled": true,
10+
"indentStyle": "space"
11+
},
12+
"linter": {
13+
"enabled": true,
14+
"rules": {
15+
"recommended": true
16+
}
17+
},
18+
"javascript": {
19+
"formatter": {
20+
"quoteStyle": "double",
21+
"semicolons": "always"
22+
}
23+
}
24+
}

bun.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
"scripts": {
4646
"bench": "bun scripts/benchmark-json-detection.ts",
4747
"build": "tsc -p tsconfig.json",
48+
"format": "biome check --write .",
49+
"lint": "biome check .",
4850
"prepublishOnly": "bun audit && bun run test && bun run build",
4951
"release": "bun run typecheck && bunx bumpp && bun publish --access public",
5052
"test": "bun test --passWithNoTests",
@@ -54,6 +56,7 @@
5456
"@toon-format/toon": "^2.1.0"
5557
},
5658
"devDependencies": {
59+
"@biomejs/biome": "^2.4.7",
5760
"@opencode-ai/plugin": "*",
5861
"@types/node": "^24.5.2",
5962
"bumpp": "^10.2.3",

scripts/benchmark-json-detection.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function makeJsonLookingGarbage(rng: () => number) {
168168
() => `${randomWord(rng, 3, 8)}:${randomWord(rng, 3, 12)}`,
169169
).join(",");
170170

171-
return `{${inner}`.padEnd(MIN_LENGTH + 40, "!") + "}";
171+
return `${`{${inner}`.padEnd(MIN_LENGTH + 40, "!")}}`;
172172
}
173173

174174
function sampleDataset(kind: "mostly-non-json" | "mixed" | "mostly-json") {
@@ -242,14 +242,20 @@ function formatPercent(value: number) {
242242

243243
function runToonBenchmark(name: string, dataset: string[]) {
244244
const results = [
245-
summarizeToonVariant(TOON_BASELINE_LABEL, (parsed) => encode(parsed), dataset),
245+
summarizeToonVariant(
246+
TOON_BASELINE_LABEL,
247+
(parsed) => encode(parsed),
248+
dataset,
249+
),
246250
summarizeToonVariant(
247251
TOON_VARIANT_LABEL,
248252
(parsed) => encode(parsed, TOON_VARIANT_OPTIONS),
249253
dataset,
250254
),
251255
];
252-
const baseline = results[0]!;
256+
const [baseline] = results;
257+
258+
if (!baseline) return;
253259

254260
console.log(`TOON benchmark: ${name}`);
255261
for (const result of results) {
@@ -262,7 +268,8 @@ function runToonBenchmark(name: string, dataset: string[]) {
262268
const timeDelta =
263269
baseline.durationMs === 0
264270
? 0
265-
: ((result.durationMs - baseline.durationMs) / baseline.durationMs) * 100;
271+
: ((result.durationMs - baseline.durationMs) / baseline.durationMs) *
272+
100;
266273

267274
console.log(
268275
`${result.name}: ${result.durationMs.toFixed(2)}ms, ${result.shorterCount}/${result.encodedCount} shorter, total chars ${result.totalOutputLength}${result === baseline ? "" : ` | size delta: ${formatPercent(sizeDelta)} | time delta: ${formatPercent(timeDelta)}`}`,
@@ -309,7 +316,9 @@ for (const scenario of ["mostly-non-json", "mixed", "mostly-json"] as const) {
309316
benchmark("trim-guarded-parse-charcode", guardedParseCharCode, dataset),
310317
benchmark("bounds-guarded-parse", boundsGuardedParse, dataset),
311318
];
312-
const baseline = results[0]!;
319+
const [baseline] = results;
320+
321+
if (!baseline) continue;
313322

314323
console.log(`\nScenario: ${scenario}`);
315324
for (const result of results) {
@@ -328,7 +337,9 @@ for (const scenario of ["mostly-non-json", "mixed", "mostly-json"] as const) {
328337
dataset,
329338
),
330339
];
331-
const looksLikeJsonBaseline = looksLikeJsonResults[0]!;
340+
const [looksLikeJsonBaseline] = looksLikeJsonResults;
341+
342+
if (!looksLikeJsonBaseline) continue;
332343

333344
console.log("looksLikeJson only:");
334345
for (const result of looksLikeJsonResults) {
@@ -344,7 +355,9 @@ for (const scenario of ["mostly-non-json", "mixed", "mostly-json"] as const) {
344355

345356
const toonDatasets = {
346357
tabular: Array.from({ length: 20 }, () => makeLongJson(createRng(101))),
347-
nested: Array.from({ length: 20 }, () => makeNestedWrapperJson(createRng(202))),
358+
nested: Array.from({ length: 20 }, () =>
359+
makeNestedWrapperJson(createRng(202)),
360+
),
348361
mixed: Array.from({ length: 10 }, () => makeLongJson(createRng(303))).concat(
349362
Array.from({ length: 10 }, () => makeNestedWrapperJson(createRng(404))),
350363
),

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { encode } from "@toon-format/toon";
21
import type { Plugin } from "@opencode-ai/plugin";
2+
import { encode } from "@toon-format/toon";
33

44
const DEFAULT_ELIGIBLE_TOOLS = ["bash"];
55
const TOON_OPTIONS = {

test/plugin.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import test from "node:test";
33

44
import ToonPlugin from "../src/index";
55

6-
const LONG_JSON = JSON.stringify({ hello: "world", items: Array.from({ length: 80 }, (_, i) => i) });
6+
const LONG_JSON = JSON.stringify({
7+
hello: "world",
8+
items: Array.from({ length: 80 }, (_, i) => i),
9+
});
710

811
function createOutput() {
912
return {

0 commit comments

Comments
 (0)