diff --git a/examples/example-plugin/src/toBeEven.ts b/examples/example-plugin/src/toBeEven.ts index 0f928397..ffbb965e 100644 --- a/examples/example-plugin/src/toBeEven.ts +++ b/examples/example-plugin/src/toBeEven.ts @@ -1,7 +1,6 @@ -import { Control, formatCompact, registerValidator } from 'earl' +import { type Control, formatCompact, registerValidator } from 'earl' declare module 'earl' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { toBeEven(this: Validators): void } diff --git a/packages/e2e/test-esbuild/stack-traces.test.ts b/packages/e2e/test-esbuild/stack-traces.test.ts index de8f49ee..3236e347 100644 --- a/packages/e2e/test-esbuild/stack-traces.test.ts +++ b/packages/e2e/test-esbuild/stack-traces.test.ts @@ -28,7 +28,7 @@ async function captureErrorAsync(fn: () => Promise) { function getStack(error: Error) { const stack = utils.stackTraceFilter()(error.stack ?? '') - return Parser.parse({ stack } as any).map((x) => ({ + return Parser.parse({ stack } as Error).map((x) => ({ at: x.functionName, file: x.fileName, })) diff --git a/packages/e2e/test-ts-node/stack-traces.test.ts b/packages/e2e/test-ts-node/stack-traces.test.ts index de8f49ee..3236e347 100644 --- a/packages/e2e/test-ts-node/stack-traces.test.ts +++ b/packages/e2e/test-ts-node/stack-traces.test.ts @@ -28,7 +28,7 @@ async function captureErrorAsync(fn: () => Promise) { function getStack(error: Error) { const stack = utils.stackTraceFilter()(error.stack ?? '') - return Parser.parse({ stack } as any).map((x) => ({ + return Parser.parse({ stack } as Error).map((x) => ({ at: x.functionName, file: x.fileName, })) diff --git a/packages/earl/src/expect.ts b/packages/earl/src/expect.ts index eca95d07..bd17ccb5 100644 --- a/packages/earl/src/expect.ts +++ b/packages/earl/src/expect.ts @@ -2,11 +2,10 @@ import { Control } from './Control.js' import { formatCompact } from './format/index.js' // to be overridden by plugins -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export interface Validators {} +export type Validators = {} // to be overridden by plugins -export interface Matchers {} +export type Matchers = {} export class Matcher { constructor( diff --git a/packages/earl/src/format/FormatOptions.ts b/packages/earl/src/format/FormatOptions.ts index 4f097453..0ac9c71f 100644 --- a/packages/earl/src/format/FormatOptions.ts +++ b/packages/earl/src/format/FormatOptions.ts @@ -31,7 +31,7 @@ export const DEFAULT_FORMAT_OPTIONS: FormatOptions = { ...DEFAULT_EQUALITY_OPTIONS, indentSize: 2, inline: false, - maxLineLength: Infinity, + maxLineLength: Number.POSITIVE_INFINITY, skipMatcherReplacement: false, requireStrictEquality: false, } diff --git a/packages/earl/src/format/format.test.ts b/packages/earl/src/format/format.test.ts index 42d965dc..2448511a 100644 --- a/packages/earl/src/format/format.test.ts +++ b/packages/earl/src/format/format.test.ts @@ -14,7 +14,7 @@ describe('format', () => { compareErrorStack: false, indentSize: 2, inline: false, - maxLineLength: Infinity, + maxLineLength: Number.POSITIVE_INFINITY, skipMatcherReplacement: false, requireStrictEquality: false, } @@ -33,11 +33,11 @@ describe('format', () => { [0.2, null, '0.2'], [-3, null, '-3'], [1e50, null, '1e+50'], - [NaN, null, 'NaN'], - [NaN, NaN, 'NaN'], - [NaN, NaN, 'NaN (different)', { uniqueNaNs: true }], - [Infinity, null, 'Infinity'], - [-Infinity, null, '-Infinity'], + [Number.NaN, null, 'NaN'], + [Number.NaN, Number.NaN, 'NaN'], + [Number.NaN, Number.NaN, 'NaN (different)', { uniqueNaNs: true }], + [Number.POSITIVE_INFINITY, null, 'Infinity'], + [Number.NEGATIVE_INFINITY, null, '-Infinity'], [0, null, '0'], [-0, null, '0'], [-0, null, '-0', { minusZero: true }], @@ -85,8 +85,8 @@ describe('format', () => { testCases: [ [function a() {}, null, 'function a()'], [function a() {}, function a() {}, 'function a() (different)'], - [function () {}, null, 'function [anonymous]()'], - [function () {}, function () {}, 'function [anonymous]() (different)'], + [() => {}, null, 'function [anonymous]()'], + [() => {}, () => {}, 'function [anonymous]() (different)'], [function* foo() {}, null, 'function* foo()'], [function* foo() {}, function* foo() {}, 'function* foo() (different)'], [function* () {}, null, 'function* [anonymous]()'], @@ -97,7 +97,6 @@ describe('format', () => { ], // This is eval-ed to avoid typescript transpiling it // With a higher target this wouldn't be necessary - // eslint-disable-next-line no-eval ...eval(`[ [async function foo() {}, null, 'async function foo()'], [async function foo() {}, async function foo() {}, 'async function foo() (different)'], @@ -126,7 +125,7 @@ describe('format', () => { 'function x() (different) & {\n a: 1\n}', ], [ - Object.assign(function () {}, { a: 1 }), + Object.assign(() => {}, { a: 1 }), null, 'function [anonymous]() & {\n a: 1\n}', ], diff --git a/packages/earl/src/format/formatCompact.test.ts b/packages/earl/src/format/formatCompact.test.ts index c18e1eae..be6dc53e 100644 --- a/packages/earl/src/format/formatCompact.test.ts +++ b/packages/earl/src/format/formatCompact.test.ts @@ -13,9 +13,9 @@ describe('formatCompact', () => { [0.2, '0.2'], [-3, '-3'], [1e50, '1e+50'], - [NaN, 'NaN'], - [Infinity, 'Infinity'], - [-Infinity, '-Infinity'], + [Number.NaN, 'NaN'], + [Number.POSITIVE_INFINITY, 'Infinity'], + [Number.NEGATIVE_INFINITY, '-Infinity'], [BigInt(1), '1n'], [BigInt(123), '123n'], [BigInt(-123), '-123n'], @@ -33,7 +33,7 @@ describe('formatCompact', () => { [undefined, 'undefined'], [true, 'true'], [false, 'false'], - [function () {}, 'function [anonymous]()'], + [() => {}, 'function [anonymous]()'], [function foo() {}, 'function foo()'], [class Foo {}, 'class Foo'], [class {}, 'class [anonymous]'], diff --git a/packages/earl/src/format/formatNumber.ts b/packages/earl/src/format/formatNumber.ts index c3f1fe37..eb869bf8 100644 --- a/packages/earl/src/format/formatNumber.ts +++ b/packages/earl/src/format/formatNumber.ts @@ -8,8 +8,8 @@ export function formatNumber( ) { if (Object.is(value, -0) && options.minusZero) { return toLine('-0') - } else if (Object.is(value, NaN)) { - if (options.uniqueNaNs && Object.is(sibling, NaN)) { + } else if (Object.is(value, Number.NaN)) { + if (options.uniqueNaNs && Object.is(sibling, Number.NaN)) { return toLine('NaN (different)') } return toLine('NaN') diff --git a/packages/earl/src/format/formatUnknown.ts b/packages/earl/src/format/formatUnknown.ts index 894c564d..c62556cd 100644 --- a/packages/earl/src/format/formatUnknown.ts +++ b/packages/earl/src/format/formatUnknown.ts @@ -87,7 +87,7 @@ export function formatUnknown( if ( type === 'Error' && options.inline && - options.maxLineLength !== Infinity + options.maxLineLength !== Number.POSITIVE_INFINITY ) { return toLine( `${typeName ?? ''}(${formatString((value as Error).message, options)})`, diff --git a/packages/earl/src/format/getComparedTypeName.ts b/packages/earl/src/format/getComparedTypeName.ts index e62ae48e..f0f48814 100644 --- a/packages/earl/src/format/getComparedTypeName.ts +++ b/packages/earl/src/format/getComparedTypeName.ts @@ -57,14 +57,12 @@ function getPrototypeName(value: object) { return '[custom prototype]' } -// eslint-disable-next-line @typescript-eslint/ban-types export function getFunctionTypeName(value: Function) { const type = getFunctionType(value) const name = value.name || '[anonymous]' return `${type} ${name}${type === 'class' ? '' : '()'}` } -// eslint-disable-next-line @typescript-eslint/ban-types function getFunctionType(value: Function) { if (value.toString().startsWith('class')) { return 'class' diff --git a/packages/earl/src/isEqual/isEqual.perf.test.ts b/packages/earl/src/isEqual/isEqual.perf.test.ts index 130f939e..47784d07 100644 --- a/packages/earl/src/isEqual/isEqual.perf.test.ts +++ b/packages/earl/src/isEqual/isEqual.perf.test.ts @@ -29,7 +29,7 @@ describe('isEqual performance', function () { roles: ['User', 'Admin'], } - it('measure', function () { + it('measure', () => { const repeat = 5 const iterations = 2000 const testValue = [dataObject, dataObject, dataObject] diff --git a/packages/earl/src/isEqual/isEqual.test.ts b/packages/earl/src/isEqual/isEqual.test.ts index ca6fc758..e75d1db8 100644 --- a/packages/earl/src/isEqual/isEqual.test.ts +++ b/packages/earl/src/isEqual/isEqual.test.ts @@ -20,7 +20,7 @@ describe('isEqual', () => { minusZero: true, indentSize: 2, inline: true, - maxLineLength: Infinity, + maxLineLength: Number.POSITIVE_INFINITY, skipMatcherReplacement: true, requireStrictEquality: false, } @@ -52,11 +52,11 @@ describe('isEqual', () => { [123.456, -123.456, false], [0, -0, true], [0, -0, false, { minusZero: true }], - [NaN, NaN, true], - [NaN, NaN, false, { uniqueNaNs: true }], - [Infinity, Infinity, true], - [Infinity, -Infinity, false], - [-Infinity, -Infinity, true], + [Number.NaN, Number.NaN, true], + [Number.NaN, Number.NaN, false, { uniqueNaNs: true }], + [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, true], + [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, false], + [Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, true], ], }, { @@ -119,9 +119,9 @@ describe('isEqual', () => { function* named() {}, async function named() {}, async function* named() {}, - function () {}, + () => {}, function* () {}, - async function () {}, + async () => {}, async function* () {}, ] const testCases: TestCase[] = [] @@ -330,13 +330,8 @@ describe('isEqual', () => { ...(() => { class MyRegExp extends RegExp {} return [ - [new RegExp('foo'), new MyRegExp('foo'), false], - [ - new RegExp('foo'), - new MyRegExp('foo'), - true, - { ignorePrototypes: true }, - ], + [/foo/, new MyRegExp('foo'), false], + [/foo/, new MyRegExp('foo'), true, { ignorePrototypes: true }], [new MyRegExp('foo'), new MyRegExp('foo'), true], [new MyRegExp('foo'), new MyRegExp('bar'), false], [ @@ -651,7 +646,7 @@ describe('isEqual', () => { ...equalityOptions, indentSize: 2, inline: false, - maxLineLength: Infinity, + maxLineLength: Number.POSITIVE_INFINITY, skipMatcherReplacement: false, requireStrictEquality: false, } diff --git a/packages/earl/src/isEqual/isEqualNumber.ts b/packages/earl/src/isEqual/isEqualNumber.ts index b57f100a..307e8b49 100644 --- a/packages/earl/src/isEqual/isEqualNumber.ts +++ b/packages/earl/src/isEqual/isEqualNumber.ts @@ -5,8 +5,8 @@ export function isEqualNumber( other: number, options: EqualityOptions, ) { - if (isNaN(value)) { - return options.uniqueNaNs ? false : isNaN(other) + if (Number.isNaN(value)) { + return options.uniqueNaNs ? false : Number.isNaN(other) } else if (value === 0) { return options.minusZero ? Object.is(value, other) : other === 0 } else { diff --git a/packages/earl/src/isEqual/isEqualObject.ts b/packages/earl/src/isEqual/isEqualObject.ts index 4b4d99c4..a862fd5a 100644 --- a/packages/earl/src/isEqual/isEqualObject.ts +++ b/packages/earl/src/isEqual/isEqualObject.ts @@ -27,10 +27,10 @@ export function isEqualObject( for (let i = 0; i < keys.length; i++) { if ( !isEqualUnknown( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + // biome-ignore lint/style/noNonNullAssertion: We know that the key exists (value as any)[keys[i]!], valueStack, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + // biome-ignore lint/style/noNonNullAssertion: We know that the key exists (other as any)[otherKeys[i]!], otherStack, options, diff --git a/packages/earl/src/matchers/basic/a.test.ts b/packages/earl/src/matchers/basic/a.test.ts index cd19a60f..c4707609 100644 --- a/packages/earl/src/matchers/basic/a.test.ts +++ b/packages/earl/src/matchers/basic/a.test.ts @@ -24,8 +24,10 @@ describe(a.name, () => { testMatcher( a(Number), - TEST_VALUES.filter((x) => typeof x === 'number' && !Number.isNaN(x)), - TEST_VALUES.filter((x) => typeof x !== 'number').concat(NaN), + TEST_VALUES.filter( + (x) => typeof x === 'number' && !Number.Number.isNaN(x), + ), + TEST_VALUES.filter((x) => typeof x !== 'number').concat(Number.NaN), ) }) diff --git a/packages/earl/src/matchers/basic/a.ts b/packages/earl/src/matchers/basic/a.ts index 8e5abc8a..110befd3 100644 --- a/packages/earl/src/matchers/basic/a.ts +++ b/packages/earl/src/matchers/basic/a.ts @@ -47,7 +47,7 @@ export function a(type: NewableOrPrimitive) { if (type === String) { return typeof value === 'string' } else if (type === Number) { - return typeof value === 'number' && !isNaN(value) + return typeof value === 'number' && !Number.isNaN(value) } else if (type === Boolean) { return typeof value === 'boolean' } else if (type === BigInt) { diff --git a/packages/earl/src/matchers/numbers/between.test.ts b/packages/earl/src/matchers/numbers/between.test.ts index faa36c77..0416c0a1 100644 --- a/packages/earl/src/matchers/numbers/between.test.ts +++ b/packages/earl/src/matchers/numbers/between.test.ts @@ -19,7 +19,7 @@ describe(between.name, () => { -Number.EPSILON, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, - NaN, + Number.NaN, ...TEST_VALUES.filter( (x) => typeof x !== 'number' && typeof x !== 'bigint', ), diff --git a/packages/earl/src/matchers/numbers/closeTo.test.ts b/packages/earl/src/matchers/numbers/closeTo.test.ts index cdbed610..22785b4d 100644 --- a/packages/earl/src/matchers/numbers/closeTo.test.ts +++ b/packages/earl/src/matchers/numbers/closeTo.test.ts @@ -15,7 +15,7 @@ describe(closeTo.name, () => { 5, 123, -4, - NaN, + Number.NaN, ...TEST_VALUES.filter((x) => typeof x !== 'number'), ], ) diff --git a/packages/earl/src/matchers/numbers/greaterThan.test.ts b/packages/earl/src/matchers/numbers/greaterThan.test.ts index 042441b9..7b0d9c57 100644 --- a/packages/earl/src/matchers/numbers/greaterThan.test.ts +++ b/packages/earl/src/matchers/numbers/greaterThan.test.ts @@ -9,7 +9,15 @@ describe(greaterThan.name, () => { describe('greaterThan(10)', () => { testMatcher( greaterThan(10), - [11, 10.5, 100, 12356.789, Infinity, BigInt(11), BigInt(100)], + [ + 11, + 10.5, + 100, + 12356.789, + Number.POSITIVE_INFINITY, + BigInt(11), + BigInt(100), + ], [ 10, 0, @@ -19,8 +27,8 @@ describe(greaterThan.name, () => { 9.998, 5, -4, - NaN, - -Infinity, + Number.NaN, + Number.NEGATIVE_INFINITY, BigInt(10), BigInt(0), BigInt(-100), diff --git a/packages/earl/src/matchers/numbers/greaterThanOrEqual.test.ts b/packages/earl/src/matchers/numbers/greaterThanOrEqual.test.ts index 9c00dd93..62912466 100644 --- a/packages/earl/src/matchers/numbers/greaterThanOrEqual.test.ts +++ b/packages/earl/src/matchers/numbers/greaterThanOrEqual.test.ts @@ -15,7 +15,7 @@ describe(greaterThanOrEqual.name, () => { 10.5, 100, 12356.789, - Infinity, + Number.POSITIVE_INFINITY, BigInt(10), BigInt(11), BigInt(100), @@ -28,8 +28,8 @@ describe(greaterThanOrEqual.name, () => { 9.998, 5, -4, - NaN, - -Infinity, + Number.NaN, + Number.NEGATIVE_INFINITY, BigInt(0), BigInt(-100), ...TEST_VALUES.filter( diff --git a/packages/earl/src/matchers/numbers/integer.test.ts b/packages/earl/src/matchers/numbers/integer.test.ts index 14251eed..45005443 100644 --- a/packages/earl/src/matchers/numbers/integer.test.ts +++ b/packages/earl/src/matchers/numbers/integer.test.ts @@ -24,9 +24,9 @@ describe(integer.name, () => { [ 0.5, -1.2, - Infinity, - -Infinity, - NaN, + Number.POSITIVE_INFINITY, + Number.NEGATIVE_INFINITY, + Number.NaN, TEST_VALUES.filter((x) => typeof x !== 'number' && typeof x !== 'bigint'), ], ) diff --git a/packages/earl/src/matchers/numbers/lessThan.test.ts b/packages/earl/src/matchers/numbers/lessThan.test.ts index 82474370..5464ea32 100644 --- a/packages/earl/src/matchers/numbers/lessThan.test.ts +++ b/packages/earl/src/matchers/numbers/lessThan.test.ts @@ -17,7 +17,7 @@ describe(lessThan.name, () => { -1, -100, -12356.789, - -Infinity, + Number.NEGATIVE_INFINITY, BigInt(9), BigInt(0), BigInt(-100), @@ -26,8 +26,8 @@ describe(lessThan.name, () => { 10, 11, 19.998, - NaN, - Infinity, + Number.NaN, + Number.POSITIVE_INFINITY, BigInt(10), BigInt(100), ...TEST_VALUES.filter( diff --git a/packages/earl/src/matchers/numbers/lessThanOrEqual.test.ts b/packages/earl/src/matchers/numbers/lessThanOrEqual.test.ts index 905f5894..dd0474b8 100644 --- a/packages/earl/src/matchers/numbers/lessThanOrEqual.test.ts +++ b/packages/earl/src/matchers/numbers/lessThanOrEqual.test.ts @@ -18,7 +18,7 @@ describe(lessThanOrEqual.name, () => { -1, -100, -12356.789, - -Infinity, + Number.NEGATIVE_INFINITY, BigInt(10), BigInt(9), BigInt(0), @@ -27,8 +27,8 @@ describe(lessThanOrEqual.name, () => { [ 11, 19.998, - NaN, - Infinity, + Number.NaN, + Number.POSITIVE_INFINITY, BigInt(100), ...TEST_VALUES.filter( (x) => typeof x !== 'number' && typeof x !== 'bigint', diff --git a/packages/earl/src/matchers/numbers/safeInteger.test.ts b/packages/earl/src/matchers/numbers/safeInteger.test.ts index 608523ce..827400f1 100644 --- a/packages/earl/src/matchers/numbers/safeInteger.test.ts +++ b/packages/earl/src/matchers/numbers/safeInteger.test.ts @@ -31,9 +31,9 @@ describe(safeInteger.name, () => { Number.MIN_SAFE_INTEGER * 2, BigInt(Number.MAX_SAFE_INTEGER) * BigInt(2), BigInt(Number.MIN_SAFE_INTEGER) * BigInt(2), - Infinity, - -Infinity, - NaN, + Number.POSITIVE_INFINITY, + Number.NEGATIVE_INFINITY, + Number.NaN, TEST_VALUES.filter((x) => typeof x !== 'number' && typeof x !== 'bigint'), ], ) diff --git a/packages/earl/src/mocks/mockFn.ts b/packages/earl/src/mocks/mockFn.ts index a3c84c29..dacaaf86 100644 --- a/packages/earl/src/mocks/mockFn.ts +++ b/packages/earl/src/mocks/mockFn.ts @@ -61,17 +61,12 @@ export function mockFn( mock[mockSymbol] = true mock.calls = [] as MockCall[] - mock.isExhausted = function () { - return oneTimeOverrides.length === 0 && parameterOverrides.length === 0 - } + mock.isExhausted = () => + oneTimeOverrides.length === 0 && parameterOverrides.length === 0 - mock.getOneTimeOverridesLength = function () { - return oneTimeOverrides.length - } + mock.getOneTimeOverridesLength = () => oneTimeOverrides.length - mock.getParameterOverridesLength = function () { - return parameterOverrides.length - } + mock.getParameterOverridesLength = () => parameterOverrides.length function runSpec(spec: Spec, args: any[]) { switch (spec.type) { @@ -114,7 +109,7 @@ export function mockFn( } } - mock.reset = function () { + mock.reset = () => { defaultSpec = { type: 'not-ready' } oneTimeOverrides = [] parameterOverrides = [] @@ -124,56 +119,56 @@ export function mockFn( } } - mock.clear = function () { + mock.clear = () => { mock.calls = [] } - mock.returns = function (value: any) { + mock.returns = (value: any) => { defaultSpec = { type: 'return', value } return mock } - mock.returnsOnce = function (value: any) { + mock.returnsOnce = (value: any) => { oneTimeOverrides.push({ type: 'return', value }) return mock } - mock.throws = function (error: any) { + mock.throws = (error: any) => { defaultSpec = { type: 'throw', error } return mock } - mock.throwsOnce = function (error: any) { + mock.throwsOnce = (error: any) => { oneTimeOverrides.push({ type: 'throw', error }) return mock } - mock.executes = function (implementation: (...args: any[]) => any) { + mock.executes = (implementation: (...args: any[]) => any) => { defaultSpec = { type: 'exec', implementation } return mock } - mock.executesOnce = function (implementation: (...args: any[]) => any) { + mock.executesOnce = (implementation: (...args: any[]) => any) => { oneTimeOverrides.push({ type: 'exec', implementation }) return mock } - mock.resolvesTo = function (value: any) { + mock.resolvesTo = (value: any) => { defaultSpec = { type: 'return', value: Promise.resolve(value) } return mock } - mock.resolvesToOnce = function (value: any) { + mock.resolvesToOnce = (value: any) => { oneTimeOverrides.push({ type: 'return', value: Promise.resolve(value) }) return mock } - mock.rejectsWith = function (error: any) { + mock.rejectsWith = (error: any) => { defaultSpec = { type: 'lazy-return', value: () => Promise.reject(error) } return mock } - mock.rejectsWithOnce = function (error: any) { + mock.rejectsWithOnce = (error: any) => { oneTimeOverrides.push({ type: 'lazy-return', value: () => Promise.reject(error), @@ -181,43 +176,41 @@ export function mockFn( return mock } - mock.given = function (...args: any[]) { - return { - returnsOnce(value: any) { - parameterOverrides.push({ args, spec: { type: 'return', value } }) - return mock - }, - - throwsOnce(error: any) { - parameterOverrides.push({ args, spec: { type: 'throw', error } }) - return mock - }, - - executesOnce(implementation: (...args: any[]) => any) { - parameterOverrides.push({ - args, - spec: { type: 'exec', implementation }, - }) - return mock - }, - - resolvesToOnce(value: any) { - parameterOverrides.push({ - args, - spec: { type: 'return', value: Promise.resolve(value) }, - }) - return mock - }, - - rejectsWithOnce(error: any) { - parameterOverrides.push({ - args, - spec: { type: 'lazy-return', value: () => Promise.reject(error) }, - }) - return mock - }, - } - } + mock.given = (...args: any[]) => ({ + returnsOnce(value: any) { + parameterOverrides.push({ args, spec: { type: 'return', value } }) + return mock + }, + + throwsOnce(error: any) { + parameterOverrides.push({ args, spec: { type: 'throw', error } }) + return mock + }, + + executesOnce(implementation: (...args: any[]) => any) { + parameterOverrides.push({ + args, + spec: { type: 'exec', implementation }, + }) + return mock + }, + + resolvesToOnce(value: any) { + parameterOverrides.push({ + args, + spec: { type: 'return', value: Promise.resolve(value) }, + }) + return mock + }, + + rejectsWithOnce(error: any) { + parameterOverrides.push({ + args, + spec: { type: 'lazy-return', value: () => Promise.reject(error) }, + }) + return mock + }, + }) if (defaultImplementation) { mock.executes(defaultImplementation) diff --git a/packages/earl/src/test/errors.ts b/packages/earl/src/test/errors.ts index 991670cc..960db657 100644 --- a/packages/earl/src/test/errors.ts +++ b/packages/earl/src/test/errors.ts @@ -48,7 +48,6 @@ export function stripIndent( ...expressions: unknown[] ) { const result = template.reduce((accumulator, part, i) => { - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands return accumulator + expressions[i - 1] + part }) @@ -69,7 +68,7 @@ export function stripIndent( ...lines.filter((line) => !/^\s*$/.test(line)).map(leadingSpaces), ) - if (minIndent === Infinity) { + if (minIndent === Number.POSITIVE_INFINITY) { minIndent = 0 } diff --git a/packages/earl/src/test/values.ts b/packages/earl/src/test/values.ts index e34a8fc8..206f8a8e 100644 --- a/packages/earl/src/test/values.ts +++ b/packages/earl/src/test/values.ts @@ -15,7 +15,7 @@ export const TEST_NUMBERS = [ Number.EPSILON, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, - NaN, + Number.NaN, ] export const TEST_BIGINTS = [BigInt(0), BigInt(1), BigInt(-1000), BigInt(1000)] diff --git a/packages/earl/src/validators/basic/toBeA.ts b/packages/earl/src/validators/basic/toBeA.ts index 665389c7..876ab856 100644 --- a/packages/earl/src/validators/basic/toBeA.ts +++ b/packages/earl/src/validators/basic/toBeA.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { a, type NewableOrPrimitive } from '../../matchers/basic/a.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that the value is an instance of a provided class or a primitive diff --git a/packages/earl/src/validators/basic/toBeFalsy.test.ts b/packages/earl/src/validators/basic/toBeFalsy.test.ts index e7ed2526..83191321 100644 --- a/packages/earl/src/validators/basic/toBeFalsy.test.ts +++ b/packages/earl/src/validators/basic/toBeFalsy.test.ts @@ -4,7 +4,7 @@ import { expect as earl, formatCompact } from '../../index.js' import { toBeFalsy } from './toBeFalsy.js' describe(toBeFalsy.name, () => { - const falsyValues = [null, undefined, false, 0, NaN, ''] + const falsyValues = [null, undefined, false, 0, Number.NaN, ''] const truthyValues = [true, 42, 'hello', {}, [], () => {}] describe('without .not', () => { diff --git a/packages/earl/src/validators/basic/toBeFalsy.ts b/packages/earl/src/validators/basic/toBeFalsy.ts index 39b763e9..e18a949a 100644 --- a/packages/earl/src/validators/basic/toBeFalsy.ts +++ b/packages/earl/src/validators/basic/toBeFalsy.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { falsy } from '../../matchers/basic/falsy.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a value is falsy, as defined by: diff --git a/packages/earl/src/validators/basic/toBeNullish.ts b/packages/earl/src/validators/basic/toBeNullish.ts index 7613d080..3371d58f 100644 --- a/packages/earl/src/validators/basic/toBeNullish.ts +++ b/packages/earl/src/validators/basic/toBeNullish.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { nullish } from '../../matchers/basic/nullish.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a value is nullish, meaning it is either `null` or diff --git a/packages/earl/src/validators/basic/toBeTruthy.test.ts b/packages/earl/src/validators/basic/toBeTruthy.test.ts index 3bd6df93..8821f720 100644 --- a/packages/earl/src/validators/basic/toBeTruthy.test.ts +++ b/packages/earl/src/validators/basic/toBeTruthy.test.ts @@ -5,7 +5,7 @@ import { toBeTruthy } from './toBeTruthy.js' describe(toBeTruthy.name, () => { const truthyValues = [true, 42, 'hello', {}, [], () => {}] - const falsyValues = [null, undefined, false, 0, NaN, ''] + const falsyValues = [null, undefined, false, 0, Number.NaN, ''] describe('without .not', () => { describe('with truthy values', () => { diff --git a/packages/earl/src/validators/basic/toBeTruthy.ts b/packages/earl/src/validators/basic/toBeTruthy.ts index 80933864..0807d635 100644 --- a/packages/earl/src/validators/basic/toBeTruthy.ts +++ b/packages/earl/src/validators/basic/toBeTruthy.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { truthy } from '../../matchers/basic/truthy.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a value is truthy, as defined by: diff --git a/packages/earl/src/validators/basic/toMatchRegex.ts b/packages/earl/src/validators/basic/toMatchRegex.ts index 2e954fe4..d0baa526 100644 --- a/packages/earl/src/validators/basic/toMatchRegex.ts +++ b/packages/earl/src/validators/basic/toMatchRegex.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { regex } from '../../matchers/basic/regex.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that the value is a string matching the given regular expression. diff --git a/packages/earl/src/validators/custom/toMatchSchema.ts b/packages/earl/src/validators/custom/toMatchSchema.ts index 3c1b34be..3eab2a9c 100644 --- a/packages/earl/src/validators/custom/toMatchSchema.ts +++ b/packages/earl/src/validators/custom/toMatchSchema.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { schema, type ZodSchema } from '../../matchers/custom/schema.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that the value conforms to the provided zod schema. diff --git a/packages/earl/src/validators/custom/toSatisfy.ts b/packages/earl/src/validators/custom/toSatisfy.ts index 0eb772d6..88a76d11 100644 --- a/packages/earl/src/validators/custom/toSatisfy.ts +++ b/packages/earl/src/validators/custom/toSatisfy.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { satisfies } from '../../matchers/custom/satisfies.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that the provided predicate returns a truthy result for the given diff --git a/packages/earl/src/validators/mocks/toHaveBeenCalled.ts b/packages/earl/src/validators/mocks/toHaveBeenCalled.ts index c22bf990..7694e1c0 100644 --- a/packages/earl/src/validators/mocks/toHaveBeenCalled.ts +++ b/packages/earl/src/validators/mocks/toHaveBeenCalled.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import type { MockFunction } from '../../mocks/index.js' import { assertIsMock, formatCalledTimes } from './utils.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that the mock function has been called at least once. diff --git a/packages/earl/src/validators/mocks/toHaveBeenCalledTimes.ts b/packages/earl/src/validators/mocks/toHaveBeenCalledTimes.ts index 68bc840c..c5671690 100644 --- a/packages/earl/src/validators/mocks/toHaveBeenCalledTimes.ts +++ b/packages/earl/src/validators/mocks/toHaveBeenCalledTimes.ts @@ -1,11 +1,10 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import type { MockFunction } from '../../mocks/index.js' import { assertIsMock, formatCalledTimes, formatTimes } from './utils.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that the mock function was called the given number of times. diff --git a/packages/earl/src/validators/mocks/toHaveBeenCalledWith.ts b/packages/earl/src/validators/mocks/toHaveBeenCalledWith.ts index 5270c205..920f4744 100644 --- a/packages/earl/src/validators/mocks/toHaveBeenCalledWith.ts +++ b/packages/earl/src/validators/mocks/toHaveBeenCalledWith.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { isEqual } from '../../isEqual/index.js' diff --git a/packages/earl/src/validators/mocks/toHaveBeenExhausted.ts b/packages/earl/src/validators/mocks/toHaveBeenExhausted.ts index 199bc7cf..44f844cf 100644 --- a/packages/earl/src/validators/mocks/toHaveBeenExhausted.ts +++ b/packages/earl/src/validators/mocks/toHaveBeenExhausted.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import type { MockFunction } from '../../mocks/index.js' import { assertIsMock } from './utils.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that the mock function was called enough so that all the diff --git a/packages/earl/src/validators/mocks/toHaveBeenLastCalledWith.ts b/packages/earl/src/validators/mocks/toHaveBeenLastCalledWith.ts index 73d771a2..7d8a9350 100644 --- a/packages/earl/src/validators/mocks/toHaveBeenLastCalledWith.ts +++ b/packages/earl/src/validators/mocks/toHaveBeenLastCalledWith.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import type { MockFunction, MockParameters } from '../../mocks/index.js' import { assertIsMock, compareArgs } from './utils.js' diff --git a/packages/earl/src/validators/mocks/toHaveBeenNthCalledWith.ts b/packages/earl/src/validators/mocks/toHaveBeenNthCalledWith.ts index c40263a6..9c0ab9fe 100644 --- a/packages/earl/src/validators/mocks/toHaveBeenNthCalledWith.ts +++ b/packages/earl/src/validators/mocks/toHaveBeenNthCalledWith.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import type { MockFunction, MockParameters } from '../../mocks/index.js' diff --git a/packages/earl/src/validators/mocks/toHaveBeenOnlyCalledWith.ts b/packages/earl/src/validators/mocks/toHaveBeenOnlyCalledWith.ts index 6d1508a7..7803297c 100644 --- a/packages/earl/src/validators/mocks/toHaveBeenOnlyCalledWith.ts +++ b/packages/earl/src/validators/mocks/toHaveBeenOnlyCalledWith.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import type { MockFunction, MockParameters } from '../../mocks/index.js' import { assertIsMock, compareArgs, formatCalledTimes } from './utils.js' diff --git a/packages/earl/src/validators/mocks/utils.ts b/packages/earl/src/validators/mocks/utils.ts index ecab1dbf..392f6626 100644 --- a/packages/earl/src/validators/mocks/utils.ts +++ b/packages/earl/src/validators/mocks/utils.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { formatCompact } from '../../format/index.js' import { isEqual } from '../../isEqual/index.js' import { isMockFn, type MockFunction } from '../../mocks/index.js' diff --git a/packages/earl/src/validators/numbers/toBeASafeInteger.ts b/packages/earl/src/validators/numbers/toBeASafeInteger.ts index 6c502daa..2a423f24 100644 --- a/packages/earl/src/validators/numbers/toBeASafeInteger.ts +++ b/packages/earl/src/validators/numbers/toBeASafeInteger.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { safeInteger } from '../../matchers/numbers/safeInteger.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a value is an integer or a bigint and falls within the safe diff --git a/packages/earl/src/validators/numbers/toBeAnInteger.ts b/packages/earl/src/validators/numbers/toBeAnInteger.ts index 857264a1..9bd40dfd 100644 --- a/packages/earl/src/validators/numbers/toBeAnInteger.ts +++ b/packages/earl/src/validators/numbers/toBeAnInteger.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { integer } from '../../matchers/numbers/integer.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a value is an integer or a bigint. diff --git a/packages/earl/src/validators/numbers/toBeBetween.ts b/packages/earl/src/validators/numbers/toBeBetween.ts index 98ccc44d..09694e95 100644 --- a/packages/earl/src/validators/numbers/toBeBetween.ts +++ b/packages/earl/src/validators/numbers/toBeBetween.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { between } from '../../matchers/numbers/between.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a number is between the two numbers. The range is diff --git a/packages/earl/src/validators/numbers/toBeCloseTo.ts b/packages/earl/src/validators/numbers/toBeCloseTo.ts index 2baff8d1..8337a151 100644 --- a/packages/earl/src/validators/numbers/toBeCloseTo.ts +++ b/packages/earl/src/validators/numbers/toBeCloseTo.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { closeTo } from '../../matchers/numbers/closeTo.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a number is close to the target value.The range is diff --git a/packages/earl/src/validators/numbers/toBeGreaterThan.ts b/packages/earl/src/validators/numbers/toBeGreaterThan.ts index 4d2af695..9cdaab4e 100644 --- a/packages/earl/src/validators/numbers/toBeGreaterThan.ts +++ b/packages/earl/src/validators/numbers/toBeGreaterThan.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { greaterThan } from '../../matchers/numbers/greaterThan.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a number is greater than the target value. diff --git a/packages/earl/src/validators/numbers/toBeGreaterThanOrEqual.ts b/packages/earl/src/validators/numbers/toBeGreaterThanOrEqual.ts index 8024ecab..1e1c3726 100644 --- a/packages/earl/src/validators/numbers/toBeGreaterThanOrEqual.ts +++ b/packages/earl/src/validators/numbers/toBeGreaterThanOrEqual.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { greaterThanOrEqual } from '../../matchers/numbers/greaterThanOrEqual.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a number is greater than or equal to the target value. diff --git a/packages/earl/src/validators/numbers/toBeLessThan.ts b/packages/earl/src/validators/numbers/toBeLessThan.ts index f7ebe124..256963e3 100644 --- a/packages/earl/src/validators/numbers/toBeLessThan.ts +++ b/packages/earl/src/validators/numbers/toBeLessThan.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { lessThan } from '../../matchers/numbers/lessThan.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a number is less the target value. diff --git a/packages/earl/src/validators/numbers/toBeLessThanOrEqual.ts b/packages/earl/src/validators/numbers/toBeLessThanOrEqual.ts index 7ab4765a..cfccf855 100644 --- a/packages/earl/src/validators/numbers/toBeLessThanOrEqual.ts +++ b/packages/earl/src/validators/numbers/toBeLessThanOrEqual.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { lessThanOrEqual } from '../../matchers/numbers/lessThanOrEqual.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a number is less than or equal to the target value. diff --git a/packages/earl/src/validators/objects/toBeEmpty.ts b/packages/earl/src/validators/objects/toBeEmpty.ts index 85a0880a..fddef97e 100644 --- a/packages/earl/src/validators/objects/toBeEmpty.ts +++ b/packages/earl/src/validators/objects/toBeEmpty.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { empty } from '../../matchers/objects/empty.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a string, array, sets or map is empty. diff --git a/packages/earl/src/validators/objects/toEqualUnsorted.ts b/packages/earl/src/validators/objects/toEqualUnsorted.ts index 47363117..f472d99b 100644 --- a/packages/earl/src/validators/objects/toEqualUnsorted.ts +++ b/packages/earl/src/validators/objects/toEqualUnsorted.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { isEqual } from '../../isEqual/index.js' diff --git a/packages/earl/src/validators/objects/toHaveLength.ts b/packages/earl/src/validators/objects/toHaveLength.ts index 3c5fa33f..6bfbdb64 100644 --- a/packages/earl/src/validators/objects/toHaveLength.ts +++ b/packages/earl/src/validators/objects/toHaveLength.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { length } from '../../matchers/objects/length.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a string, array or object with a `length` property has a diff --git a/packages/earl/src/validators/objects/toHaveSubset.ts b/packages/earl/src/validators/objects/toHaveSubset.ts index 585e1deb..1ea0c1ba 100644 --- a/packages/earl/src/validators/objects/toHaveSubset.ts +++ b/packages/earl/src/validators/objects/toHaveSubset.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { type Subset, subset } from '../../matchers/objects/subset.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that an object contains the given key value pairs. diff --git a/packages/earl/src/validators/objects/toInclude.ts b/packages/earl/src/validators/objects/toInclude.ts index 89a6f9ad..9b524c87 100644 --- a/packages/earl/src/validators/objects/toInclude.ts +++ b/packages/earl/src/validators/objects/toInclude.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { includes } from '../../matchers/objects/includes.js' @@ -12,7 +12,6 @@ type MemberOf = T extends (infer U)[] : unknown declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a string includes all of the provided substrings. The @@ -82,9 +81,7 @@ function formatItems(items: unknown[]) { function languageJoin(items: string[]) { if (items.length === 1) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return items[0]! } - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions return `all of: ${items.slice(0, -1).join(', ')} and ${items.at(-1)}` } diff --git a/packages/earl/src/validators/other/errors.ts b/packages/earl/src/validators/other/errors.ts index c92cbdf8..914c1f43 100644 --- a/packages/earl/src/validators/other/errors.ts +++ b/packages/earl/src/validators/other/errors.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { format, formatCompact } from '../../format/index.js' export function captureError(fn: () => unknown) { diff --git a/packages/earl/src/validators/other/toBeRejectedWith.ts b/packages/earl/src/validators/other/toBeRejectedWith.ts index ede11eab..325cfbf9 100644 --- a/packages/earl/src/validators/other/toBeRejectedWith.ts +++ b/packages/earl/src/validators/other/toBeRejectedWith.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { captureAsyncError, processError } from './errors.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that an async function or a promise was rejected. @@ -138,7 +137,6 @@ export async function toBeRejectedWith( async function handleAsyncFunction( control: Control, - // eslint-disable-next-line @typescript-eslint/ban-types fn: Function, errorClassOrMessage?: (new (...args: any[]) => Error) | string | RegExp, message?: string | RegExp, diff --git a/packages/earl/src/validators/other/toEqual.ts b/packages/earl/src/validators/other/toEqual.ts index 531a41b6..850b669b 100644 --- a/packages/earl/src/validators/other/toEqual.ts +++ b/packages/earl/src/validators/other/toEqual.ts @@ -1,4 +1,4 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { isEqual } from '../../isEqual/index.js' diff --git a/packages/earl/src/validators/other/toExactlyEqual.test.ts b/packages/earl/src/validators/other/toExactlyEqual.test.ts index 78fb283c..a7ae2559 100644 --- a/packages/earl/src/validators/other/toExactlyEqual.test.ts +++ b/packages/earl/src/validators/other/toExactlyEqual.test.ts @@ -15,7 +15,7 @@ describe(toExactlyEqual.name, () => { it('passes for NaNs', () => { expect(() => { // @ts-expect-error - desired behavior - earl(NaN).toExactlyEqual(NaN) + earl(Number.NaN).toExactlyEqual(Number.NaN) }).not.to.throw() }) @@ -48,7 +48,7 @@ describe(toExactlyEqual.name, () => { it('fails for NaNs', () => { expect(() => { // @ts-expect-error - desired behavior - earl(NaN).not.toExactlyEqual(NaN) + earl(Number.NaN).not.toExactlyEqual(Number.NaN) }).to.throw( 'The value NaN is the exact same value as NaN, but it was expected not to be.', ) diff --git a/packages/earl/src/validators/other/toExactlyEqual.ts b/packages/earl/src/validators/other/toExactlyEqual.ts index f179932e..c7bd8208 100644 --- a/packages/earl/src/validators/other/toExactlyEqual.ts +++ b/packages/earl/src/validators/other/toExactlyEqual.ts @@ -1,9 +1,8 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a value is referentially equal to the expected value. diff --git a/packages/earl/src/validators/other/toLooseEqual.ts b/packages/earl/src/validators/other/toLooseEqual.ts index c3ef56be..99a0c235 100644 --- a/packages/earl/src/validators/other/toLooseEqual.ts +++ b/packages/earl/src/validators/other/toLooseEqual.ts @@ -1,11 +1,10 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { LOOSE_FORMAT_OPTIONS } from '../../format/FormatOptions.js' import { format, formatCompact } from '../../format/index.js' import { isEqual, LOOSE_EQUALITY_OPTIONS } from '../../isEqual/index.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a value is loosely equal to another value. The equality is diff --git a/packages/earl/src/validators/other/toThrow.ts b/packages/earl/src/validators/other/toThrow.ts index 89a90f02..ef5adc51 100644 --- a/packages/earl/src/validators/other/toThrow.ts +++ b/packages/earl/src/validators/other/toThrow.ts @@ -1,10 +1,9 @@ -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { formatCompact } from '../../format/index.js' import { captureError, processError } from './errors.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a function throws a given message and/or error class when diff --git a/packages/earl/src/validators/snapshots/toMatchSnapshot.test.ts b/packages/earl/src/validators/snapshots/toMatchSnapshot.test.ts index c656166b..96d145b6 100644 --- a/packages/earl/src/validators/snapshots/toMatchSnapshot.test.ts +++ b/packages/earl/src/validators/snapshots/toMatchSnapshot.test.ts @@ -13,7 +13,6 @@ describe(toMatchSnapshot.name, () => { let content: string let envCi: string | undefined let envUpdateSnapshots: string | undefined - // eslint-disable-next-line no-path-concat const SNAPSHOT_FILE = fileURLToPath(import.meta.url) + '.snapshot' const mochaContext = (title: string): MochaTestContext => ({ diff --git a/packages/earl/src/validators/snapshots/toMatchSnapshot.ts b/packages/earl/src/validators/snapshots/toMatchSnapshot.ts index dda47970..87aba5dd 100644 --- a/packages/earl/src/validators/snapshots/toMatchSnapshot.ts +++ b/packages/earl/src/validators/snapshots/toMatchSnapshot.ts @@ -1,6 +1,6 @@ import { writeFileSync } from 'fs' -import { Control } from '../../Control.js' +import type { Control } from '../../Control.js' import { registerValidator } from '../../expect.js' import { format, formatCompact } from '../../format/index.js' import { formatSnapshot } from './format.js' @@ -9,7 +9,6 @@ import { getSnapshotUpdateMode } from './getSnapshotUpdateMode.js' import type { TestContext } from './TestContext.js' declare module '../../expect.js' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Validators { /** * Asserts that a value is equal to a snapshot. The first time the assertion @@ -50,7 +49,6 @@ declare module '../../expect.js' { registerValidator('toMatchSnapshot', toMatchSnapshot) export function toMatchSnapshot(control: Control, context: TestContext) { - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (context === undefined) { throw new TypeError( 'Invalid or no test context provided to .toMatchSnapshot(context).', diff --git a/packages/website/generators/api-reference/generate.test.ts b/packages/website/generators/api-reference/generate.test.ts index ceed4f5a..d3f4ec51 100644 --- a/packages/website/generators/api-reference/generate.test.ts +++ b/packages/website/generators/api-reference/generate.test.ts @@ -1,5 +1,5 @@ import { expect } from 'earl' -import { readFileSync } from 'fs' +import { readFileSync } from 'node:fs' import { generateMarkdownForMethodDocumentation } from './generate' import { parseTsDocComment } from './tsdocs/parse' diff --git a/packages/website/generators/api-reference/generate.ts b/packages/website/generators/api-reference/generate.ts index 59ca10a7..568fbc01 100644 --- a/packages/website/generators/api-reference/generate.ts +++ b/packages/website/generators/api-reference/generate.ts @@ -2,7 +2,7 @@ import { sortBy } from 'lodash' import { extractTsDocCommentsFromString } from './tsdocs/extract' import { parseTsDocComment } from './tsdocs/parse' -import { MethodDocumentation } from './types' +import type { MethodDocumentation } from './types' export function generateSectionReference( sectionName: string, @@ -26,10 +26,11 @@ export function generateSectionReference( abbreviatedSignature: prefixMethodSignature(prefix, c.abbreviatedSignature), })) + const markdown = prefixed + .map(generateMarkdownForMethodDocumentation) + .join('\n') return { - reference: - `## ${sectionName}\n\n` + - prefixed.map(generateMarkdownForMethodDocumentation).join('\n'), + reference: `## ${sectionName}\n\n${markdown}`, } } @@ -78,8 +79,10 @@ ${ // Instead of rendering a few consecutive code snippets, we render a single, // examples separated with a blank line. doc.examples.reduce((a, v) => { - if (a.endsWith('```')) return a.slice(0, -3) + v.replace(/```\w+\n/, '\n') - else return a + '\n' + v + if (a.endsWith('```')) { + return a.slice(0, -3) + v.replace(/```\w+\n/, '\n') + } + return `${a}\n${v}` }, '') }` diff --git a/packages/website/generators/api-reference/generateApiReference.ts b/packages/website/generators/api-reference/generateApiReference.ts index e4e62136..7be5da9b 100644 --- a/packages/website/generators/api-reference/generateApiReference.ts +++ b/packages/website/generators/api-reference/generateApiReference.ts @@ -1,8 +1,8 @@ /* eslint-disable no-console */ import glob from 'fast-glob' -import * as fs from 'fs' -import { resolve } from 'path' -import { promisify } from 'util' +import * as fs from 'node:fs' +import { resolve } from 'node:path' +import { promisify } from 'node:util' const writeFile = promisify(fs.writeFile) const readFile = promisify(fs.readFile) @@ -61,7 +61,7 @@ export async function generateApiReference( if (args.out) { await writeFile(args.out, output, 'utf-8') return '' - } else { - return output } + + return output } diff --git a/packages/website/generators/api-reference/index.ts b/packages/website/generators/api-reference/index.ts index 1a78e2ac..e2ed2c1d 100644 --- a/packages/website/generators/api-reference/index.ts +++ b/packages/website/generators/api-reference/index.ts @@ -1,5 +1,5 @@ -import { writeFileSync } from 'fs' -import path from 'path' +import { writeFileSync } from 'node:fs' +import path from 'node:path' import { generateApiReference } from './generateApiReference' @@ -31,7 +31,6 @@ async function main() { } void main().catch((err) => { - // eslint-disable-next-line no-console console.error(err) process.exit(1) }) diff --git a/packages/website/generators/api-reference/tsdocs/extract.ts b/packages/website/generators/api-reference/tsdocs/extract.ts index 08c1fa7b..252ee561 100644 --- a/packages/website/generators/api-reference/tsdocs/extract.ts +++ b/packages/website/generators/api-reference/tsdocs/extract.ts @@ -1,6 +1,6 @@ import { assert } from 'ts-essentials' -import { MethodComment } from '../types' +import type { MethodComment } from '../types' // @todo: this method could be simplified to only work when semicolon is present at the end of the signature export function extractTsDocCommentsFromString( @@ -18,10 +18,8 @@ export function extractTsDocCommentsFromString( `Couldn't find any block comments in source:\n\`${source}\``, ) while (rawMethodComment != null) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const comment = `/** ${rawMethodComment[1]!.trim()} */` - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - let signature = removeGetterKeyword(rawMethodComment[2]!.trim()) + const comment = `/** ${rawMethodComment[1]?.trim()} */` + let signature = removeGetterKeyword(rawMethodComment[2]?.trim() ?? '') signature = signature.replace(/\n/g, '') signature = signature.replace(/[ ]+/g, ' ') signature = signature.replace(/,[ ]?\)/g, ')') diff --git a/packages/website/generators/api-reference/tsdocs/parse.test.ts b/packages/website/generators/api-reference/tsdocs/parse.test.ts index 1ed17338..12df4266 100644 --- a/packages/website/generators/api-reference/tsdocs/parse.test.ts +++ b/packages/website/generators/api-reference/tsdocs/parse.test.ts @@ -1,8 +1,9 @@ import { expect } from 'earl' -import { MethodComment } from '../types' +import type { MethodComment } from '../types' import { parseTsDocComment } from './parse' +// biome-ignore lint/suspicious/noExportsInTest: This is actually used in another file export const sampleMethodComment: MethodComment = { signature: 'someMethod(x: number, y: number): void', comment: `/** diff --git a/packages/website/generators/api-reference/tsdocs/parse.ts b/packages/website/generators/api-reference/tsdocs/parse.ts index 8cfb99a5..5b6af00e 100644 --- a/packages/website/generators/api-reference/tsdocs/parse.ts +++ b/packages/website/generators/api-reference/tsdocs/parse.ts @@ -1,8 +1,8 @@ -import { DocExcerpt, DocNode, TSDocParser } from '@microsoft/tsdoc' +import { DocExcerpt, type DocNode, TSDocParser } from '@microsoft/tsdoc' import { assert } from 'ts-essentials' import { Node, Project as TSProject } from 'ts-morph' -import { MethodComment, MethodDocumentation, Param } from '../types' +import type { MethodComment, MethodDocumentation, Param } from '../types' export function parseTsDocComment( methodComment: MethodComment, @@ -16,10 +16,7 @@ export function parseTsDocComment( if (parserContext.log.messages.length > 0) { throw new Error( - `Syntax error: \n ${ - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - parserContext.log.messages[0]!.text - }\nwhile parsing: \n${methodComment.comment}\n${methodComment.signature}`, + `Syntax error: \n ${parserContext.log.messages[0]?.text}\nwhile parsing: \n${methodComment.comment}\n${methodComment.signature}`, ) } @@ -102,8 +99,7 @@ function abbreviateSignature(signature: string, project: TSProject): string { assert(Node.isFunctionDeclaration(functionDeclaration)) if (signature.includes('this:')) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - functionDeclaration.getParameter('this')!.remove() + functionDeclaration.getParameter('this')?.remove() } functionDeclaration.removeReturnType() diff --git a/packages/website/generators/test-examples/chunks/preamble.ts b/packages/website/generators/test-examples/chunks/preamble.ts index 723e4572..fad29729 100644 --- a/packages/website/generators/test-examples/chunks/preamble.ts +++ b/packages/website/generators/test-examples/chunks/preamble.ts @@ -1,6 +1,3 @@ -// Common setup shared across all examples -export {} - /* eslint-disable */ import * as z from 'zod' diff --git a/packages/website/generators/test-examples/generate.ts b/packages/website/generators/test-examples/generate.ts index 60bcee01..627b8cb6 100644 --- a/packages/website/generators/test-examples/generate.ts +++ b/packages/website/generators/test-examples/generate.ts @@ -1,7 +1,7 @@ -import { readFileSync } from 'fs' -import { join } from 'path' +import { readFileSync } from 'node:fs' +import { join } from 'node:path' -import { Example } from './types' +import type { Example } from './types' export function generateTestFile(examples: Example[]): string { // cut off first few lines of preamble as they are comments diff --git a/packages/website/generators/test-examples/index.ts b/packages/website/generators/test-examples/index.ts index 59ab8c56..b347d736 100644 --- a/packages/website/generators/test-examples/index.ts +++ b/packages/website/generators/test-examples/index.ts @@ -1,9 +1,9 @@ import FastGlob from 'fast-glob' -import { readFileSync, writeFileSync } from 'fs' -import { basename, join } from 'path' +import { readFileSync, writeFileSync } from 'node:fs' +import { basename, join } from 'node:path' import { generateTestFile } from './generate' -import { Example } from './types' +import type { Example } from './types' export async function main() { console.log('Generating test examples from tsdocs...')