Skip to content

Commit a488715

Browse files
committed
fix: biome issues
1 parent 9954345 commit a488715

16 files changed

Lines changed: 272 additions & 147 deletions

biome.json

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@
44
"linter": {
55
"enabled": true,
66
"rules": {
7-
"recommended": true
7+
"recommended": true,
8+
"suspicious": {
9+
"noTemplateCurlyInString": "off"
10+
}
811
},
9-
"includes": ["**", "!**/dist/**", "!**/node_modules/**", "!**/.turbo/**"]
12+
"includes": [
13+
"**",
14+
"!**/dist/**",
15+
"!**/node_modules/**",
16+
"!**/.turbo/**",
17+
"!**/generated/**",
18+
"!**/coverage/**"
19+
]
1020
},
1121
"formatter": {
1222
"enabled": true,
1323
"indentStyle": "space",
1424
"indentWidth": 2,
15-
"includes": ["**", "!**/dist/**", "!**/node_modules/**"]
25+
"includes": [
26+
"**",
27+
"!**/dist/**",
28+
"!**/node_modules/**",
29+
"!**/.turbo/**",
30+
"!**/generated/**",
31+
"!**/coverage/**"
32+
]
1633
},
1734
"javascript": {
1835
"formatter": {

packages/lib/src/__tests__/multi-tab-support.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
22
import { Workerify } from '../index.js';
3-
import type { BroadcastMessage } from '../types.js';
43

54
// Mock fetch for registration
65
global.fetch = vi.fn();
@@ -41,9 +40,11 @@ class MockBroadcastChannel {
4140
}
4241

4342
// Helper to simulate receiving a message
44-
simulateMessage(data: any) {
43+
simulateMessage(data: unknown) {
4544
const event = new MessageEvent('message', { data });
46-
this.listeners.get('message')?.forEach((listener) => listener(event));
45+
this.listeners.get('message')?.forEach((listener) => {
46+
listener(event);
47+
});
4748
}
4849
}
4950

@@ -58,7 +59,9 @@ describe('Multi-tab Support', () => {
5859
vi.clearAllMocks();
5960
mockFetch = global.fetch as ReturnType<typeof vi.fn>;
6061
// Mock location for proper URL
61-
global.location = { origin: 'http://localhost:3000' } as any;
62+
global.location = {
63+
origin: 'http://localhost:3000',
64+
} as unknown as Location;
6265
workerify = new Workerify({ logger: false });
6366
});
6467

@@ -71,9 +74,9 @@ describe('Multi-tab Support', () => {
7174
const instance1 = new Workerify({ logger: false });
7275
const instance2 = new Workerify({ logger: false });
7376

74-
// Access private property through any cast
75-
const consumerId1 = (instance1 as any).consumerId;
76-
const consumerId2 = (instance2 as any).consumerId;
77+
// Access private property through type assertion
78+
const consumerId1 = (instance1 as { consumerId: string }).consumerId;
79+
const consumerId2 = (instance2 as { consumerId: string }).consumerId;
7780

7881
expect(consumerId1).toBeDefined();
7982
expect(consumerId2).toBeDefined();

packages/lib/src/__tests__/plugins.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ describe('Plugin System', () => {
241241
options;
242242

243243
// Add OPTIONS handler for preflight
244-
app.option('/*', (req, reply) => {
244+
app.option('/*', (_req, reply) => {
245245
reply.headers = {
246246
'Access-Control-Allow-Origin': origin.join(', '),
247247
'Access-Control-Allow-Methods': methods.join(', '),
@@ -270,7 +270,7 @@ describe('Plugin System', () => {
270270
const loggingPlugin: WorkerifyPlugin = (app) => {
271271
// In a real implementation, this would intercept requests
272272
// For testing, we'll just add a route that logs
273-
app.all('/logged/*', (req, reply) => {
273+
app.all('/logged/*', (req, _reply) => {
274274
logs.push(`${req.method} ${req.url}`);
275275
return { logged: true };
276276
});
@@ -295,7 +295,7 @@ describe('Plugin System', () => {
295295
const { secret, protected: protectedRoutes } = options;
296296

297297
// Add auth route
298-
app.post('/auth/login', (req) => {
298+
app.post('/auth/login', (_req) => {
299299
// Simulate authentication
300300
return { token: 'fake-jwt-token', secret };
301301
});

packages/lib/src/__tests__/request-handling.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
22
import { Workerify } from '../index.js';
3-
import type { WorkerifyReply, WorkerifyRequest } from '../types.js';
3+
import type { WorkerifyReply } from '../types.js';
44
import {
5-
createMockReply,
65
createMockRequest,
76
setupBroadcastChannelMock,
87
stringToArrayBuffer,
9-
waitForAsync,
108
} from './test-utils.js';
119

1210
// Setup mocks
@@ -273,7 +271,7 @@ describe('Request Handling', () => {
273271
});
274272

275273
it('should allow handlers to modify reply object', async () => {
276-
const handler = vi.fn().mockImplementation((req, reply) => {
274+
const handler = vi.fn().mockImplementation((_req, reply) => {
277275
reply.status = 201;
278276
reply.statusText = 'Created';
279277
reply.headers = { 'X-Custom': 'value' };
@@ -445,7 +443,7 @@ describe('Request Handling', () => {
445443

446444
describe('BroadcastChannel response sending', () => {
447445
it('should send response via BroadcastChannel', () => {
448-
const postMessage = vi.spyOn(workerify['channel'], 'postMessage');
446+
const postMessage = vi.spyOn(workerify.channel, 'postMessage');
449447
const sendResponse = (workerify as any).sendResponse.bind(workerify);
450448

451449
const reply: WorkerifyReply = {

packages/lib/src/__tests__/test-utils.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import type { WorkerifyReply, WorkerifyRequest } from '../types.js';
22

33
// Mock BroadcastChannel for testing
44
export class MockBroadcastChannel {
5-
private listeners: Array<(event: { data: any }) => void> = [];
5+
private listeners: Array<(event: { data: unknown }) => void> = [];
66
name: string;
77

88
constructor(name: string) {
99
this.name = name;
1010
}
1111

12-
postMessage(data: any) {
12+
postMessage(data: unknown) {
1313
// Simulate async message delivery
1414
setTimeout(() => {
1515
this.listeners.forEach((listener) => {
@@ -18,13 +18,16 @@ export class MockBroadcastChannel {
1818
}, 0);
1919
}
2020

21-
addEventListener(type: string, listener: (event: { data: any }) => void) {
21+
addEventListener(type: string, listener: (event: { data: unknown }) => void) {
2222
if (type === 'message') {
2323
this.listeners.push(listener);
2424
}
2525
}
2626

27-
removeEventListener(type: string, listener: (event: { data: any }) => void) {
27+
removeEventListener(
28+
type: string,
29+
listener: (event: { data: unknown }) => void,
30+
) {
2831
if (type === 'message') {
2932
const index = this.listeners.indexOf(listener);
3033
if (index > -1) {
@@ -37,7 +40,7 @@ export class MockBroadcastChannel {
3740
this.listeners = [];
3841
}
3942

40-
set onmessage(handler: ((event: { data: any }) => void) | null) {
43+
set onmessage(handler: ((event: { data: unknown }) => void) | null) {
4144
if (handler) {
4245
this.addEventListener('message', handler);
4346
}
@@ -53,7 +56,14 @@ export function createMockRequest(
5356
): WorkerifyRequest {
5457
return {
5558
url,
56-
method: method as any,
59+
method: method as
60+
| 'GET'
61+
| 'POST'
62+
| 'PUT'
63+
| 'DELETE'
64+
| 'PATCH'
65+
| 'HEAD'
66+
| 'OPTIONS',
5767
headers: {
5868
'user-agent': 'test',
5969
...headers,

packages/lib/src/__tests__/types.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,23 @@ describe('Type Definitions', () => {
123123

124124
describe('RouteHandler', () => {
125125
it('should support synchronous handlers', () => {
126-
const handler: RouteHandler = (request, reply) => {
126+
const handler: RouteHandler = (_request, _reply) => {
127127
return 'sync response';
128128
};
129129

130130
expect(typeof handler).toBe('function');
131131
});
132132

133133
it('should support asynchronous handlers', () => {
134-
const handler: RouteHandler = async (request, reply) => {
134+
const handler: RouteHandler = async (_request, _reply) => {
135135
return Promise.resolve('async response');
136136
};
137137

138138
expect(typeof handler).toBe('function');
139139
});
140140

141141
it('should support handlers that return void', () => {
142-
const handler: RouteHandler = (request, reply) => {
142+
const handler: RouteHandler = (_request, reply) => {
143143
reply.status = 200;
144144
reply.body = 'modified reply';
145145
// No return value
@@ -305,15 +305,15 @@ describe('Type Definitions', () => {
305305

306306
describe('WorkerifyPlugin', () => {
307307
it('should support synchronous plugin', () => {
308-
const plugin: WorkerifyPlugin = (instance, options) => {
308+
const plugin: WorkerifyPlugin = (_instance, _options) => {
309309
// Plugin implementation
310310
};
311311

312312
expect(typeof plugin).toBe('function');
313313
});
314314

315315
it('should support asynchronous plugin', () => {
316-
const plugin: WorkerifyPlugin = async (instance, options) => {
316+
const plugin: WorkerifyPlugin = async (_instance, _options) => {
317317
return Promise.resolve();
318318
};
319319

@@ -326,7 +326,7 @@ describe('Type Definitions', () => {
326326
enabled: boolean;
327327
}
328328

329-
const plugin: WorkerifyPlugin = (instance, options: PluginOptions) => {
329+
const plugin: WorkerifyPlugin = (_instance, options: PluginOptions) => {
330330
if (options?.enabled) {
331331
// Plugin logic
332332
}
@@ -336,7 +336,7 @@ describe('Type Definitions', () => {
336336
});
337337

338338
it('should support plugin without options', () => {
339-
const plugin: WorkerifyPlugin = (instance) => {
339+
const plugin: WorkerifyPlugin = (_instance) => {
340340
// Plugin implementation without options
341341
};
342342

@@ -348,7 +348,7 @@ describe('Type Definitions', () => {
348348
it('should allow route handlers to be assigned to RouteHandler type', () => {
349349
const syncHandler = () => 'sync';
350350
const asyncHandler = async () => 'async';
351-
const voidHandler = (req: WorkerifyRequest, reply: WorkerifyReply) => {
351+
const voidHandler = (_req: WorkerifyRequest, reply: WorkerifyReply) => {
352352
reply.status = 200;
353353
};
354354

packages/lib/src/__tests__/workerify.test.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
22
import { Workerify } from '../index.js';
3-
import {
4-
createMockRequest,
5-
setupBroadcastChannelMock,
6-
waitForAsync,
7-
} from './test-utils.js';
3+
import { setupBroadcastChannelMock } from './test-utils.js';
84

95
// Setup mocks
106
setupBroadcastChannelMock();
@@ -134,8 +130,8 @@ describe('Workerify', () => {
134130

135131
// Mock routes acknowledgment
136132
setTimeout(() => {
137-
const channel = workerify['channel'] as any;
138-
if (channel && channel.listeners) {
133+
const channel = workerify.channel as any;
134+
if (channel?.listeners) {
139135
channel.listeners.forEach((listener: any) => {
140136
listener({
141137
data: {
@@ -171,8 +167,8 @@ describe('Workerify', () => {
171167
});
172168

173169
setTimeout(() => {
174-
const channel = workerify['channel'] as any;
175-
if (channel && channel.listeners) {
170+
const channel = workerify.channel as any;
171+
if (channel?.listeners) {
176172
channel.listeners.forEach((listener: any) => {
177173
listener({
178174
data: {
@@ -198,8 +194,8 @@ describe('Workerify', () => {
198194
});
199195

200196
setTimeout(() => {
201-
const channel = workerify['channel'] as any;
202-
if (channel && channel.listeners) {
197+
const channel = workerify.channel as any;
198+
if (channel?.listeners) {
203199
channel.listeners.forEach((listener: any) => {
204200
listener({
205201
data: {
@@ -226,8 +222,8 @@ describe('Workerify', () => {
226222
});
227223

228224
setTimeout(() => {
229-
const channel = workerify['channel'] as any;
230-
if (channel && channel.listeners) {
225+
const channel = workerify.channel as any;
226+
if (channel?.listeners) {
231227
channel.listeners.forEach((listener: any) => {
232228
listener({
233229
data: {
@@ -263,7 +259,7 @@ describe('Workerify', () => {
263259

264260
describe('Integration with BroadcastChannel', () => {
265261
it('should NOT send route updates when routes are registered (deferred to listen)', async () => {
266-
const channelSpy = vi.spyOn(workerify['channel'], 'postMessage');
262+
const channelSpy = vi.spyOn(workerify.channel, 'postMessage');
267263

268264
workerify.get('/test', () => 'test');
269265

@@ -272,7 +268,7 @@ describe('Workerify', () => {
272268
});
273269

274270
it('should update service worker routes on listen', async () => {
275-
const channelSpy = vi.spyOn(workerify['channel'], 'postMessage');
271+
const channelSpy = vi.spyOn(workerify.channel, 'postMessage');
276272

277273
workerify.get('/test1', () => 'test1');
278274
workerify.post('/test2', () => 'test2');
@@ -286,8 +282,8 @@ describe('Workerify', () => {
286282
});
287283

288284
setTimeout(() => {
289-
const channel = workerify['channel'] as any;
290-
if (channel && channel.listeners) {
285+
const channel = workerify.channel as any;
286+
if (channel?.listeners) {
291287
channel.listeners.forEach((listener: any) => {
292288
listener({
293289
data: {

packages/lib/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export class Workerify {
354354
if (this.options.logger) {
355355
console.log('[Workerify] Routes registered successfully');
356356
}
357-
resolve(message.body || false);
357+
resolve(typeof message.body === 'boolean' ? message.body : false);
358358
}
359359
};
360360
this.channel.postMessage({

0 commit comments

Comments
 (0)