Skip to content

Commit 282da65

Browse files
enable biome check on examples (#225)
* enable biome check on examples * Reorder imports and update lefthook config Reordered import statements for consistency across multiple files and updated lefthook.yml to include examples directory in biome checks. Minor cleanup in code-interpreter and worker files for improved clarity.
1 parent b1a86c8 commit 282da65

File tree

11 files changed

+77
-38
lines changed

11 files changed

+77
-38
lines changed

biome.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
"ignoreUnknown": false,
1313
"includes": [
1414
"packages/**",
15+
"examples/**",
1516
"!node_modules",
1617
"!**/node_modules",
18+
"!**/worker-configuration.d.ts",
1719
"!package.json",
1820
"!**/package.json",
1921
"!dist",
@@ -56,6 +58,11 @@
5658
}
5759
}
5860
},
61+
"css": {
62+
"parser": {
63+
"tailwindDirectives": true
64+
}
65+
},
5966
"vcs": {
6067
"clientKind": "git",
6168
"enabled": false,

examples/code-interpreter/src/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import OpenAI from 'openai';
21
import { getSandbox } from '@cloudflare/sandbox';
2+
import type OpenAI from 'openai';
33

44
export { Sandbox } from '@cloudflare/sandbox';
55

@@ -11,12 +11,6 @@ type ResponseInputItem = OpenAI.Responses.ResponseInputItem;
1111
type FunctionTool = OpenAI.Responses.FunctionTool;
1212
type FunctionCall = OpenAI.Responses.ResponseFunctionToolCall;
1313

14-
interface SandboxResult {
15-
results?: Array<{ text?: string; html?: string; [key: string]: any }>;
16-
logs?: { stdout?: string[]; stderr?: string[] };
17-
error?: string;
18-
}
19-
2014
async function callCloudflareAPI(
2115
env: Env,
2216
input: ResponseInputItem[],
@@ -51,9 +45,9 @@ async function executePythonCode(env: Env, code: string): Promise<string> {
5145
const sandboxId = env.Sandbox.idFromName('default');
5246
const sandbox = getSandbox(env.Sandbox, sandboxId.toString());
5347
const pythonCtx = await sandbox.createCodeContext({ language: 'python' });
54-
const result = (await sandbox.runCode(code, {
48+
const result = await sandbox.runCode(code, {
5549
context: pythonCtx
56-
})) as SandboxResult;
50+
});
5751

5852
// Extract output from results (expressions)
5953
if (result.results?.length) {
@@ -70,7 +64,7 @@ async function executePythonCode(env: Env, code: string): Promise<string> {
7064
}
7165
if (result.logs?.stderr?.length) {
7266
if (output) output += '\n';
73-
output += 'Error: ' + result.logs.stderr.join('\n');
67+
output += `Error: ${result.logs.stderr.join('\n')}`;
7468
}
7569

7670
return result.error

examples/typescript-validator/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Use Cloudflare sandbox as base
22
FROM docker.io/cloudflare/sandbox:0.5.0
33

4+
# On a mac, you might need to actively pick up the
5+
# arm64 build of the image.
6+
# FROM --platform=linux/arm64 cloudflare/sandbox-test:0.5.0
7+
8+
49
# Install esbuild for TypeScript bundling
510
RUN npm install -g esbuild
611

examples/typescript-validator/src/App.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useState } from 'react';
2+
import CodeViewerSheet from './components/CodeViewerSheet';
3+
import CornerSquares from './components/CornerSquares';
4+
import FlowDiagram from './components/FlowDiagram';
25
import SchemaEditor from './components/SchemaEditor';
36
import TestDataPanel from './components/TestDataPanel';
4-
import FlowDiagram from './components/FlowDiagram';
5-
import CornerSquares from './components/CornerSquares';
6-
import CodeViewerSheet from './components/CodeViewerSheet';
7-
import type { ValidateResponse, ErrorResponse, StatusLine } from './types';
7+
import type { ErrorResponse, StatusLine, ValidateResponse } from './types';
88

99
const DEFAULT_SCHEMA = `import { z } from 'zod';
1010
@@ -69,7 +69,7 @@ export default function App() {
6969
return;
7070
}
7171

72-
let parsedTestData;
72+
let parsedTestData: unknown;
7373
try {
7474
parsedTestData = JSON.parse(trimmedTestData);
7575
} catch (error) {
@@ -182,12 +182,14 @@ export default function App() {
182182
</div>
183183
<div className="flex gap-3">
184184
<button
185+
type="button"
185186
onClick={() => setIsCodeViewerOpen(true)}
186187
className="bg-bg-cream hover:bg-bg-cream-dark text-text-dark border border-border-beige px-6 py-3 rounded-full font-medium text-sm transition-all duration-200 active:scale-[0.98]"
187188
>
188189
View Code
189190
</button>
190191
<button
192+
type="button"
191193
onClick={handleValidate}
192194
disabled={isValidating}
193195
className="bg-orange-primary hover:border-dashed disabled:bg-border-light disabled:cursor-not-allowed text-bg-cream border border-orange-primary px-6 py-3 rounded-full font-medium text-sm transition-all duration-200 active:scale-[0.98]"

examples/typescript-validator/src/components/CodeViewerSheet.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useState } from 'react';
21
import { Highlight, themes } from 'prism-react-renderer';
2+
import { useState } from 'react';
33

44
interface CodeViewerSheetProps {
55
isOpen: boolean;
@@ -84,6 +84,7 @@ const result = await response.json();`;
8484
<>
8585
{/* Backdrop */}
8686
{isOpen && (
87+
// biome-ignore lint/a11y/noStaticElementInteractions: backdrop is interactive
8788
<div
8889
className="fixed inset-0 bg-black/20 z-40 transition-opacity"
8990
onClick={onClose}
@@ -119,6 +120,7 @@ const result = await response.json();`;
119120
stroke="currentColor"
120121
viewBox="0 0 24 24"
121122
>
123+
<title>Sandbox SDK Docs</title>
122124
<path
123125
strokeLinecap="round"
124126
strokeLinejoin="round"
@@ -140,6 +142,7 @@ const result = await response.json();`;
140142
stroke="currentColor"
141143
viewBox="0 0 24 24"
142144
>
145+
<title>Dynamic Workers Docs</title>
143146
<path
144147
strokeLinecap="round"
145148
strokeLinejoin="round"
@@ -151,6 +154,7 @@ const result = await response.json();`;
151154
</div>
152155
</div>
153156
<button
157+
type="button"
154158
onClick={onClose}
155159
className="text-text-dark hover:text-orange-primary transition-colors"
156160
aria-label="Close"
@@ -161,6 +165,7 @@ const result = await response.json();`;
161165
stroke="currentColor"
162166
viewBox="0 0 24 24"
163167
>
168+
<title>Close</title>
164169
<path
165170
strokeLinecap="round"
166171
strokeLinejoin="round"
@@ -174,6 +179,7 @@ const result = await response.json();`;
174179
{/* Tabs */}
175180
<div className="flex border-b border-border-beige bg-bg-cream-dark">
176181
<button
182+
type="button"
177183
onClick={() => setActiveTab('compilation')}
178184
className={`px-6 py-3 text-sm font-medium transition-colors border-b-2 ${
179185
activeTab === 'compilation'
@@ -184,6 +190,7 @@ const result = await response.json();`;
184190
Compilation (Sandbox SDK)
185191
</button>
186192
<button
193+
type="button"
187194
onClick={() => setActiveTab('execution')}
188195
className={`px-6 py-3 text-sm font-medium transition-colors border-b-2 ${
189196
activeTab === 'execution'
@@ -210,9 +217,21 @@ const result = await response.json();`;
210217
style={{ ...style, backgroundColor: 'transparent' }}
211218
>
212219
{tokens.map((line, i) => (
213-
<div key={i} {...getLineProps({ line })}>
220+
<div
221+
key={
222+
// biome-ignore lint/suspicious/noArrayIndexKey: i is a valid prop
223+
i
224+
}
225+
{...getLineProps({ line })}
226+
>
214227
{line.map((token, key) => (
215-
<span key={key} {...getTokenProps({ token })} />
228+
<span
229+
key={
230+
// biome-ignore lint/suspicious/noArrayIndexKey: key is a valid prop
231+
key
232+
}
233+
{...getTokenProps({ token })}
234+
/>
216235
))}
217236
</div>
218237
))}

examples/typescript-validator/src/components/FlowDiagram.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from 'react';
2-
import DottedBackground from './DottedBackground';
32
import type { StatusLine } from '../types';
3+
import DottedBackground from './DottedBackground';
44

55
interface FlowDiagramProps {
66
statusLines: StatusLine[];
@@ -54,10 +54,10 @@ export default function FlowDiagram({ statusLines }: FlowDiagramProps) {
5454
const loadMatch = line.text.match(/Load.*?\((\d+)ms\)/);
5555
const executeMatch = line.text.match(/Execute.*?\((\d+)ms\)/);
5656

57-
if (installMatch) result.install = parseInt(installMatch[1]);
58-
if (bundleMatch) result.bundle = parseInt(bundleMatch[1]);
59-
if (loadMatch) result.load = parseInt(loadMatch[1]);
60-
if (executeMatch) result.execute = parseInt(executeMatch[1]);
57+
if (installMatch) result.install = parseInt(installMatch[1], 10);
58+
if (bundleMatch) result.bundle = parseInt(bundleMatch[1], 10);
59+
if (loadMatch) result.load = parseInt(loadMatch[1], 10);
60+
if (executeMatch) result.execute = parseInt(executeMatch[1], 10);
6161
});
6262

6363
return result;
@@ -123,9 +123,10 @@ export default function FlowDiagram({ statusLines }: FlowDiagramProps) {
123123
{/* Schema Node */}
124124
<div className="flex flex-col items-center">
125125
<div
126-
className={`w-24 h-24 rounded-sm border-2 border-dashed flex flex-col items-center justify-center gap-1 transition-all duration-300 ${schemaNodeDone ? 'border-[#521000] bg-[#5210000d]' : 'border-[#ebd5c1] bg-[#fffbf5]'}`}
126+
className={`w-24 h-24 rounded-sm border-2 border-dashed flex flex-col items-center justify-center gap-1 transition-all duration-300 ${schemaNodeDone ? 'border-text-dark bg-[#5210000d]' : 'border-border-beige bg-bg-cream'}`}
127127
>
128128
<svg className="w-8 h-8" viewBox="0 0 25 24" fill="none">
129+
<title>Schema</title>
129130
<path
130131
d="M9.87182 18.3256L5.14774 12.0072L9.84586 5.86857L8.93876 4.63086L3.64504 11.5551L3.6377 12.4407L8.95688 19.5633L9.87182 18.3256Z"
131132
fill="currentColor"
@@ -177,6 +178,7 @@ export default function FlowDiagram({ statusLines }: FlowDiagramProps) {
177178
className="absolute inset-0 w-full h-full"
178179
preserveAspectRatio="none"
179180
>
181+
<title>Connection</title>
180182
<line
181183
x1="0"
182184
y1="50%"
@@ -193,14 +195,15 @@ export default function FlowDiagram({ statusLines }: FlowDiagramProps) {
193195
{/* Sandbox Node */}
194196
<div className="flex flex-col items-center relative">
195197
{isCached && (
196-
<div className="absolute -top-6 left-1/2 -translate-x-1/2 bg-[#19e306] text-[#fffbf5] text-[9px] font-medium px-2 py-0.5 rounded-full whitespace-nowrap">
198+
<div className="absolute -top-6 left-1/2 -translate-x-1/2 bg-[#19e306] text-bg-cream text-[9px] font-medium px-2 py-0.5 rounded-full whitespace-nowrap">
197199
Cached ⚡
198200
</div>
199201
)}
200202
<div
201-
className={`w-24 h-24 rounded-sm border-2 border-dashed flex flex-col items-center justify-center gap-1 transition-all duration-300 ${sandboxNodeDone ? 'border-[#521000] bg-[#5210000d]' : 'border-[#ebd5c1] bg-[#fffbf5]'}`}
203+
className={`w-24 h-24 rounded-sm border-2 border-dashed flex flex-col items-center justify-center gap-1 transition-all duration-300 ${sandboxNodeDone ? 'border-text-dark bg-[#5210000d]' : 'border-border-beige bg-bg-cream'}`}
202204
>
203205
<svg className="w-8 h-8" viewBox="0 0 25 24" fill="none">
206+
<title>Sandbox SDK</title>
204207
<path
205208
d="M21.5 16.0018V7.99739C21.4997 7.73541 21.4308 7.47807 21.3001 7.25101C21.1694 7.02394 20.9815 6.83506 20.7552 6.70317L13.6302 2.55661C13.2869 2.35675 12.8968 2.25146 12.4995 2.25146C12.1023 2.25146 11.7122 2.35675 11.3689 2.55661L4.24484 6.70317C4.01848 6.83506 3.83061 7.02394 3.69993 7.25101C3.56925 7.47807 3.50032 7.73541 3.5 7.99739V16.0018C3.50016 16.2639 3.56901 16.5214 3.6997 16.7487C3.83038 16.9759 4.01834 17.1649 4.24484 17.2969L11.3698 21.4435C11.7132 21.6431 12.1033 21.7482 12.5005 21.7482C12.8976 21.7482 13.2877 21.6431 13.6311 21.4435L20.7561 17.2969C20.9824 17.1648 21.1702 16.9758 21.3007 16.7485C21.4312 16.5213 21.4999 16.2638 21.5 16.0018Z"
206209
stroke="currentColor"
@@ -241,6 +244,7 @@ export default function FlowDiagram({ statusLines }: FlowDiagramProps) {
241244
className="absolute inset-0 w-full h-full"
242245
preserveAspectRatio="none"
243246
>
247+
<title>Connection</title>
244248
<line
245249
x1="0"
246250
y1="50%"
@@ -257,9 +261,10 @@ export default function FlowDiagram({ statusLines }: FlowDiagramProps) {
257261
{/* Dynamic Worker Node */}
258262
<div className="flex flex-col items-center">
259263
<div
260-
className={`w-24 h-24 rounded-sm border-2 border-dashed flex flex-col items-center justify-center gap-1 transition-all duration-300 ${workerNodeDone ? 'border-[#521000] bg-[#5210000d]' : 'border-[#ebd5c1] bg-[#fffbf5]'}`}
264+
className={`w-24 h-24 rounded-sm border-2 border-dashed flex flex-col items-center justify-center gap-1 transition-all duration-300 ${workerNodeDone ? 'border-text-dark bg-[#5210000d]' : 'border-border-beige bg-bg-cream'}`}
261265
>
262266
<svg className="w-8 h-8" viewBox="0 0 25 24" fill="none">
267+
<title>Dynamic Worker</title>
263268
<path
264269
d="M9.87182 18.3256L5.14774 12.0072L9.84586 5.86857L8.93876 4.63086L3.64504 11.5551L3.6377 12.4407L8.95688 19.5633L9.87182 18.3256Z"
265270
fill="currentColor"
@@ -301,6 +306,7 @@ export default function FlowDiagram({ statusLines }: FlowDiagramProps) {
301306
className="absolute inset-0 w-full h-full"
302307
preserveAspectRatio="none"
303308
>
309+
<title>Connection</title>
304310
<line
305311
x1="0"
306312
y1="50%"
@@ -317,9 +323,10 @@ export default function FlowDiagram({ statusLines }: FlowDiagramProps) {
317323
{/* Result Node */}
318324
<div className="flex flex-col items-center">
319325
<div
320-
className={`w-24 h-24 rounded-sm border-2 border-dashed flex flex-col items-center justify-center gap-1 transition-all duration-300 ${resultNodeDone ? 'border-[#521000] bg-[#5210000d]' : 'border-[#ebd5c1] bg-[#fffbf5]'}`}
326+
className={`w-24 h-24 rounded-sm border-2 border-dashed flex flex-col items-center justify-center gap-1 transition-all duration-300 ${resultNodeDone ? 'border-text-dark bg-[#5210000d]' : 'border-border-beige bg-bg-cream'}`}
321327
>
322328
<svg className="w-8 h-8" viewBox="0 0 24 24" fill="none">
329+
<title>Result</title>
323330
<circle
324331
cx="12"
325332
cy="12"
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"lib": ["esnext"],
4+
"lib": ["esnext", "dom", "dom.iterable"],
55
"module": "esnext",
6+
"jsx": "react-jsx",
67
"moduleResolution": "bundler",
78
"types": ["@types/node", "./worker-configuration.d.ts"],
89
"esModuleInterop": true,
@@ -11,5 +12,10 @@
1112
"skipLibCheck": true,
1213
"noEmit": true
1314
},
14-
"include": ["worker-configuration.d.ts", "worker/**/*.ts", "src/**/*.ts"]
15+
"include": [
16+
"worker-configuration.d.ts",
17+
"worker/**/*.ts",
18+
"src/**/*.ts",
19+
"src/**/*.tsx"
20+
]
1521
}

examples/typescript-validator/vite.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { defineConfig } from 'vite';
2-
import react from '@vitejs/plugin-react';
3-
import tailwindcss from '@tailwindcss/vite';
41
import { cloudflare } from '@cloudflare/vite-plugin';
2+
import tailwindcss from '@tailwindcss/vite';
3+
import react from '@vitejs/plugin-react';
4+
import { defineConfig } from 'vite';
55

66
export default defineConfig({
77
plugins: [

examples/typescript-validator/worker/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { getSandbox } from '@cloudflare/sandbox';
22
import type {
3+
ErrorResponse,
34
ValidateRequest,
45
ValidateResponse,
5-
ErrorResponse,
66
ZodParseResult
77
} from './types';
88

examples/typescript-validator/worker/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export default {
2828
}
2929
} satisfies ExportedHandler<Env>;
3030

31-
// Export Compiler DO
32-
export { CompilerDO } from './compiler';
33-
3431
// Export Sandbox DO from SDK
3532
export { Sandbox } from '@cloudflare/sandbox';
33+
// Export Compiler DO
34+
export { CompilerDO } from './compiler';

0 commit comments

Comments
 (0)