Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add more eslint (closes #1) #258

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
sourceType: 'module',
project: ['./tsconfig.json'],
},
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', '@stylistic/js', '@stylistic/ts'],
rules: {
'linebreak-style': ['error', 'unix'],
'@typescript-eslint/no-confusing-void-expression': [
Expand Down Expand Up @@ -44,6 +44,21 @@ module.exports = {
allowNumber: true,
},
],
'@stylistic/ts/lines-between-class-members': [
'error',
'always',
{ exceptAfterSingleLine: true },
],
'@stylistic/js/no-multiple-empty-lines': ['error', { max: 1 }],
'@stylistic/ts/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{
blankLine: 'always',
prev: '*',
next: ['enum', 'interface', 'type'],
},
],
},
ignorePatterns: ['dist/**/*'],
};
1 change: 1 addition & 0 deletions __tests__/bandwidth.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('bandwidth', async () => {
const msg = dummyPayloadSmall();
const id = sendClosure(msg);
await waitForMessage(serverTransport, (msg) => msg.id === id);

return;
},
{ time: BENCH_DURATION },
Expand Down
3 changes: 3 additions & 0 deletions __tests__/cancellation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe.each(testMatrix(['ws', 'naive']))(
const setup = await transport.setup({ client: opts, server: opts });
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down Expand Up @@ -336,6 +337,7 @@ describe.each(testMatrix())(
const setup = await transport.setup({ client: opts, server: opts });
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down Expand Up @@ -591,6 +593,7 @@ describe.each(testMatrix())(
const setup = await transport.setup({ client: opts, server: opts });
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe.each(testMatrix())(
const setup = await transport.setup({ client: opts, server: opts });
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down Expand Up @@ -487,6 +488,7 @@ describe('request finishing triggers signal onabort', async () => {
const setup = await transport.setup({ client: opts, server: opts });
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down
1 change: 1 addition & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('should handle incompatabilities', async () => {
});
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down
1 change: 1 addition & 0 deletions __tests__/disconnects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe.each(testMatrix())(
const setup = await transport.setup({ client: opts, server: opts });
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down
1 change: 1 addition & 0 deletions __tests__/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe.each(testMatrix())(
const setup = await transport.setup({ client: opts, server: opts });
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export async function testFinishesCleanly({

export const createPostTestCleanups = () => {
const cleanupFns: Array<() => Promise<void>> = [];

return {
addPostTestCleanup: (fn: () => Promise<void>) => {
cleanupFns.push(fn);
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class Observable<T> {
observe(listener: (val: T) => void) {
this.listeners.add(listener);
listener(this.get());

return () => this.listeners.delete(listener);
}

Expand Down
6 changes: 6 additions & 0 deletions __tests__/fixtures/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const testServiceProcedures = TestServiceScaffold.procedures({
responseData: Type.Object({ result: Type.Number() }),
async handler({ ctx, reqInit: { n } }) {
ctx.state.count += n;

return Ok({ result: ctx.state.count });
},
}),
Expand All @@ -29,6 +30,7 @@ const testServiceProcedures = TestServiceScaffold.procedures({
responseData: Type.Array(Type.Number()),
async handler({ ctx, reqInit: { n } }) {
ctx.state.count += n;

return Ok([ctx.state.count]);
},
}),
Expand Down Expand Up @@ -133,6 +135,7 @@ export const OrderingServiceSchema = ServiceSchema.define(
responseData: Type.Object({ n: Type.Number() }),
async handler({ ctx, reqInit: { n } }) {
ctx.state.msgs.push(n);

return Ok({ n });
},
}),
Expand All @@ -153,6 +156,7 @@ export const BinaryFileServiceSchema = ServiceSchema.define({
responseData: Type.Object({ contents: Type.Uint8Array() }),
async handler({ reqInit: { file } }) {
const bytes: Uint8Array = Buffer.from(`contents for file ${file}`);

return Ok({ contents: bytes });
},
}),
Expand Down Expand Up @@ -236,6 +240,7 @@ export const SubscribableServiceSchema = ServiceSchema.define(
responseData: Type.Object({ result: Type.Number() }),
async handler({ ctx, reqInit: { n } }) {
ctx.state.count.set((prev) => prev + n);

return Ok({ result: ctx.state.count.get() });
},
}),
Expand Down Expand Up @@ -278,6 +283,7 @@ export const UploadableServiceSchema = ServiceSchema.define({
for await (const req of reqReadable) {
result += unwrapOrThrow(req).n;
}

return Ok({ result: `${reqInit.prefix} ${result}` });
},
}),
Expand Down
3 changes: 3 additions & 0 deletions __tests__/fixtures/transports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const transports: Array<TransportMatrixEntry> = [
const transports: Array<
WebSocketClientTransport | WebSocketServerTransport
> = [];

return {
simulatePhantomDisconnect() {
for (const transport of transports) {
Expand Down Expand Up @@ -87,6 +88,7 @@ export const transports: Array<TransportMatrixEntry> = [
}, 'debug');

transports.push(clientTransport);

return clientTransport;
},
getServerTransport(handshakeOptions) {
Expand All @@ -110,6 +112,7 @@ export const transports: Array<TransportMatrixEntry> = [
}

transports.push(serverTransport);

return serverTransport as ServerTransport<Connection>;
},
async restartServer() {
Expand Down
1 change: 1 addition & 0 deletions __tests__/invalid-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('cancels invalid request', () => {
const setup = await transport.setup({ client: opts, server: opts });
getClientTransport = setup.getClientTransport;
getServerTransport = setup.getServerTransport;

return async () => {
await postTestCleanup();
await setup.cleanup();
Expand Down
1 change: 1 addition & 0 deletions __tests__/negative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('should handle incompatabilities', async () => {
const clientTransport = new WebSocketClientTransport(
() => {
connectCalls++;

return Promise.resolve(createLocalWebSocketClient(port));
},
'client',
Expand Down
3 changes: 3 additions & 0 deletions codec/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function uint8ArrayToBase64(uint8Array: Uint8Array) {
uint8Array.forEach((byte) => {
binary += String.fromCharCode(byte);
});

return btoa(binary);
}

Expand All @@ -19,6 +20,7 @@ function base64ToUint8Array(base64: string) {
for (let i = 0; i < binaryString.length; i++) {
uint8Array[i] = binaryString.charCodeAt(i);
}

return uint8Array;
}

Expand Down Expand Up @@ -59,6 +61,7 @@ export const NaiveJsonCodec: Codec = {
) as unknown;

if (typeof parsed === 'object') return parsed;

return null;
} catch {
return null;
Expand Down
1 change: 1 addition & 0 deletions logging/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const cleanedLogFn = (log: LogFn) => {
// skip cloning object if metadata has no transportMessage
if (!metadata?.transportMessage) {
log(msg, metadata);

return;
}

Expand Down
Loading
Loading