Skip to content

Commit 61ee878

Browse files
committed
biome
1 parent 380065e commit 61ee878

28 files changed

+270
-235
lines changed

PROJECT.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ Woohoo
205205

206206
## Implementation phase 13
207207

208-
- Block `return await` with biome
209208
- Do we handle stop of execution in multi-line script for non-zero return values?
210209

211210
## Implementation phase 14
@@ -214,3 +213,7 @@ Woohoo
214213
- Search the web for official grammars and use an existing npm package for parsing the grammer and the input
215214
- Further extend composition tests
216215
- Start by writing `real-parser.md` and then confirm further work.
216+
217+
## Implementation phase 15
218+
219+
- Implement set -e

src/BashEnv.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ import { createLazyCommands } from "./commands/registry.js";
22
import { type IFileSystem, VirtualFs } from "./fs.js";
33
import type { InitialFiles } from "./fs-interface.js";
44
import {
5-
executeIfStatement,
5+
type BuiltinContext,
6+
evaluateTopLevelTest,
7+
executeCaseStatement,
68
executeForLoop,
7-
executeWhileLoop,
9+
executeIfStatement,
810
executeUntilLoop,
9-
executeCaseStatement,
10-
evaluateTopLevelTest,
11+
executeWhileLoop,
1112
executeWithHereDoc,
1213
expandVariablesAsync,
14+
type HereDocContext,
1315
handleCd,
16+
handleExit,
1417
handleExport,
15-
handleUnset,
1618
handleLocal,
17-
handleExit,
18-
handleVariableAssignment,
1919
handleTestExpression,
20+
handleUnset,
21+
handleVariableAssignment,
2022
type InterpreterContext,
21-
type HereDocContext,
22-
type BuiltinContext,
2323
} from "./interpreter/index.js";
2424
import {
2525
GlobExpander,
@@ -743,7 +743,10 @@ export class BashEnv {
743743

744744
// Handle [[ ]] test expressions
745745
if (expandedCommand === "[[") {
746-
return await handleTestExpression(expandedArgs, this.getInterpreterContext());
746+
return await handleTestExpression(
747+
expandedArgs,
748+
this.getInterpreterContext(),
749+
);
747750
}
748751

749752
// Handle variable assignment: VAR=value (no args, command contains =)

src/agent-examples/codebase-exploration.test.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,45 @@ describe("Agent Scenario: Disk Usage Analysis with ls -h and du -h", () => {
185185
files: {
186186
// Small config files
187187
"/project/package.json": { content: '{"name": "app"}', mode: 0o644 },
188-
"/project/tsconfig.json": { content: '{"target": "es2020"}', mode: 0o644 },
188+
"/project/tsconfig.json": {
189+
content: '{"target": "es2020"}',
190+
mode: 0o644,
191+
},
189192
// Source files of varying sizes
190193
"/project/src/index.ts": { content: "a".repeat(500), mode: 0o644 },
191194
"/project/src/utils.ts": { content: "b".repeat(2 * 1024), mode: 0o644 }, // 2K
192195
"/project/src/api.ts": { content: "c".repeat(5 * 1024), mode: 0o644 }, // 5K
193196
// Large build artifacts
194-
"/project/dist/bundle.js": { content: "d".repeat(150 * 1024), mode: 0o644 }, // 150K
195-
"/project/dist/bundle.js.map": { content: "e".repeat(300 * 1024), mode: 0o644 }, // 300K
197+
"/project/dist/bundle.js": {
198+
content: "d".repeat(150 * 1024),
199+
mode: 0o644,
200+
}, // 150K
201+
"/project/dist/bundle.js.map": {
202+
content: "e".repeat(300 * 1024),
203+
mode: 0o644,
204+
}, // 300K
196205
// Node modules simulation
197-
"/project/node_modules/lodash/index.js": { content: "f".repeat(500 * 1024), mode: 0o644 }, // 500K
198-
"/project/node_modules/lodash/package.json": { content: '{"name": "lodash"}', mode: 0o644 },
199-
"/project/node_modules/express/index.js": { content: "g".repeat(200 * 1024), mode: 0o644 }, // 200K
206+
"/project/node_modules/lodash/index.js": {
207+
content: "f".repeat(500 * 1024),
208+
mode: 0o644,
209+
}, // 500K
210+
"/project/node_modules/lodash/package.json": {
211+
content: '{"name": "lodash"}',
212+
mode: 0o644,
213+
},
214+
"/project/node_modules/express/index.js": {
215+
content: "g".repeat(200 * 1024),
216+
mode: 0o644,
217+
}, // 200K
200218
// Log files
201-
"/project/logs/app.log": { content: "h".repeat(1024 * 1024), mode: 0o644 }, // 1M
202-
"/project/logs/error.log": { content: "i".repeat(50 * 1024), mode: 0o644 }, // 50K
219+
"/project/logs/app.log": {
220+
content: "h".repeat(1024 * 1024),
221+
mode: 0o644,
222+
}, // 1M
223+
"/project/logs/error.log": {
224+
content: "i".repeat(50 * 1024),
225+
mode: 0o644,
226+
}, // 50K
203227
},
204228
cwd: "/project",
205229
});

src/agent-examples/refactoring-workflow.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,7 @@ fifth line`,
388388
it("should convert single imports to barrel export", async () => {
389389
const env = createAdvancedEnv();
390390
// Transform import to export (simpler pattern)
391-
const result = await env.exec(
392-
"sed 's/import/export/' /code/imports.ts",
393-
);
391+
const result = await env.exec("sed 's/import/export/' /code/imports.ts");
394392
expect(result.stdout).toContain("export { foo }");
395393
expect(result.stdout).toContain("export { bar }");
396394
expect(result.exitCode).toBe(0);
@@ -399,9 +397,7 @@ fifth line`,
399397
it("should find functions that need documentation", async () => {
400398
const env = createAdvancedEnv();
401399
// Find function declarations that could use JSDoc
402-
const result = await env.exec(
403-
"grep -n '^function' /code/deprecated.ts",
404-
);
400+
const result = await env.exec("grep -n '^function' /code/deprecated.ts");
405401
expect(result.stdout).toContain("function oldFunc");
406402
expect(result.stdout).toContain("function activeFunc");
407403
expect(result.exitCode).toBe(0);

src/agent-examples/security-audit.test.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,27 @@ describe("Agent Scenario: File Permission Audit with find -perm", () => {
274274
const createPermEnv = () =>
275275
new BashEnv({
276276
files: {
277-
"/server/bin/start.sh": { content: "#!/bin/bash\nnode app.js", mode: 0o755 },
278-
"/server/bin/deploy.sh": { content: "#!/bin/bash\n# deploy script", mode: 0o755 },
279-
"/server/bin/backup.sh": { content: "#!/bin/bash\n# backup", mode: 0o700 },
277+
"/server/bin/start.sh": {
278+
content: "#!/bin/bash\nnode app.js",
279+
mode: 0o755,
280+
},
281+
"/server/bin/deploy.sh": {
282+
content: "#!/bin/bash\n# deploy script",
283+
mode: 0o755,
284+
},
285+
"/server/bin/backup.sh": {
286+
content: "#!/bin/bash\n# backup",
287+
mode: 0o700,
288+
},
280289
"/server/config/app.json": { content: '{"port": 3000}', mode: 0o644 },
281-
"/server/config/secrets.json": { content: '{"key": "secret"}', mode: 0o600 },
282-
"/server/config/db.json": { content: '{"host": "localhost"}', mode: 0o644 },
290+
"/server/config/secrets.json": {
291+
content: '{"key": "secret"}',
292+
mode: 0o600,
293+
},
294+
"/server/config/db.json": {
295+
content: '{"host": "localhost"}',
296+
mode: 0o644,
297+
},
283298
"/server/logs/app.log": { content: "log data", mode: 0o644 },
284299
"/server/logs/error.log": { content: "errors", mode: 0o644 },
285300
"/server/data/users.db": { content: "user data", mode: 0o600 },

src/agent-examples/text-processing-workflows.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ END_RECORD`,
698698
"awk '/ERROR BLOCK START/,/ERROR BLOCK END/ { count++ } END { print count }' /logs/server.log",
699699
);
700700
// Two blocks, 5 lines each (START + error + stack + 2 traces + END)
701-
expect(parseInt(result.stdout.trim())).toBeGreaterThan(8);
701+
expect(parseInt(result.stdout.trim(), 10)).toBeGreaterThan(8);
702702
expect(result.exitCode).toBe(0);
703703
});
704704
});
@@ -718,9 +718,7 @@ END_RECORD`,
718718

719719
it("should extract cache settings", async () => {
720720
const env = createLogEnv();
721-
const result = await env.exec(
722-
"grep -A3 '\\[cache\\]' /logs/config.ini",
723-
);
721+
const result = await env.exec("grep -A3 '\\[cache\\]' /logs/config.ini");
724722
expect(result.stdout).toContain("[cache]");
725723
expect(result.stdout).toContain("enabled=true");
726724
expect(result.stdout).toContain("ttl=3600");
@@ -732,9 +730,11 @@ END_RECORD`,
732730
it("should combine record fields using getline", async () => {
733731
const env = createLogEnv();
734732
const result = await env.exec(
735-
"awk '/^RECORD:/ { id=$2; getline; split($0,a,\": \"); name=a[2]; getline; split($0,b,\": \"); email=b[2]; print id, name, email }' /data/records.txt",
733+
'awk \'/^RECORD:/ { id=$2; getline; split($0,a,": "); name=a[2]; getline; split($0,b,": "); email=b[2]; print id, name, email }\' /data/records.txt',
734+
);
735+
expect(result.stdout).toContain(
736+
"user001 Alice Johnson alice@example.com",
736737
);
737-
expect(result.stdout).toContain("user001 Alice Johnson alice@example.com");
738738
expect(result.stdout).toContain("user002 Bob Smith bob@example.com");
739739
expect(result.exitCode).toBe(0);
740740
});
@@ -895,7 +895,7 @@ Stack trace follows...`,
895895
it("should sanitize for SQL safety (remove quotes)", async () => {
896896
const env = createSanitizeEnv();
897897
const result = await env.exec(
898-
"echo \"user'; DROP TABLE users;--\" | tr -d \"';\"",
898+
'echo "user\'; DROP TABLE users;--" | tr -d "\';"',
899899
);
900900
expect(result.stdout).not.toContain("'");
901901
expect(result.stdout).not.toContain(";");

src/commands/awk/awk.math.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ describe("awk math functions", () => {
7676

7777
it("srand() can be called with a seed", async () => {
7878
const env = new BashEnv();
79-
const result = await env.exec("echo '' | awk '{ srand(42); print rand() }'");
79+
const result = await env.exec(
80+
"echo '' | awk '{ srand(42); print rand() }'",
81+
);
8082
const value = parseFloat(result.stdout.trim());
8183
expect(value).toBeGreaterThanOrEqual(0);
8284
expect(value).toBeLessThan(1);

src/commands/awk/executor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,9 @@ function handleGetline(stmt: string, ctx: AwkContext): string {
576576
if (stmt === "getline") {
577577
// Read into $0
578578
ctx.line = nextLine;
579-
ctx.fields = ctx.fieldSep ? nextLine.split(ctx.fieldSep) : nextLine.split(/\s+/);
579+
ctx.fields = ctx.fieldSep
580+
? nextLine.split(ctx.fieldSep)
581+
: nextLine.split(/\s+/);
580582
ctx.NF = ctx.fields.length;
581583
ctx.NR++;
582584
ctx.lineIndex = nextLineIndex;

src/commands/awk/expressions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ export function evaluateExpression(
7070
case "srand": {
7171
// In real awk, srand() seeds the random number generator
7272
// We'll just return a value and the random will work with Math.random()
73-
const seed = args.length > 0 ? Number(evaluateExpression(args[0], ctx)) : Date.now();
73+
const seed =
74+
args.length > 0
75+
? Number(evaluateExpression(args[0], ctx))
76+
: Date.now();
7477
// Store seed for reference (doesn't actually change behavior)
75-
ctx.vars["_srand_seed"] = seed;
78+
ctx.vars._srand_seed = seed;
7679
return seed;
7780
}
7881
}

src/commands/awk/parser.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export function parseAwkProgram(program: string): ParsedProgram {
4848
}
4949
} else {
5050
// Pattern range { action }: /start/,/end/ { action }
51-
const rangeAction = remaining.match(/^\/([^/]*)\/\s*,\s*\/([^/]*)\/\s*\{/);
51+
const rangeAction = remaining.match(
52+
/^\/([^/]*)\/\s*,\s*\/([^/]*)\/\s*\{/,
53+
);
5254
if (rangeAction) {
5355
const actionStart = remaining.indexOf("{");
5456
const endBrace = findMatchingBrace(remaining, actionStart);
@@ -97,7 +99,10 @@ export function parseAwkProgram(program: string): ParsedProgram {
9799
}
98100
} else {
99101
// Condition only (no action) or just a print expression
100-
if (remaining.startsWith("print") || remaining.startsWith("printf")) {
102+
if (
103+
remaining.startsWith("print") ||
104+
remaining.startsWith("printf")
105+
) {
101106
result.main.push({ pattern: null, action: remaining });
102107
} else {
103108
// It's a condition without action - default to print

0 commit comments

Comments
 (0)