Skip to content

Commit d80a985

Browse files
committed
lint
1 parent 01fa857 commit d80a985

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

schema.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export class $ConstructedBy extends $Schema {
146146
super()
147147
this.v = c
148148
}
149+
149150
/**
150151
* @param {any} o
151152
* @return {o is C extends ((...args:any[]) => infer T) ? T : (C extends (new (...args:any[]) => any) ? InstanceType<C> : never)} o
@@ -184,7 +185,6 @@ export class $Literal extends $Schema {
184185
}
185186
}
186187

187-
188188
/**
189189
* @template {LiteralType[]} T
190190
* @param {T} literals
@@ -439,7 +439,7 @@ export const string = constructedBy(String)
439439
/**
440440
* @type {$Schema<undefined>}
441441
*/
442-
const undefined_ = literal(void 0)
442+
const undefined_ = literal(undefined)
443443

444444
/**
445445
* @type {$Schema<void>}
@@ -451,18 +451,20 @@ const void_ = undefined_
451451
*/
452452
const null_ = literal(null)
453453

454-
export {null_ as null, void_ as void, undefined_ as undefined, }
454+
export { null_ as null, void_ as void, undefined_ as undefined }
455455

456-
/* c8 ignore start*/
456+
/* c8 ignore start */
457457
/**
458458
* Assert that a variable is of this specific type.
459459
* The assertion check is only performed in non-production environments.
460460
*
461461
* @type {<T>(o:any,schema:$Schema<T>) => asserts o is T}
462462
*/
463-
export const assert = env.production ? () => {} : (o, schema) => {
464-
if (!schema.check(o)) {
465-
throw error.create(`Expected value to be of type ${schema.constructor.name}.`)
466-
}
467-
}
463+
export const assert = env.production
464+
? () => {}
465+
: (o, schema) => {
466+
if (!schema.check(o)) {
467+
throw error.create(`Expected value to be of type ${schema.constructor.name}.`)
468+
}
469+
}
468470
/* c8 ignore end */

schema.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const testSchemas = _tc => {
2525
t.assert(!s.bigint.validate(new Date()))
2626
})
2727
t.group('symbol', () => {
28-
t.assert(s.symbol.validate(Symbol()))
28+
t.assert(s.symbol.validate(Symbol('random symbol')))
2929
// @ts-expect-error
3030
t.assert(!s.symbol.validate({}))
3131
// @ts-expect-error
@@ -45,15 +45,15 @@ export const testSchemas = _tc => {
4545
const myobject = s.object({
4646
num: s.number
4747
})
48-
const q = /** @type {number} */ (/** @type {any} */ ({ num: 42, x:9 }))
48+
const q = /** @type {number} */ (/** @type {any} */ ({ num: 42, x: 9 }))
4949
if (myobject.check(q)) {
5050
s.number.validate(q)
5151
myobject.validate(q)
5252
} else {
5353
// q is a number now
5454
s.number.validate(q)
5555
}
56-
t.assert(myobject.check({ num: 42, x:9 }))
56+
t.assert(myobject.check({ num: 42, x: 9 }))
5757
// @ts-expect-error
5858
t.assert(!myobject.validate(undefined))
5959
// @ts-expect-error
@@ -92,7 +92,7 @@ export const testSchemas = _tc => {
9292
class BetterString extends String { }
9393
// @ts-expect-error
9494
t.assert(!s.string.validate(new BetterString()))
95-
t.assert(s.string.validate("hi"))
95+
t.assert(s.string.validate('hi'))
9696
// @ts-expect-error
9797
t.assert(!s.string.validate(undefined))
9898
// @ts-expect-error
@@ -111,7 +111,7 @@ export const testSchemas = _tc => {
111111
{
112112
const mysimplearray = s.array(s.object({}))
113113
// @ts-expect-error
114-
if (env.production) t.fails(() => t.assert(mysimplearray.ensure({x: 4})))
114+
if (env.production) t.fails(() => t.assert(mysimplearray.ensure({ x: 4 })))
115115
mysimplearray.cast([{}])
116116
}
117117
})
@@ -132,7 +132,7 @@ export const testSchemas = _tc => {
132132
t.assert(!myintersectionNever.validate(42))
133133
// @ts-expect-error
134134
t.assert(!myintersectionNever.validate('str'))
135-
const myintersection = s.intersect(s.object({a: s.number}), s.object({ b: s.number }))
135+
const myintersection = s.intersect(s.object({ a: s.number }), s.object({ b: s.number }))
136136
t.assert(myintersection.validate({ a: 42, b: 42 }))
137137
// @ts-expect-error
138138
t.assert(!myintersection.validate({ a: 42 }))
@@ -208,12 +208,12 @@ export const testSchemas = _tc => {
208208
$fun.validate(/** @param {number} n */ (n) => n) // expected string result
209209
const $fun2 = s.lambda(s.number, s.string, s.void)
210210
t.assert($fun2.validate(() => ''))
211-
t.assert($fun2.validate(/** @param {number} n */ (n) => n+''))
211+
t.assert($fun2.validate(/** @param {number} n */ (n) => n + ''))
212212
t.assert($fun2.validate(/** @param {number} n */ (n) => n)) // this works now, because void is the absense of value
213213
const $fun3 = s.lambda(s.number, s.undefined)
214214
// @ts-expect-error
215215
$fun3.validate(/** @param {number} n */ (n) => n) // this doesn't work, because expected the literal undefined.
216216
// @ts-expect-error
217-
t.assert(!$fun3.validate(/** @type {(a: number, b: number) => undefined} */ ((a, b) => undefined))) // too many parameters
217+
t.assert(!$fun3.validate(/** @type {(a: number, b: number) => undefined} */ (a, b) => undefined)) // too many parameters
218218
})
219219
}

0 commit comments

Comments
 (0)