Skip to content

Commit

Permalink
Move core to biome (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad authored Jun 25, 2024
1 parent f9a34a0 commit d465cf9
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 136 deletions.
2 changes: 1 addition & 1 deletion packages/amqp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.8.2",
"@kibertoad/biome-config": "^1.2.0",
"@kibertoad/biome-config": "^1.2.1",
"@message-queue-toolkit/core": "*",
"@types/amqplib": "^0.10.5",
"@types/node": "^20.12.12",
Expand Down
4 changes: 0 additions & 4 deletions packages/core/.eslintignore

This file was deleted.

80 changes: 0 additions & 80 deletions packages/core/.eslintrc.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/core/.prettierrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/lib/errors/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InternalError } from '@lokalise/node-core'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
export type FreeformRecord = Record<string, any>

export type CommonErrorParams = {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/events/DomainEventEmitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { randomUUID } from 'node:crypto'
import { waitAndRetry } from '@lokalise/node-core'
import type { CommonEventDefinitionPublisherSchemaType } from '@message-queue-toolkit/schemas'
import type { AwilixContainer } from 'awilix'
import { expect } from 'vitest'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import type { z } from 'zod'

import type { Dependencies } from '../../test/testContext'
import { registerDependencies, TestEvents } from '../../test/testContext'
import { TestEvents, registerDependencies } from '../../test/testContext'

import { FakeListener } from './fakes/FakeListener'

Expand Down
6 changes: 3 additions & 3 deletions packages/core/lib/events/DomainEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { resolveHandlerSpy } from '../queues/HandlerSpy'

import type { EventRegistry } from './EventRegistry'
import type {
EventHandler,
AnyEventHandler,
SingleEventHandler,
CommonEventDefinition,
CommonEventDefinitionConsumerSchemaType,
EventTypeNames,
CommonEventDefinitionPublisherSchemaType,
EventHandler,
EventTypeNames,
SingleEventHandler,
} from './eventTypes'

export class DomainEventEmitter<SupportedEvents extends CommonEventDefinition[]> {
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/messages/MetadataFiller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from 'vitest'
import { CommonMetadataFiller } from './MetadataFiller'

const TEST_MESSAGE = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/queues/AbstractPublisherManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export abstract class AbstractPublisherManager<
if (this.isAsync) {
await (publisher as AsyncPublisher<object, unknown>).publish(resolvedMessage, messageOptions)
} else {
(publisher as SyncPublisher<object, unknown>).publish(resolvedMessage, messageOptions)
;(publisher as SyncPublisher<object, unknown>).publish(resolvedMessage, messageOptions)
}

return resolvedMessage
Expand Down
6 changes: 3 additions & 3 deletions packages/core/lib/queues/AbstractQueueService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { types } from 'node:util'

import type { ErrorReporter, ErrorResolver, Either } from '@lokalise/node-core'
import type { Either, ErrorReporter, ErrorResolver } from '@lokalise/node-core'
import { resolveGlobalErrorLogObject } from '@lokalise/node-core'
import type { CommonEventDefinition } from '@message-queue-toolkit/schemas'
import type { ZodSchema, ZodType } from 'zod'
Expand All @@ -21,9 +21,9 @@ import type {
BarrierCallback,
BarrierResult,
MessageHandlerConfig,
PreHandlingOutputs,
Prehandler,
PrehandlerResult,
PreHandlingOutputs,
} from './HandlerContainer'
import type { HandlerSpy, PublicHandlerSpy } from './HandlerSpy'
import { resolveHandlerSpy } from './HandlerSpy'
Expand Down Expand Up @@ -383,7 +383,7 @@ export abstract class AbstractQueueService<
protected abstract processMessage(
message: MessagePayloadSchemas,
messageType: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
preHandlingOutputs: PreHandlingOutputs<PrehandlerOutput, any>,
): Promise<Either<'retryLater', 'success'>>

Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/queues/HandlerContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class MessageHandlerConfigBuilder<
MessagePayloadSchemas,
ExecutionContext,
PrehandlerOutput,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
any
>[]

Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/queues/HandlerSpy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type DeepPartial<T> = T extends Function

export class HandlerSpy<MessagePayloadSchemas extends object> {
public name = 'HandlerSpy'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
private readonly messageBuffer: Fifo<SpyResultInput<any>>
private readonly messageIdField: keyof MessagePayloadSchemas
private readonly messageTypeField: keyof MessagePayloadSchemas
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/queues/MessageSchemaContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class MessageSchemaContainer<MessagePayloadSchemas extends object> {
}

public resolveSchema(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
message: Record<string, any>,
): Either<Error, ZodSchema<MessagePayloadSchemas>> {
const schema = this.messageSchemas[message[this.messageTypeField]]
Expand Down
10 changes: 5 additions & 5 deletions packages/core/lib/types/MessageQueueTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export interface AsyncPublisher<MessagePayloadType extends object, MessageOption
publish(message: MessagePayloadType, options: MessageOptions): Promise<unknown>
}

export { TransactionObservabilityManager }
export type { TransactionObservabilityManager }

export type LogFn = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
<T extends object>(obj: T, msg?: string, ...args: any[]): void
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
(obj: unknown, msg?: string, ...args: any[]): void
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
(msg: string, ...args: any[]): void
}

Expand All @@ -51,6 +51,6 @@ export type Logger = {

export type SchemaMap<SupportedMessageTypes extends string> = Record<
SupportedMessageTypes,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
ZodSchema<any>
>
1 change: 1 addition & 0 deletions packages/core/lib/utils/dateUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'vitest'
import { isRetryDateExceeded } from './dateUtils'

describe('dateUtils', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/core/lib/utils/matchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function isShallowSubset(
}

// eslint-disable-next-line prefer-const
for (let key of keysSubset) {
for (const key of keysSubset) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (maybeSubset[key] !== maybeSuperset![key]) {
return false
Expand All @@ -36,10 +36,11 @@ export function isShallowSubset(
/**
* Returns true if `validatedObject` contains all of the fields included on `matcher`, and their values are deeply equal
*/
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
export function objectMatches(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
matcher: Record<string, any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: This is expected
validatedObject: Record<string, any>,
): boolean {
for (const key in matcher) {
Expand Down
18 changes: 5 additions & 13 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"scripts": {
"build": "del-cli dist && del-cli coverage && tsc",
"build:release": "del-cli dist && del-cli coverage && npm run lint && tsc --project tsconfig.release.json",
"lint": "eslint . --ext .ts && tsc --noEmit",
"lint:fix": "prettier --write . && eslint . --ext .ts --fix",
"lint": "biome check . && tsc --project tsconfig.json --noEmit",
"lint:fix": "biome check --write .",
"test": "vitest",
"test:coverage": "npm test -- --coverage",
"test:ci": "npm run docker:start:dev && npm run test:coverage && npm run docker:stop:dev",
Expand All @@ -34,18 +34,14 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@biomejs/biome": "1.8.2",
"@kibertoad/biome-config": "^1.2.1",
"@types/node": "^20.12.8",
"@types/tmp": "^0.2.6",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"@vitest/coverage-v8": "^1.6.0",
"awilix": "^10.0.2",
"awilix-manager": "^5.2.1",
"del-cli": "^5.1.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-vitest": "0.4.1",
"prettier": "^3.2.5",
"typescript": "^5.5.2",
"vitest": "^1.6.0"
},
Expand All @@ -66,9 +62,5 @@
"rabbitmq",
"rabbit"
],
"files": [
"README.md",
"LICENSE",
"dist/*"
]
"files": ["README.md", "LICENSE", "dist/*"]
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as fs from 'node:fs/promises'

import { describe } from 'vitest'
import { describe, expect, it, vi } from 'vitest'

import {
defaultTemporaryFilePathResolver,
JsonStreamStringifySerializer,
defaultTemporaryFilePathResolver,
} from '../../lib/payload-store/JsonStreamStringifySerializer'
import { streamToString } from '../utils/streamUtils'

Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/queues/HandlerSpy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'vitest'
import { describe, expect, it } from 'vitest'

import { HandlerSpy, isHandlerSpy } from '../../lib/queues/HandlerSpy'

Expand Down Expand Up @@ -350,13 +350,13 @@ describe('HandlerSpy', () => {
})

describe('isHandlerSpy', () => {
it('HandlerSpy returns true', async () => {
it('HandlerSpy returns true', () => {
const spy = new HandlerSpy<Message>()

expect(isHandlerSpy(spy)).toBe(true)
})

it('Not a HandlerSpy returns false', async () => {
it('Not a HandlerSpy returns false', () => {
expect(isHandlerSpy({})).toBe(false)
expect(isHandlerSpy('abc')).toBe(false)
expect(isHandlerSpy(null)).toBe(false)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/testContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ErrorReporter } from '@lokalise/node-core'
import type { Resolver } from 'awilix'
import { asFunction, createContainer, Lifetime } from 'awilix'
import { Lifetime, asFunction, createContainer } from 'awilix'
import { AwilixManager } from 'awilix-manager'
import type { Logger } from 'pino'
import pino from 'pino'
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function registerDependencies(dependencyOverrides: DependencyOverri
return diContainer
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
type DiConfig = Record<keyof Dependencies, Resolver<any>>

export interface Dependencies {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/utils/matchUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe } from 'vitest'
import { describe, expect, it } from 'vitest'

import { isShallowSubset } from '../../lib/utils/matchUtils'

Expand Down

0 comments on commit d465cf9

Please sign in to comment.