diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 939a092..e26aaa9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: - '18' - '20' - '22' + - '24' steps: - uses: actions/checkout@v4 - name: Setup Node.js ${{ matrix.node-version }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 406131c..578c615 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Initialize CodeQL uses: github/codeql-action/init@v3 diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index 0bcacca..79f9e5c 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -14,12 +14,12 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: cache: npm - node-version: "18" + node-version: "20" # npm@9 may fail with https://github.com/npm/cli/issues/6723 # npm@10 may fail with "GitFetcher requires an Arborist constructor to pack a tarball" diff --git a/eslint.config.mjs b/eslint.config.mjs index 3d5529e..0af8fa6 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -11,112 +11,141 @@ import { FlatCompat } from "@eslint/eslintrc"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, }); -export default [{ +export default [ + { ignores: ["**/*.js", "test/deno*", "test/bun*"], -}, ...fixupConfigRules(compat.extends( - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:import/recommended", - "plugin:import/typescript", - "prettier", -)), { + }, + ...fixupConfigRules( + compat.extends( + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:import/recommended", + "plugin:import/typescript", + "prettier", + ), + ), + { plugins: { - "@typescript-eslint": fixupPluginRules(typescriptEslintEslintPlugin), - tsdoc, + "@typescript-eslint": fixupPluginRules(typescriptEslintEslintPlugin), + tsdoc, }, languageOptions: { - parser: tsParser, - ecmaVersion: 5, - sourceType: "script", + parser: tsParser, + ecmaVersion: 5, + sourceType: "script", - parserOptions: { - project: "./tsconfig.json", - }, + parserOptions: { + project: "./tsconfig.json", + }, }, settings: {}, rules: { - "no-constant-condition": ["warn", { - checkLoops: false, - }], + "no-constant-condition": [ + "warn", + { + checkLoops: false, + }, + ], - "no-useless-escape": "warn", - "no-console": "warn", - "no-var": "warn", - "no-return-await": "warn", - "prefer-const": "warn", - "guard-for-in": "warn", - curly: "warn", - "no-param-reassign": "warn", - "prefer-spread": "warn", - "import/no-unresolved": "off", - "import/no-cycle": "error", - "import/no-default-export": "warn", - "tsdoc/syntax": "warn", - "@typescript-eslint/await-thenable": "warn", + "no-useless-escape": "warn", + "no-console": "warn", + "no-var": "warn", + "no-return-await": "warn", + "prefer-const": "warn", + "guard-for-in": "warn", + curly: "warn", + "no-param-reassign": "warn", + "prefer-spread": "warn", + "import/no-unresolved": "off", + "import/no-cycle": "error", + "import/no-default-export": "warn", + "tsdoc/syntax": "warn", + "@typescript-eslint/await-thenable": "warn", - "@typescript-eslint/array-type": ["warn", { - default: "generic", - }], + "@typescript-eslint/array-type": [ + "warn", + { + default: "generic", + }, + ], - "@typescript-eslint/naming-convention": ["warn", { - selector: "default", - format: ["camelCase", "UPPER_CASE", "PascalCase"], - leadingUnderscore: "allow", - }, { - selector: "typeLike", - format: ["PascalCase"], - leadingUnderscore: "allow", - }], + "@typescript-eslint/naming-convention": [ + "warn", + { + selector: "default", + format: ["camelCase", "UPPER_CASE", "PascalCase"], + leadingUnderscore: "allow", + }, + { + selector: "typeLike", + format: ["PascalCase"], + leadingUnderscore: "allow", + }, + ], - "@typescript-eslint/restrict-plus-operands": "warn", - //"@typescript-eslint/no-throw-literal": "warn", - "@typescript-eslint/unbound-method": "warn", - "@typescript-eslint/explicit-module-boundary-types": "warn", - //"@typescript-eslint/no-extra-semi": "warn", - "@typescript-eslint/no-extra-non-null-assertion": "warn", + "@typescript-eslint/restrict-plus-operands": "warn", + //"@typescript-eslint/no-throw-literal": "warn", + "@typescript-eslint/unbound-method": "warn", + "@typescript-eslint/explicit-module-boundary-types": "warn", + //"@typescript-eslint/no-extra-semi": "warn", + "@typescript-eslint/no-extra-non-null-assertion": "warn", - "@typescript-eslint/no-unused-vars": ["warn", { - argsIgnorePattern: "^_", - }], + "@typescript-eslint/no-unused-vars": [ + "warn", + { + argsIgnorePattern: "^_", + }, + ], - "@typescript-eslint/no-use-before-define": "warn", - "@typescript-eslint/no-for-in-array": "warn", - "@typescript-eslint/no-unsafe-argument": "warn", - "@typescript-eslint/no-unsafe-call": "warn", + "@typescript-eslint/no-use-before-define": "warn", + "@typescript-eslint/no-for-in-array": "warn", + "@typescript-eslint/no-unsafe-argument": "warn", + "@typescript-eslint/no-unsafe-call": "warn", - "@typescript-eslint/no-unnecessary-condition": ["warn", { - allowConstantLoopConditions: true, - }], + "@typescript-eslint/no-unnecessary-condition": [ + "warn", + { + allowConstantLoopConditions: true, + }, + ], - "@typescript-eslint/no-unnecessary-type-constraint": "warn", - "@typescript-eslint/no-implied-eval": "warn", - "@typescript-eslint/no-non-null-asserted-optional-chain": "warn", - "@typescript-eslint/no-invalid-void-type": "warn", - "@typescript-eslint/no-loss-of-precision": "warn", - "@typescript-eslint/no-confusing-void-expression": "warn", - "@typescript-eslint/no-redundant-type-constituents": "warn", - "@typescript-eslint/prefer-for-of": "warn", - "@typescript-eslint/prefer-includes": "warn", - "@typescript-eslint/prefer-string-starts-ends-with": "warn", - "@typescript-eslint/prefer-readonly": "warn", - "@typescript-eslint/prefer-regexp-exec": "warn", - "@typescript-eslint/prefer-nullish-coalescing": "warn", - "@typescript-eslint/prefer-optional-chain": "warn", - "@typescript-eslint/prefer-ts-expect-error": "warn", - "@typescript-eslint/indent": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-var-requires": "off", - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/no-unnecessary-type-constraint": "warn", + "@typescript-eslint/no-implied-eval": "warn", + "@typescript-eslint/no-non-null-asserted-optional-chain": "warn", + "@typescript-eslint/no-invalid-void-type": "warn", + "@typescript-eslint/no-loss-of-precision": "warn", + "@typescript-eslint/no-confusing-void-expression": "warn", + "@typescript-eslint/no-redundant-type-constituents": "warn", + "@typescript-eslint/prefer-for-of": "warn", + "@typescript-eslint/prefer-includes": "warn", + "@typescript-eslint/prefer-string-starts-ends-with": "warn", + "@typescript-eslint/prefer-readonly": "warn", + "@typescript-eslint/prefer-regexp-exec": "warn", + "@typescript-eslint/prefer-nullish-coalescing": "warn", + "@typescript-eslint/prefer-optional-chain": "warn", + "@typescript-eslint/prefer-ts-expect-error": "warn", + "@typescript-eslint/consistent-type-imports": [ + "error", + { + prefer: "type-imports", + disallowTypeAnnotations: false, + }, + ], + "@typescript-eslint/indent": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/ban-ts-comment": "off", }, -}]; + }, +]; diff --git a/src/CachedKeyDecoder.ts b/src/CachedKeyDecoder.ts index 73524f0..0de4a7d 100644 --- a/src/CachedKeyDecoder.ts +++ b/src/CachedKeyDecoder.ts @@ -16,8 +16,8 @@ export class CachedKeyDecoder implements KeyDecoder { hit = 0; miss = 0; private readonly caches: Array>; - private readonly maxKeyLength: number; - private readonly maxLengthPerKey: number; + readonly maxKeyLength: number; + readonly maxLengthPerKey: number; constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) { this.maxKeyLength = maxKeyLength; diff --git a/src/Decoder.ts b/src/Decoder.ts index 9239dd1..bba8804 100644 --- a/src/Decoder.ts +++ b/src/Decoder.ts @@ -1,11 +1,13 @@ import { prettyByte } from "./utils/prettyByte.ts"; -import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec.ts"; +import { ExtensionCodec } from "./ExtensionCodec.ts"; import { getInt64, getUint64, UINT32_MAX } from "./utils/int.ts"; import { utf8Decode } from "./utils/utf8.ts"; import { ensureUint8Array } from "./utils/typedArrays.ts"; -import { CachedKeyDecoder, KeyDecoder } from "./CachedKeyDecoder.ts"; +import { CachedKeyDecoder } from "./CachedKeyDecoder.ts"; import { DecodeError } from "./DecodeError.ts"; import type { ContextOf } from "./context.ts"; +import type { ExtensionCodecType } from "./ExtensionCodec.ts"; +import type { KeyDecoder } from "./CachedKeyDecoder.ts"; export type DecoderOptions = Readonly< Partial<{ @@ -70,7 +72,7 @@ export type DecoderOptions = Readonly< /** * A function to convert decoded map key to a valid JS key type. - * + * * Defaults to a function that throws an error if the key is not a string or a number. */ mapKeyConverter: (key: unknown) => MapKeyType; diff --git a/src/Encoder.ts b/src/Encoder.ts index ffb4f6b..43fcd8f 100644 --- a/src/Encoder.ts +++ b/src/Encoder.ts @@ -1,9 +1,10 @@ import { utf8Count, utf8Encode } from "./utils/utf8.ts"; -import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec.ts"; +import { ExtensionCodec } from "./ExtensionCodec.ts"; import { setInt64, setUint64 } from "./utils/int.ts"; import { ensureUint8Array } from "./utils/typedArrays.ts"; import type { ExtData } from "./ExtData.ts"; import type { ContextOf } from "./context.ts"; +import type { ExtensionCodecType } from "./ExtensionCodec.ts"; export const DEFAULT_MAX_DEPTH = 100; export const DEFAULT_INITIAL_BUFFER_SIZE = 2048;