Skip to content

Commit

Permalink
refactor: upgrade to typescript-eslint v8
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Aug 3, 2024
1 parent 6115266 commit 66a98f8
Show file tree
Hide file tree
Showing 32 changed files with 278 additions and 180 deletions.
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
"prettier": "^3.3.3",
Expand Down
10 changes: 5 additions & 5 deletions libraries/adb-credential-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function openDatabase() {
return new Promise<IDBDatabase>((resolve, reject) => {
const request = indexedDB.open("Tango", 1);
request.onerror = () => {
reject(request.error);
reject(request.error!);
};
request.onupgradeneeded = () => {
const db = request.result;
Expand All @@ -27,13 +27,13 @@ async function saveKey(key: Uint8Array): Promise<void> {
const store = transaction.objectStore("Authentication");
const putRequest = store.add(key);
putRequest.onerror = () => {
reject(putRequest.error);
reject(putRequest.error!);
};
putRequest.onsuccess = () => {
resolve();
};
transaction.onerror = () => {
reject(transaction.error);
reject(transaction.error!);
};
transaction.oncomplete = () => {
db.close();
Expand All @@ -49,13 +49,13 @@ async function getAllKeys() {
const store = transaction.objectStore("Authentication");
const getRequest = store.getAll();
getRequest.onerror = () => {
reject(getRequest.error);
reject(getRequest.error!);
};
getRequest.onsuccess = () => {
resolve(getRequest.result as Uint8Array[]);
};
transaction.onerror = () => {
reject(transaction.error);
reject(transaction.error!);
};
transaction.oncomplete = () => {
db.close();
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb-daemon-webusb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@yume-chan/struct": "workspace:^0.0.24"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/test-runner": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb-scrcpy/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class AdbScrcpyForwardConnection extends AdbScrcpyConnection {
};
}
return stream;
} catch (e) {
} catch {
// Maybe the server is still starting
await delay(100);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb-server-node-tcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@yume-chan/struct": "workspace:^0.0.24"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
"prettier": "^3.3.3",
Expand Down
7 changes: 2 additions & 5 deletions libraries/adb-server-node-tcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { AdbIncomingSocketHandler, AdbServerClient } from "@yume-chan/adb";
import {
MaybeConsumable,
PushReadableStream,
tryClose,
WrapWritableStream,
WritableStream,
} from "@yume-chan/stream-extra";
Expand Down Expand Up @@ -32,11 +33,7 @@ function nodeSocketToConnection(
socket.resume();
});
socket.on("end", () => {
try {
controller.close();
} catch (e) {
// controller already closed
}
tryClose(controller);
});
}),
writable: new WritableStream<Uint8Array>({
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@yume-chan/struct": "workspace:^0.0.24"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/test-runner": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb/src/commands/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class AdbSync extends AutoDisposable {
try {
await this.lstat(path + "/");
return true;
} catch (e) {
} catch {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb/src/daemon/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export class AdbPacketDispatcher implements Closeable {
remoteId,
this.options.initialDelayedAckBytes,
);
} catch (e) {
} catch {
await this.sendPacket(
AdbCommand.Close,
0,
Expand Down
13 changes: 5 additions & 8 deletions libraries/adb/src/server/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
BufferedReadableStream,
MaybeConsumable,
WrapWritableStream,
tryCancel,
tryClose,
} from "@yume-chan/stream-extra";
import type { ValueOrPromise } from "@yume-chan/struct";
import {
Expand All @@ -23,12 +25,7 @@ import {
import type { AdbIncomingSocketHandler, AdbSocket, Closeable } from "../adb.js";
import { AdbBanner } from "../banner.js";
import type { AdbFeature } from "../features.js";
import {
NOOP,
hexToNumber,
sequenceEqual,
write4HexDigits,
} from "../utils/index.js";
import { hexToNumber, sequenceEqual, write4HexDigits } from "../utils/index.js";

import { AdbServerTransport } from "./transport.js";

Expand Down Expand Up @@ -123,8 +120,8 @@ class AdbServerStream {
}

async dispose() {
await this.#buffered.cancel().catch(NOOP);
await this.#writer.close().catch(NOOP);
void tryCancel(this.#buffered);
void tryClose(this.#writer);
await this.#connection.close();
}
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/adb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"references": [
{
"path": "./tsconfig.build.json"
"path": "./tsconfig.test.json"
},
{
"path": "./tsconfig.test.json"
"path": "./tsconfig.build.json"
}
]
}
2 changes: 1 addition & 1 deletion libraries/android-bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@yume-chan/struct": "workspace:^0.0.24"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/test-runner": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion libraries/android-bin/src/bug-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class BugReport extends AdbCommandBase {
*/
async bugReportZ(options?: BugReportZOptions): Promise<string> {
if (options?.signal?.aborted) {
throw options?.signal.reason ?? new Error("Aborted");
throw options?.signal.reason as Error;
}

if (!this.#supportsBugReportZ) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/android-bin/src/string-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const p = {
const result = format.stringify(value);
// Parse the result to make sure it is valid
format.parse({ value: result, position: 0 });
} catch (e) {
} catch {
// ignore
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ export const p = {
while (true) {
try {
result.push(format.parse(reader));
} catch (e) {
} catch {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/event/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@yume-chan/async": "^2.2.0"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/test-runner": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion libraries/fetch-scrcpy-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"gh-release-fetch": "^4.0.3"
},
"devDependencies": {
"@types/node": "^20.14.12"
"@types/node": "^22.1.0"
}
}
4 changes: 2 additions & 2 deletions libraries/no-data-view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
"test": "run-test"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/test-runner": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
"prettier": "^3.3.3",
"tinybench": "^2.8.0",
"tinybench": "^2.9.0",
"typescript": "^5.5.4"
}
}
2 changes: 1 addition & 1 deletion libraries/pcm-player/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@types/audioworklet": "^0.0.57",
"@types/audioworklet": "^0.0.58",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
"prettier": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion libraries/scrcpy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@yume-chan/struct": "workspace:^0.0.24"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/test-runner": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions libraries/scrcpy/src/options/1_21.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ScrcpyOptions1_21 extends ScrcpyOptions<ScrcpyOptionsInit1_21> {
}
}

#deviceMessageError: unknown;
#deviceMessageError: Error | undefined;

override async parseDeviceMessage(
id: number,
Expand All @@ -97,12 +97,12 @@ export class ScrcpyOptions1_21 extends ScrcpyOptions<ScrcpyOptionsInit1_21> {
break;
}
} catch (e) {
this.#deviceMessageError = e;
this.#deviceMessageError = e as Error;
throw e;
}
}

override async endDeviceMessageStream(e?: unknown): Promise<void> {
override async endDeviceMessageStream(e?: Error): Promise<void> {
await super.endDeviceMessageStream(e);
this.#deviceMessageError ??=
e ?? new Error("Device message stream ended");
Expand Down
2 changes: 1 addition & 1 deletion libraries/stream-extra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@yume-chan/struct": "workspace:^0.0.24"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/test-runner": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
Expand Down
8 changes: 2 additions & 6 deletions libraries/stream-extra/src/buffered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { ExactReadableEndedError } from "@yume-chan/struct";

import { PushReadableStream } from "./push-readable.js";
import type { ReadableStream, ReadableStreamDefaultReader } from "./stream.js";

const NOOP = () => {
// no-op
};
import { tryCancel } from "./try-close.js";

export class BufferedReadableStream implements AsyncExactReadable {
#buffered: Uint8Array | undefined;
Expand Down Expand Up @@ -133,8 +130,7 @@ export class BufferedReadableStream implements AsyncExactReadable {
await controller.enqueue(buffered);

controller.abortSignal.addEventListener("abort", () => {
// NOOP: the reader might already be released
this.reader.cancel().catch(NOOP);
void tryCancel(this.reader);
});

// Manually pipe the stream
Expand Down
7 changes: 2 additions & 5 deletions libraries/stream-extra/src/duplex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
WritableStreamDefaultWriter,
} from "./stream.js";
import { WritableStream } from "./stream.js";
import { tryClose } from "./try-close.js";
import { WrapReadableStream } from "./wrap-readable.js";

const NOOP = () => {
Expand Down Expand Up @@ -134,11 +135,7 @@ export class DuplexStreamFactory<R, W> {
this.#closed.resolve();

for (const controller of this.#readableControllers) {
try {
controller.close();
} catch {
// ignore
}
tryClose(controller);
}

await this.#options.dispose?.();
Expand Down
1 change: 1 addition & 0 deletions libraries/stream-extra/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export * from "./stream.js";
export * from "./struct-deserialize.js";
export * from "./struct-serialize.js";
export * from "./task.js";
export * from "./try-close.js";
export * from "./wrap-readable.js";
export * from "./wrap-writable.js";
44 changes: 44 additions & 0 deletions libraries/stream-extra/src/try-close.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { BufferedReadableStream } from "./buffered.js";
import type { PushReadableStreamController } from "./push-readable.js";
import type {
ReadableStream,
ReadableStreamDefaultController,
ReadableStreamDefaultReader,
WritableStreamDefaultWriter,
} from "./stream.js";

export function tryClose(
controller: PushReadableStreamController<unknown>,
): boolean;
export function tryClose(
controller: ReadableStreamDefaultController<unknown>,
): boolean;
export function tryClose(writer: WritableStreamDefaultWriter<never>): boolean;
export function tryClose(controller: { close(): void }) {
try {
controller.close();
return true;
} catch {
return false;
}
}

export async function tryCancel(
stream: ReadableStream<unknown>,
): Promise<boolean>;
export async function tryCancel(
stream: BufferedReadableStream,
): Promise<boolean>;
export async function tryCancel(
reader: ReadableStreamDefaultReader<unknown>,
): Promise<boolean>;
export async function tryCancel(stream: {
cancel(): Promise<void>;
}): Promise<boolean> {
try {
await stream.cancel();
return true;
} catch {
return false;
}
}
2 changes: 1 addition & 1 deletion libraries/struct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@yume-chan/no-data-view": "workspace:^0.0.24"
},
"devDependencies": {
"@types/node": "^20.14.12",
"@types/node": "^22.1.0",
"@yume-chan/eslint-config": "workspace:^1.0.0",
"@yume-chan/test-runner": "workspace:^1.0.0",
"@yume-chan/tsconfig": "workspace:^1.0.0",
Expand Down
Loading

0 comments on commit 66a98f8

Please sign in to comment.