Skip to content

Commit

Permalink
chore: update ts, eslint, config etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoniangreen committed Mar 3, 2024
1 parent 6fb3408 commit dab8d65
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 7 deletions.
28 changes: 28 additions & 0 deletions lib/compile/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand Down Expand Up @@ -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[]
) {
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -789,6 +815,7 @@ function addExprNames(names: UsedNames, from: SafeExpr): UsedNames {
}

function optimizeExpr<T extends SafeExpr | Code>(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
Expand Down Expand Up @@ -823,6 +850,7 @@ function subtractNames(names: UsedNames, from: UsedNames): void {
}

export function not<T extends Code | SafeExpr>(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)}`
}
Expand Down
1 change: 1 addition & 0 deletions lib/compile/validate/dataType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,17 @@ export default class Ajv {
validate<T>(schema: JTDSchemaType<T>, 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<N extends never, T extends SomeJTDSchemaType>(
schema: T,
data: unknown
): data is JTDDataType<T>
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
validate<T>(schema: AsyncSchema, data: unknown | T): Promise<T>
validate<T>(schemaKeyRef: AnySchema | string, data: unknown): data is T | Promise<T>
validate<T>(
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<T> {
let v: AnyValidateFunction | undefined
Expand All @@ -374,6 +377,7 @@ export default class Ajv {
compile<T = unknown>(schema: JTDSchemaType<T>, _meta?: boolean): ValidateFunction<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
compile<N extends never, T extends SomeJTDSchemaType>(
schema: T,
_meta?: boolean
Expand Down
1 change: 1 addition & 0 deletions lib/standalone/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> {
Expand Down
1 change: 1 addition & 0 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface DataValidationCxt<T extends string | number = string | number>
}

export interface ValidateFunction<T = unknown> {
// 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
Expand Down
1 change: 1 addition & 0 deletions lib/vocabularies/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`,
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion spec/types/async-validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe("$async validation and type guards", () => {
let result: boolean | Promise<Foo>
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))
}
Expand Down

0 comments on commit dab8d65

Please sign in to comment.