Skip to content

Commit

Permalink
Start migration to biome linter
Browse files Browse the repository at this point in the history
  • Loading branch information
sz-piotr committed Apr 21, 2024
1 parent 9192722 commit 918cdb1
Show file tree
Hide file tree
Showing 76 changed files with 195 additions and 241 deletions.
3 changes: 1 addition & 2 deletions examples/example-plugin/src/toBeEven.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeEven(this: Validators<number>): void
}
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/test-esbuild/stack-traces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function captureErrorAsync(fn: () => Promise<void>) {

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,
}))
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/test-ts-node/stack-traces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function captureErrorAsync(fn: () => Promise<void>) {

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,
}))
Expand Down
5 changes: 2 additions & 3 deletions packages/earl/src/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {}
export type Validators<T> = {}

// to be overridden by plugins
export interface Matchers {}
export type Matchers = {}

export class Matcher {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion packages/earl/src/format/FormatOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
19 changes: 9 additions & 10 deletions packages/earl/src/format/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('format', () => {
compareErrorStack: false,
indentSize: 2,
inline: false,
maxLineLength: Infinity,
maxLineLength: Number.POSITIVE_INFINITY,
skipMatcherReplacement: false,
requireStrictEquality: false,
}
Expand All @@ -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 }],
Expand Down Expand Up @@ -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]()'],
Expand All @@ -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)'],
Expand Down Expand Up @@ -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}',
],
Expand Down
8 changes: 4 additions & 4 deletions packages/earl/src/format/formatCompact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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]'],
Expand Down
4 changes: 2 additions & 2 deletions packages/earl/src/format/formatNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion packages/earl/src/format/formatUnknown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)})`,
Expand Down
2 changes: 0 additions & 2 deletions packages/earl/src/format/getComparedTypeName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion packages/earl/src/isEqual/isEqual.perf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
27 changes: 11 additions & 16 deletions packages/earl/src/isEqual/isEqual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('isEqual', () => {
minusZero: true,
indentSize: 2,
inline: true,
maxLineLength: Infinity,
maxLineLength: Number.POSITIVE_INFINITY,
skipMatcherReplacement: true,
requireStrictEquality: false,
}
Expand Down Expand Up @@ -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],
],
},
{
Expand Down Expand Up @@ -119,9 +119,9 @@ describe('isEqual', () => {
function* named() {},
async function named() {},
async function* named() {},
function () {},
() => {},
function* () {},
async function () {},
async () => {},
async function* () {},
]
const testCases: TestCase[] = []
Expand Down Expand Up @@ -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],
[
Expand Down Expand Up @@ -651,7 +646,7 @@ describe('isEqual', () => {
...equalityOptions,
indentSize: 2,
inline: false,
maxLineLength: Infinity,
maxLineLength: Number.POSITIVE_INFINITY,
skipMatcherReplacement: false,
requireStrictEquality: false,
}
Expand Down
4 changes: 2 additions & 2 deletions packages/earl/src/isEqual/isEqualNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/earl/src/isEqual/isEqualObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions packages/earl/src/matchers/basic/a.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/earl/src/matchers/basic/a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/earl/src/matchers/numbers/between.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
Expand Down
2 changes: 1 addition & 1 deletion packages/earl/src/matchers/numbers/closeTo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe(closeTo.name, () => {
5,
123,
-4,
NaN,
Number.NaN,
...TEST_VALUES.filter((x) => typeof x !== 'number'),
],
)
Expand Down
14 changes: 11 additions & 3 deletions packages/earl/src/matchers/numbers/greaterThan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,8 +27,8 @@ describe(greaterThan.name, () => {
9.998,
5,
-4,
NaN,
-Infinity,
Number.NaN,
Number.NEGATIVE_INFINITY,
BigInt(10),
BigInt(0),
BigInt(-100),
Expand Down
6 changes: 3 additions & 3 deletions packages/earl/src/matchers/numbers/greaterThanOrEqual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe(greaterThanOrEqual.name, () => {
10.5,
100,
12356.789,
Infinity,
Number.POSITIVE_INFINITY,
BigInt(10),
BigInt(11),
BigInt(100),
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions packages/earl/src/matchers/numbers/integer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
)
Expand Down
6 changes: 3 additions & 3 deletions packages/earl/src/matchers/numbers/lessThan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe(lessThan.name, () => {
-1,
-100,
-12356.789,
-Infinity,
Number.NEGATIVE_INFINITY,
BigInt(9),
BigInt(0),
BigInt(-100),
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions packages/earl/src/matchers/numbers/lessThanOrEqual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe(lessThanOrEqual.name, () => {
-1,
-100,
-12356.789,
-Infinity,
Number.NEGATIVE_INFINITY,
BigInt(10),
BigInt(9),
BigInt(0),
Expand All @@ -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',
Expand Down
Loading

0 comments on commit 918cdb1

Please sign in to comment.