From 6f56230d6a3fa8038c44325b6a871c339be74407 Mon Sep 17 00:00:00 2001 From: KATT Date: Tue, 3 Oct 2023 10:47:34 +0200 Subject: [PATCH 1/9] chore: disable `@typescript-eslint/no-explicit-any` for project "no-inner-declarations": "off",@typescript-eslint/no-explicit-any --- .eslintrc.cjs | 1 + src/types.ts | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index b40f945a..4f746a41 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -123,6 +123,7 @@ module.exports = { "no-only-tests/no-only-tests": "error", // These on-by-default rules don't work well for this repo and we like them off. + "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/padding-line-between-statements": [ "error", { blankLine: "always", next: "*", prev: "block-like" }, diff --git a/src/types.ts b/src/types.ts index a6d04749..e9f5c8a4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,3 @@ -// eslint-disable-next-line eslint-comments/disable-enable-pair -/* eslint-disable @typescript-eslint/no-explicit-any */ const brand = Symbol("branded"); export type TsonBranded = TType & { [brand]: TBrand }; From 371a21362ca3a1e38adb8f5448de84b4c894f14f Mon Sep 17 00:00:00 2001 From: KATT Date: Wed, 4 Oct 2023 20:01:23 +0200 Subject: [PATCH 2/9] ok works --- .eslintrc.cjs | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 4f746a41..45f04dd3 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -55,6 +55,7 @@ module.exports = { }, rules: { // These off-by-default rules work well for this repo and we like them on. + "@typescript-eslint/no-explicit-any": "off", "deprecation/deprecation": "error", }, }, From 3d3bb58d165e22a558fd93fb67a1af6ac2b1feb8 Mon Sep 17 00:00:00 2001 From: KATT Date: Wed, 4 Oct 2023 20:02:18 +0200 Subject: [PATCH 3/9] cool --- src/async/deserializeAsync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/async/deserializeAsync.ts b/src/async/deserializeAsync.ts index 7d4b138f..cb39571a 100644 --- a/src/async/deserializeAsync.ts +++ b/src/async/deserializeAsync.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any, eslint-comments/disable-enable-pair */ +/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ import { TsonError } from "../errors.js"; From 72756eedb7cfecbe0462b816757abd917acfec13 Mon Sep 17 00:00:00 2001 From: KATT Date: Wed, 4 Oct 2023 20:04:01 +0200 Subject: [PATCH 4/9] cowboy --- .eslintrc.cjs | 1 + src/async/asyncTypes.ts | 2 -- src/handlers/tsonPromise.test.ts | 2 -- src/internals/getNonce.crypto.test.ts | 2 -- src/internals/getNonce.nocrypto.test.ts | 2 -- src/sync/deserialize.ts | 2 +- src/sync/serialize.ts | 2 +- 7 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 45f04dd3..da6782b5 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -56,6 +56,7 @@ module.exports = { rules: { // These off-by-default rules work well for this repo and we like them on. "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unsafe-member-access": "off", "deprecation/deprecation": "error", }, }, diff --git a/src/async/asyncTypes.ts b/src/async/asyncTypes.ts index ec4db1f8..42a5c199 100644 --- a/src/async/asyncTypes.ts +++ b/src/async/asyncTypes.ts @@ -1,5 +1,3 @@ -// eslint-disable-next-line eslint-comments/disable-enable-pair -/* eslint-disable @typescript-eslint/no-explicit-any */ import { TsonType } from "../types.js"; import { TsonBranded, TsonTypeTesterCustom } from "../types.js"; import { serialized } from "../types.js"; diff --git a/src/handlers/tsonPromise.test.ts b/src/handlers/tsonPromise.test.ts index 6f78340a..3aa2d76f 100644 --- a/src/handlers/tsonPromise.test.ts +++ b/src/handlers/tsonPromise.test.ts @@ -425,7 +425,6 @@ test("stringify and parse promise with a promise over a network connection", asy }); }); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any const port = (server.address() as any).port as number; // ----- client -------- @@ -461,7 +460,6 @@ test("stringify and parse promise with a promise over a network connection", asy const err = await firstPromise.rejectedPromise.catch((err) => err); assert.instanceOf(err, Error); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access expect(err.cause).toMatchInlineSnapshot(` { "name": "TsonPromiseRejectionError", diff --git a/src/internals/getNonce.crypto.test.ts b/src/internals/getNonce.crypto.test.ts index d003a465..e57bd0ef 100644 --- a/src/internals/getNonce.crypto.test.ts +++ b/src/internals/getNonce.crypto.test.ts @@ -1,5 +1,3 @@ -// eslint-disable-next-line eslint-comments/disable-enable-pair -/* eslint-disable @typescript-eslint/no-explicit-any */ import { expect, test } from "vitest"; test("with crypto", async () => { diff --git a/src/internals/getNonce.nocrypto.test.ts b/src/internals/getNonce.nocrypto.test.ts index 6a2c68ef..42123fa0 100644 --- a/src/internals/getNonce.nocrypto.test.ts +++ b/src/internals/getNonce.nocrypto.test.ts @@ -1,5 +1,3 @@ -// eslint-disable-next-line eslint-comments/disable-enable-pair -/* eslint-disable @typescript-eslint/no-explicit-any */ import { expect, test } from "vitest"; test("without crypto", async () => { diff --git a/src/sync/deserialize.ts b/src/sync/deserialize.ts index 4baf6059..72fb8866 100644 --- a/src/sync/deserialize.ts +++ b/src/sync/deserialize.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any, eslint-comments/disable-enable-pair */ +/* eslint-disable eslint-comments/disable-enable-pair */ import { isTsonTuple } from "../internals/isTsonTuple.js"; import { mapOrReturn } from "../internals/mapOrReturn.js"; diff --git a/src/sync/serialize.ts b/src/sync/serialize.ts index 6ea012c9..11436c39 100644 --- a/src/sync/serialize.ts +++ b/src/sync/serialize.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any, eslint-comments/disable-enable-pair */ +/* eslint-disable eslint-comments/disable-enable-pair */ import { TsonCircularReferenceError } from "../errors.js"; import { GetNonce, getNonce } from "../internals/getNonce.js"; import { mapOrReturn } from "../internals/mapOrReturn.js"; From 3fd99d8a95b35a2ec0f517a3e049cd6182312cc6 Mon Sep 17 00:00:00 2001 From: KATT Date: Wed, 4 Oct 2023 20:04:32 +0200 Subject: [PATCH 5/9] fix --- src/index.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index e581a872..3e0b1a49 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,5 +1,3 @@ -// eslint-disable-next-line eslint-comments/disable-enable-pair -/* eslint-disable @typescript-eslint/no-explicit-any */ import { expect, test, vitest } from "vitest"; import { @@ -179,7 +177,6 @@ test("async: bad values", async () => { expect(onErrorSpy).toHaveBeenCalledTimes(1); }); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access expect(onErrorSpy.mock.calls[0][0]).toMatchInlineSnapshot( "[TsonError: Stream interrupted: Stream ended with 1 pending promises]", ); From 8a0ff3e1d36780f3744766c8e8c767dd5a14e4a7 Mon Sep 17 00:00:00 2001 From: KATT Date: Wed, 4 Oct 2023 20:08:05 +0200 Subject: [PATCH 6/9] lint --- .eslintrc.cjs | 7 ++++++- README.md | 6 +++--- src/async/deserializeAsync.ts | 1 - src/sync/createTson.ts | 2 -- src/sync/deserialize.ts | 2 -- src/sync/serialize.ts | 1 - 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index da6782b5..7e049c95 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -16,6 +16,9 @@ module.exports = { extends: ["plugin:markdown/recommended"], files: ["**/*.md"], processor: "markdown/markdown", + rules: { + "eslint-comments/disable-enable-pair": "off", + }, }, { extends: [ @@ -58,6 +61,7 @@ module.exports = { "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unsafe-member-access": "off", "deprecation/deprecation": "error", + "eslint-comments/disable-enable-pair": "off", }, }, { @@ -121,7 +125,8 @@ module.exports = { rules: { // These off/less-strict-by-default rules work well for this repo and we like them on. - "@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "all" }], + "@typescript-eslint/no-unused-vars": "off", + "eslint-comments/disable-enable-pair": "off", "no-only-tests/no-only-tests": "error", // These on-by-default rules don't work well for this repo and we like them off. diff --git a/README.md b/README.md index 31b297b5..ba7fafe8 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Serialize exactly what you want; no more, no less. ### Example ```ts -/* eslint-disable eslint-comments/disable-enable-pair, @typescript-eslint/no-unused-vars, n/no-missing-import */ +/* eslint-disable @typescript-eslint/no-unused-vars, n/no-missing-import */ import { // Create serializer / deserializer @@ -113,7 +113,7 @@ type Obj = typeof obj; > See test reference in [`./src/extend/temporal.test.ts`](./src/extend/temporal.test.ts) ```ts -/* eslint-disable eslint-comments/disable-enable-pair, @typescript-eslint/no-unused-vars, n/no-missing-import, n/no-unpublished-import */ +/* eslint-disable @typescript-eslint/no-unused-vars, n/no-missing-import, n/no-unpublished-import */ import { Temporal } from "@js-temporal/polyfill"; import { TsonType, createTson } from "tupleson"; @@ -141,7 +141,7 @@ const tson = createTson({ > See test reference in [`./src/extend/decimal.test.ts`](./src/extend/decimal.test.ts) ```ts -/* eslint-disable eslint-comments/disable-enable-pair, @typescript-eslint/no-unused-vars, n/no-missing-import, n/no-unpublished-import */ +/* eslint-disable @typescript-eslint/no-unused-vars, n/no-missing-import, n/no-unpublished-import */ import { Decimal } from "decimal.js"; const decimalJs: TsonType = { diff --git a/src/async/deserializeAsync.ts b/src/async/deserializeAsync.ts index 581b6987..e83a8f2e 100644 --- a/src/async/deserializeAsync.ts +++ b/src/async/deserializeAsync.ts @@ -1,4 +1,3 @@ -/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ import { TsonError } from "../errors.js"; diff --git a/src/sync/createTson.ts b/src/sync/createTson.ts index 87c20f3a..3b600b80 100644 --- a/src/sync/createTson.ts +++ b/src/sync/createTson.ts @@ -1,5 +1,3 @@ -/* eslint-disable eslint-comments/disable-enable-pair */ - import { TsonOptions } from "../types.js"; import { createTsonDeserialize, createTsonParser } from "./deserialize.js"; import { createTsonSerialize, createTsonStringify } from "./serialize.js"; diff --git a/src/sync/deserialize.ts b/src/sync/deserialize.ts index 72fb8866..f19aee74 100644 --- a/src/sync/deserialize.ts +++ b/src/sync/deserialize.ts @@ -1,5 +1,3 @@ -/* eslint-disable eslint-comments/disable-enable-pair */ - import { isTsonTuple } from "../internals/isTsonTuple.js"; import { mapOrReturn } from "../internals/mapOrReturn.js"; import { diff --git a/src/sync/serialize.ts b/src/sync/serialize.ts index 11436c39..a793abaf 100644 --- a/src/sync/serialize.ts +++ b/src/sync/serialize.ts @@ -1,4 +1,3 @@ -/* eslint-disable eslint-comments/disable-enable-pair */ import { TsonCircularReferenceError } from "../errors.js"; import { GetNonce, getNonce } from "../internals/getNonce.js"; import { mapOrReturn } from "../internals/mapOrReturn.js"; From 6a1ba9be3710de271596cd6045672ebe73adeed5 Mon Sep 17 00:00:00 2001 From: KATT Date: Wed, 4 Oct 2023 20:26:26 +0200 Subject: [PATCH 7/9] fix --- src/async/deserializeAsync.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/async/deserializeAsync.ts b/src/async/deserializeAsync.ts index e83a8f2e..7ee90547 100644 --- a/src/async/deserializeAsync.ts +++ b/src/async/deserializeAsync.ts @@ -188,6 +188,7 @@ export function createTsonParseAsync(opts: TsonAsyncOptions): TsonParseAsync { const walk = walker(head.nonce); + const result = walk(head.json); void getStreamedValues(buffer, walk).catch((cause) => { // Something went wrong while getting the streamed values @@ -207,7 +208,7 @@ export function createTsonParseAsync(opts: TsonAsyncOptions): TsonParseAsync { opts.onStreamError?.(err); }); - return walk(head.json); + return result; } const result = await init().catch((cause: unknown) => { From cf5833a896b37e4837d943ef8fa9da8064a21c6e Mon Sep 17 00:00:00 2001 From: KATT Date: Wed, 4 Oct 2023 20:27:51 +0200 Subject: [PATCH 8/9] cool --- src/async/deserializeAsync.ts | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/async/deserializeAsync.ts b/src/async/deserializeAsync.ts index 7ee90547..0f6c1fdc 100644 --- a/src/async/deserializeAsync.ts +++ b/src/async/deserializeAsync.ts @@ -188,27 +188,28 @@ export function createTsonParseAsync(opts: TsonAsyncOptions): TsonParseAsync { const walk = walker(head.nonce); - const result = walk(head.json); - void getStreamedValues(buffer, walk).catch((cause) => { - // Something went wrong while getting the streamed values - - const err = new TsonError( - `Stream interrupted: ${(cause as Error).message}`, - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - { cause }, - ); - - // cancel all pending promises - for (const deferred of deferreds.values()) { - deferred.reject(err); - } + try { + return walk(head.json); + } finally { + void getStreamedValues(buffer, walk).catch((cause) => { + // Something went wrong while getting the streamed values + + const err = new TsonError( + `Stream interrupted: ${(cause as Error).message}`, + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + { cause }, + ); - deferreds.clear(); + // cancel all pending promises + for (const deferred of deferreds.values()) { + deferred.reject(err); + } - opts.onStreamError?.(err); - }); + deferreds.clear(); - return result; + opts.onStreamError?.(err); + }); + } } const result = await init().catch((cause: unknown) => { From 5598f2d50badee3bc73a9b7a475e3ef9abc20b9f Mon Sep 17 00:00:00 2001 From: KATT Date: Wed, 4 Oct 2023 20:28:06 +0200 Subject: [PATCH 9/9] cool --- src/async/deserializeAsync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/async/deserializeAsync.ts b/src/async/deserializeAsync.ts index 0f6c1fdc..537655df 100644 --- a/src/async/deserializeAsync.ts +++ b/src/async/deserializeAsync.ts @@ -191,7 +191,7 @@ export function createTsonParseAsync(opts: TsonAsyncOptions): TsonParseAsync { try { return walk(head.json); } finally { - void getStreamedValues(buffer, walk).catch((cause) => { + getStreamedValues(buffer, walk).catch((cause) => { // Something went wrong while getting the streamed values const err = new TsonError(