From dab8d65c1d997ce4d263256dc46fbc6fc4c4b69b Mon Sep 17 00:00:00 2001 From: Jason Green Date: Sun, 3 Mar 2024 22:11:00 +0000 Subject: [PATCH] chore: update ts, eslint, config etc --- lib/compile/codegen/index.ts | 28 ++++++++++++++++++++++++++++ lib/compile/validate/dataType.ts | 1 + lib/core.ts | 4 ++++ lib/standalone/instance.ts | 1 + lib/types/index.ts | 1 + lib/vocabularies/code.ts | 1 + package.json | 12 ++++++------ spec/types/async-validate.spec.ts | 2 +- 8 files changed, 43 insertions(+), 7 deletions(-) diff --git a/lib/compile/codegen/index.ts b/lib/compile/codegen/index.ts index 5a6d1ee58..97af6a888 100644 --- a/lib/compile/codegen/index.ts +++ b/lib/compile/codegen/index.ts @@ -42,8 +42,11 @@ abstract class Node { class Def extends Node { constructor( + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly varKind: Name, + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly name: Name, + // eslint-disable-next-line @typescript-eslint/parameter-properties private rhs?: SafeExpr ) { super() @@ -68,8 +71,11 @@ class Def extends Node { class Assign extends Node { constructor( + // eslint-disable-next-line @typescript-eslint/parameter-properties readonly lhs: Code, + // eslint-disable-next-line @typescript-eslint/parameter-properties public rhs: SafeExpr, + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly sideEffects?: boolean ) { super() @@ -94,6 +100,7 @@ class Assign extends Node { class AssignOp extends Assign { constructor( lhs: Code, + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly op: Code, rhs: SafeExpr, sideEffects?: boolean @@ -108,6 +115,7 @@ class AssignOp extends Assign { class Label extends Node { readonly names: UsedNames = {} + // eslint-disable-next-line @typescript-eslint/parameter-properties constructor(readonly label: Name) { super() } @@ -119,6 +127,7 @@ class Label extends Node { class Break extends Node { readonly names: UsedNames = {} + // eslint-disable-next-line @typescript-eslint/parameter-properties constructor(readonly label?: Code) { super() } @@ -130,6 +139,7 @@ class Break extends Node { } class Throw extends Node { + // eslint-disable-next-line @typescript-eslint/parameter-properties constructor(readonly error: Code) { super() } @@ -144,6 +154,7 @@ class Throw extends Node { } class AnyCode extends Node { + // eslint-disable-next-line @typescript-eslint/parameter-properties constructor(private code: SafeExpr) { super() } @@ -167,6 +178,7 @@ class AnyCode extends Node { } abstract class ParentNode extends Node { + // eslint-disable-next-line @typescript-eslint/parameter-properties constructor(readonly nodes: ChildNode[] = []) { super() } @@ -225,6 +237,7 @@ class If extends BlockNode { static readonly kind = "if" else?: If | Else constructor( + // eslint-disable-next-line @typescript-eslint/parameter-properties private condition: Code | boolean, nodes?: ChildNode[] ) { @@ -279,6 +292,7 @@ abstract class For extends BlockNode { } class ForLoop extends For { + // eslint-disable-next-line @typescript-eslint/parameter-properties constructor(private iteration: Code) { super() } @@ -300,9 +314,13 @@ class ForLoop extends For { class ForRange extends For { constructor( + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly varKind: Name, + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly name: Name, + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly from: SafeExpr, + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly to: SafeExpr ) { super() @@ -322,9 +340,13 @@ class ForRange extends For { class ForIter extends For { constructor( + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly loop: "of" | "in", + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly varKind: Name, + // eslint-disable-next-line @typescript-eslint/parameter-properties private readonly name: Name, + // eslint-disable-next-line @typescript-eslint/parameter-properties private iterable: Code ) { super() @@ -348,8 +370,11 @@ class ForIter extends For { class Func extends BlockNode { static readonly kind = "func" constructor( + // eslint-disable-next-line @typescript-eslint/parameter-properties public name: Name, + // eslint-disable-next-line @typescript-eslint/parameter-properties public args: Code, + // eslint-disable-next-line @typescript-eslint/parameter-properties public async?: boolean ) { super() @@ -408,6 +433,7 @@ class Try extends BlockNode { class Catch extends BlockNode { static readonly kind = "catch" + // eslint-disable-next-line @typescript-eslint/parameter-properties constructor(readonly error: Name) { super() } @@ -789,6 +815,7 @@ function addExprNames(names: UsedNames, from: SafeExpr): UsedNames { } function optimizeExpr(expr: T, names: UsedNames, constants: Constants): T +// eslint-disable-next-line no-redeclare function optimizeExpr(expr: SafeExpr, names: UsedNames, constants: Constants): SafeExpr { if (expr instanceof Name) return replaceName(expr) if (!canOptimize(expr)) return expr @@ -823,6 +850,7 @@ function subtractNames(names: UsedNames, from: UsedNames): void { } export function not(x: T): T +// eslint-disable-next-line no-redeclare export function not(x: Code | SafeExpr): Code | SafeExpr { return typeof x == "boolean" || typeof x == "number" || x === null ? !x : _`!${par(x)}` } diff --git a/lib/compile/validate/dataType.ts b/lib/compile/validate/dataType.ts index b315c2ce9..d8142b3e1 100644 --- a/lib/compile/validate/dataType.ts +++ b/lib/compile/validate/dataType.ts @@ -30,6 +30,7 @@ export function getSchemaTypes(schema: AnySchemaObject): JSONType[] { return types } +// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents export function getJSONTypes(ts: unknown | unknown[]): JSONType[] { const types: unknown[] = Array.isArray(ts) ? ts : ts ? [ts] : [] if (types.every(isJSONType)) return types diff --git a/lib/core.ts b/lib/core.ts index 3686ffe76..e41ca3e2a 100644 --- a/lib/core.ts +++ b/lib/core.ts @@ -343,14 +343,17 @@ export default class Ajv { validate(schema: JTDSchemaType, data: unknown): data is T // This overload is only intended for typescript inference, the first // argument prevents manual type annotation from matching this overload + // eslint-disable-next-line @typescript-eslint/no-unused-vars validate( schema: T, data: unknown ): data is JTDDataType + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents validate(schema: AsyncSchema, data: unknown | T): Promise validate(schemaKeyRef: AnySchema | string, data: unknown): data is T | Promise validate( schemaKeyRef: AnySchema | string, // key, ref or schema object + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents data: unknown | T // to be validated ): boolean | Promise { let v: AnyValidateFunction | undefined @@ -374,6 +377,7 @@ export default class Ajv { compile(schema: JTDSchemaType, _meta?: boolean): ValidateFunction // This overload is only intended for typescript inference, the first // argument prevents manual type annotation from matching this overload + // eslint-disable-next-line @typescript-eslint/no-unused-vars compile( schema: T, _meta?: boolean diff --git a/lib/standalone/instance.ts b/lib/standalone/instance.ts index c4b2c30b5..9bf5e01a0 100644 --- a/lib/standalone/instance.ts +++ b/lib/standalone/instance.ts @@ -4,6 +4,7 @@ import * as requireFromString from "require-from-string" export default class AjvPack { errors?: ErrorObject[] | null // errors from the last validation + // eslint-disable-next-line @typescript-eslint/parameter-properties constructor(readonly ajv: Ajv) {} validate(schemaKeyRef: AnySchema | string, data: unknown): boolean | Promise { diff --git a/lib/types/index.ts b/lib/types/index.ts index 054b10f6f..b5ef53eeb 100644 --- a/lib/types/index.ts +++ b/lib/types/index.ts @@ -48,6 +48,7 @@ export interface DataValidationCxt } export interface ValidateFunction { + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents (this: Ajv | any, data: any, dataCxt?: DataValidationCxt): data is T errors?: null | ErrorObject[] evaluated?: Evaluated diff --git a/lib/vocabularies/code.ts b/lib/vocabularies/code.ts index 92cdd5b04..a2a22262f 100644 --- a/lib/vocabularies/code.ts +++ b/lib/vocabularies/code.ts @@ -98,6 +98,7 @@ export function usePattern({gen, it: {opts}}: KeywordCxt, pattern: string): Name const rx = regExp(pattern, u) return gen.scopeValue("pattern", { + // eslint-disable-next-line @typescript-eslint/no-base-to-string key: rx.toString(), ref: rx, code: _`${regExp.code === "new RegExp" ? newRegExp : useFunc(gen, regExp)}(${pattern}, ${u})`, diff --git a/package.json b/package.json index 6eee40b4f..544a60584 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "uri-js": "^4.4.1" }, "devDependencies": { - "@ajv-validator/config": "git://github.com/ajv-validator/config", + "@ajv-validator/config": "git://github.com/ajv-validator/config#upgrade-deps", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.2.3", @@ -73,16 +73,16 @@ "@types/mocha": "^10.0.6", "@types/node": "^20.11.19", "@types/require-from-string": "^1.2.3", - "@typescript-eslint/eslint-plugin": "^3.10.1", - "@typescript-eslint/parser": "^3.10.1", + "@typescript-eslint/eslint-plugin": "^7.1.0", + "@typescript-eslint/parser": "^7.1.0", "ajv-formats": "^3.0.0-rc.0", "browserify": "^17.0.0", "chai": "^4.4.1", "cross-env": "^7.0.3", "dayjs": "^1.11.10", "dayjs-plugin-utc": "^0.1.2", - "eslint": "^7.32.0", - "eslint-config-prettier": "^7.2.0", + "eslint": "^8.57.0", + "eslint-config-prettier": "^9.1.0", "fast-uri": "^2.3.0", "glob": "^10.3.10", "husky": "^9.0.11", @@ -104,7 +104,7 @@ "rollup-plugin-terser": "^7.0.2", "ts-node": "^10.9.2", "tsify": "^5.0.4", - "typescript": "^4.9.5" + "typescript": "^5.3.3" }, "collective": { "type": "opencollective", diff --git a/spec/types/async-validate.spec.ts b/spec/types/async-validate.spec.ts index 8e3f0588c..44a452957 100644 --- a/spec/types/async-validate.spec.ts +++ b/spec/types/async-validate.spec.ts @@ -110,7 +110,7 @@ describe("$async validation and type guards", () => { let result: boolean | Promise if ((result = validate(data))) { if (typeof result == "boolean") { - data.foo.should.equal(1) + (data as any).foo.should.equal(1) } else { await result.then((_data) => _data.foo.should.equal(1)) }