Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Jul 13, 2024
1 parent ec9daf0 commit ed1c4bc
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 65 deletions.
2 changes: 1 addition & 1 deletion apps/core/src/app.config.testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isDev } from './shared/utils/environment.util'
import { mergeArgv } from './utils/env.util'
import type { AxiosRequestConfig } from 'axios'

console.log(argv)
console.info(argv)
export const PORT = argv.port || 3333
export const CROSS_DOMAIN = {
allowedOrigins: [
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type MiddlewareConsumer,
Module,
type NestModule,
Type,
type Type,
} from '@nestjs/common'
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core'
import { ThrottlerGuard } from '@nestjs/throttler'
Expand Down
14 changes: 7 additions & 7 deletions apps/core/src/common/filters/all-exception.filter.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import fs, { WriteStream } from 'node:fs'
import fs, { type WriteStream } from 'node:fs'
import { resolve } from 'node:path'
import chalk from 'chalk'
import { FastifyReply, FastifyRequest } from 'fastify'
import type { FastifyReply, FastifyRequest } from 'fastify'

import { HTTP_REQUEST_TIME } from '@core/constants/meta.constant'
import { LOG_DIR } from '@core/constants/path.constant'
import { REFLECTOR } from '@core/constants/system.constant'
import { isDev, isTest } from '@core/global/env.global'
import {
ArgumentsHost,
type ArgumentsHost,
Catch,
ExceptionFilter,
type ExceptionFilter,
HttpException,
HttpStatus,
Inject,
Logger,
} from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import type { Reflector } from '@nestjs/core'

import { getIp } from '../../shared/utils/ip.util'
import { BizException } from '../exceptions/biz.exception'
import type { BizException } from '../exceptions/biz.exception'
import { LoggingInterceptor } from '../interceptors/logging.interceptor'

type myError = {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
const logMessage = `IP: ${ip} Error Info: (${status}${
bizCode ? ` ,B${bizCode}` : ''
}) ${message} Path: ${decodeURI(url)}`
if (isTest) console.log(logMessage)
if (isTest) console.info(logMessage)
this.logger.warn(logMessage)
}
// @ts-ignore
Expand Down
7 changes: 4 additions & 3 deletions apps/core/src/common/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { isTest } from '@core/global/env.global'
import { getSessionUser } from '@core/modules/auth/auth.util'
import { getNestExecutionContextRequest } from '@core/transformers/get-req.transformer'
import {
CanActivate,
ExecutionContext,
type CanActivate,
type ExecutionContext,
Injectable,
UnauthorizedException,
} from '@nestjs/common'
Expand All @@ -17,7 +17,8 @@ export class AuthGuard implements CanActivate {
}

const req = this.getRequest(context)
const session = await getSessionUser(req)

const session = await getSessionUser(req.raw)

req.raw['session'] = session
req.raw['isAuthenticated'] = !!session
Expand Down
6 changes: 3 additions & 3 deletions apps/core/src/common/guards/spider.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @description 禁止爬虫的守卫
* @author Innei <https://innei.in>
*/
import { Observable } from 'rxjs'
import type { Observable } from 'rxjs'

import { isDev } from '@core/global/env.global'
import { getNestExecutionContextRequest } from '@core/transformers/get-req.transformer'
import {
CanActivate,
ExecutionContext,
type CanActivate,
type ExecutionContext,
ForbiddenException,
Injectable,
} from '@nestjs/common'
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/common/interceptors/cache.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { of, tap } from 'rxjs'

import { Inject, Injectable, Logger, RequestMethod } from '@nestjs/common'
import { HttpAdapterHost, Reflector } from '@nestjs/core'
import type { HttpAdapterHost, Reflector } from '@nestjs/core'

import { REDIS } from '@core/app.config.testing'
import { hashString } from '@core/shared/utils/tool.utils'
Expand Down
12 changes: 6 additions & 6 deletions apps/core/src/common/interceptors/idempotence.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { FastifyRequest } from 'fastify'
import type { FastifyRequest } from 'fastify'
import { catchError, tap } from 'rxjs'

import {
HTTP_IDEMPOTENCE_KEY,
HTTP_IDEMPOTENCE_OPTIONS,
} from '@core/constants/meta.constant'
import { REFLECTOR } from '@core/constants/system.constant'
import { CacheService } from '@core/processors/cache/cache.service'
import type { CacheService } from '@core/processors/cache/cache.service'
import { getIp } from '@core/shared/utils/ip.util'
import { getRedisKey } from '@core/shared/utils/redis.util'
import { hashString } from '@core/shared/utils/tool.utils'
import {
CallHandler,
type CallHandler,
ConflictException,
ExecutionContext,
type ExecutionContext,
Inject,
Injectable,
NestInterceptor,
type NestInterceptor,
SetMetadata,
} from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import type { Reflector } from '@nestjs/core'

const IdempotenceHeaderKey = 'x-idempotence'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* @author Innei
*/
import { isObjectLike } from 'lodash'
import { Observable, map } from 'rxjs'
import { type Observable, map } from 'rxjs'
import snakecaseKeys from 'snakecase-keys'

import { RESPONSE_PASSTHROUGH_METADATA } from '@core/constants/system.constant'
import {
CallHandler,
ExecutionContext,
type CallHandler,
type ExecutionContext,
Injectable,
NestInterceptor,
type NestInterceptor,
} from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import type { Reflector } from '@nestjs/core'

@Injectable()
export class JSONTransformerInterceptor implements NestInterceptor {
Expand Down
8 changes: 4 additions & 4 deletions apps/core/src/common/interceptors/logging.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
* @author Surmon <https://github.com/surmon-china>
* @author Innei <https://github.com/Innei>
*/
import { Observable } from 'rxjs'
import type { Observable } from 'rxjs'
import { tap } from 'rxjs/operators'

import { HTTP_REQUEST_TIME } from '@core/constants/meta.constant'
import { isDev } from '@core/shared/utils/environment.util'
import {
CallHandler,
ExecutionContext,
type CallHandler,
type ExecutionContext,
Injectable,
Logger,
NestInterceptor,
type NestInterceptor,
SetMetadata,
} from '@nestjs/common'

Expand Down
10 changes: 5 additions & 5 deletions apps/core/src/common/interceptors/response.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* @author Innei
*/
import { isArrayLike, omit } from 'lodash'
import { Observable } from 'rxjs'
import type { Observable } from 'rxjs'
import { map } from 'rxjs/operators'

import * as SYSTEM from '@core/constants/system.constant'
import {
CallHandler,
ExecutionContext,
type CallHandler,
type ExecutionContext,
Injectable,
NestInterceptor,
type NestInterceptor,
} from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import type { Reflector } from '@nestjs/core'

export interface Response<T> {
data: T
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DatabaseService } from '@core/processors/database/database.service'
import type { DatabaseService } from '@core/processors/database/database.service'
import { Injectable } from '@nestjs/common'

@Injectable()
Expand Down
9 changes: 4 additions & 5 deletions apps/core/src/modules/auth/auth.util.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable no-async-promise-executor */
import { authConfig } from './auth.config'
import { getSessionBase } from './auth.implement.deprated'
import { getSessionBase } from './auth.implement'
import type { users } from '@meta-muse/drizzle/schema'
import type { Session } from '@meta-muse/complied'
import type { FastifyRequest } from 'fastify'

export const getSession = (req: FastifyRequest) =>
import type { IncomingMessage } from 'node:http'
export const getSession = (req: IncomingMessage) =>
getSessionBase(req, authConfig)

export interface SessionUser {
Expand All @@ -14,7 +13,7 @@ export interface SessionUser {
expires: string
user: typeof users.$inferSelect
}
export const getSessionUser = (req: FastifyRequest) => {
export const getSessionUser = (req: IncomingMessage) => {
return new Promise<SessionUser | null>((resolve) => {
getSessionBase(req, {
...authConfig,
Expand Down
5 changes: 4 additions & 1 deletion apps/core/src/processors/cache/cache.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import redisStore from 'cache-manager-ioredis'

import { REDIS } from '@core/app.config'
import { CacheModuleOptions, CacheOptionsFactory } from '@nestjs/cache-manager'
import type {
CacheModuleOptions,
CacheOptionsFactory,
} from '@nestjs/cache-manager'
import { Injectable } from '@nestjs/common'

@Injectable()
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/processors/cache/cache.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Cache } from 'cache-manager'
import { Redis } from 'ioredis'
import type { Cache } from 'cache-manager'
import type { Redis } from 'ioredis'

import { RedisIoAdapterKey } from '@core/common/adapter/io.adapter'
import { CACHE_MANAGER } from '@nestjs/cache-manager'
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/processors/database/database.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DATABASE } from '@core/app.config'
import { createDrizzle, migrateDb } from '@meta-muse/drizzle'
import { Injectable, OnModuleInit } from '@nestjs/common'
import { Injectable, type OnModuleInit } from '@nestjs/common'
// const drizzleLogger = new Logger('')

export const db = createDrizzle(DATABASE.url, {
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/processors/gateway/shared/events.gateway.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BusinessEvents } from '@core/constants/business-event.constant'
import type { BusinessEvents } from '@core/constants/business-event.constant'
import { Injectable } from '@nestjs/common'

import { WebEventsGateway } from '../web/events.gateway'
import type { WebEventsGateway } from '../web/events.gateway'

@Injectable()
export class SharedGateway {
Expand Down
10 changes: 5 additions & 5 deletions apps/core/src/processors/gateway/web/events.gateway.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import SocketIO from 'socket.io'
import type SocketIO from 'socket.io'

import { BusinessEvents } from '@core/constants/business-event.constant'
import { RedisKeys } from '@core/constants/cache.constant'
import { CacheService } from '@core/processors/cache/cache.service'
import type { CacheService } from '@core/processors/cache/cache.service'
import { getRedisKey } from '@core/shared/utils/redis.util'
import { scheduleManager } from '@core/shared/utils/schedule.util'
import { getShortDate } from '@core/shared/utils/time.util'
import {
GatewayMetadata,
OnGatewayConnection,
OnGatewayDisconnect,
type GatewayMetadata,
type OnGatewayConnection,
type OnGatewayDisconnect,
WebSocketGateway,
WebSocketServer,
} from '@nestjs/websockets'
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/processors/helper/helper.http.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { performance } from 'node:perf_hooks'
import { inspect } from 'node:util'
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'
import axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios'
import chalk from 'chalk'

import { version } from '@core/../package.json'
Expand All @@ -9,7 +9,7 @@ import { RedisKeys } from '@core/constants/cache.constant'
import { getRedisKey } from '@core/shared/utils/redis.util'
import { Injectable, Logger } from '@nestjs/common'

import { CacheService } from '../cache/cache.service'
import type { CacheService } from '../cache/cache.service'

declare module 'axios' {
interface AxiosRequestConfig {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/processors/helper/helper.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isDev } from '@core/global/env.global'
import { Global, Module, Provider } from '@nestjs/common'
import { Global, Module, type Provider } from '@nestjs/common'
import { EventEmitterModule } from '@nestjs/event-emitter/dist/event-emitter.module'
import { ThrottlerModule } from '@nestjs/throttler'

Expand Down
33 changes: 26 additions & 7 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
"organizeImports": {
"enabled": true
},
"files": {
"include": [
"*.ts",
"*.tsx",
"*.mts",
"*.cts",
"*.js",
"*.jsx",
"*.mjs",
"*.cjs",
"*.json"
]
},
"javascript": {
"parser": {
"unsafeParameterDecoratorsEnabled": true
Expand Down Expand Up @@ -123,13 +136,7 @@
"overrides": [
{
"include": [
"*.config.[tj]s",
"pages/**/*.[tj]sx",
"src/pages/**/*.[tj]sx",
"src/views/**/*.[tj]sx",
"views/**/*.[tj]sx",
"src/store/**/*.[tj]s",
"store/**/*.[tj]s"
"*.config.[tj]s"
],
"linter": {
"rules": {
Expand All @@ -139,6 +146,18 @@
}
}
},
{
"include": [
"apps/core/**/*"
],
"linter": {
"rules": {
"correctness": {
"useHookAtTopLevel": "off"
}
}
}
},
{
"include": [
"*.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dev": "pnpm -C \"apps/core\" run start",
"dev:web": "pnpm -C \"apps/web\" run dev",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "biome lint --apply src/**/*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json} --no-errors-on-unmatched",
"lint": "biome lint --write --no-errors-on-unmatched",
"test": "pnpm -C \"test\" run test",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
Expand Down
2 changes: 1 addition & 1 deletion test/helper/redis-mock.helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import IORedis, { Redis } from 'ioredis'
import IORedis, { type Redis } from 'ioredis'

import { CacheService } from '@core/processors/cache/cache.service'
import { Global, Module } from '@nestjs/common'
Expand Down

0 comments on commit ed1c4bc

Please sign in to comment.