From ed1c4bcf17b6a3e4250bc006f9ec4dfd122c2948 Mon Sep 17 00:00:00 2001 From: Innei Date: Sat, 13 Jul 2024 15:09:48 +0800 Subject: [PATCH] chore: lint Signed-off-by: Innei --- apps/core/src/app.config.testing.ts | 2 +- apps/core/src/app.module.ts | 2 +- .../common/filters/all-exception.filter.ts | 14 ++++---- apps/core/src/common/guards/auth.guard.ts | 7 ++-- apps/core/src/common/guards/spider.guard.ts | 6 ++-- .../common/interceptors/cache.interceptor.ts | 2 +- .../interceptors/idempotence.interceptor.ts | 12 +++---- .../json-transformer.interceptor.ts | 10 +++--- .../interceptors/logging.interceptor.ts | 8 ++--- .../interceptors/response.interceptor.ts | 10 +++--- ...prated.ts => auth.implement.depredated.ts} | 0 apps/core/src/modules/auth/auth.service.ts | 2 +- apps/core/src/modules/auth/auth.util.ts | 9 +++-- .../processors/cache/cache.config.service.ts | 5 ++- .../src/processors/cache/cache.service.ts | 4 +-- .../processors/database/database.service.ts | 2 +- .../gateway/shared/events.gateway.ts | 4 +-- .../processors/gateway/web/events.gateway.ts | 10 +++--- .../processors/helper/helper.http.service.ts | 4 +-- .../src/processors/helper/helper.module.ts | 2 +- biome.json | 33 +++++++++++++++---- package.json | 2 +- test/helper/redis-mock.helper.ts | 2 +- 23 files changed, 87 insertions(+), 65 deletions(-) rename apps/core/src/modules/auth/{auth.implement.deprated.ts => auth.implement.depredated.ts} (100%) diff --git a/apps/core/src/app.config.testing.ts b/apps/core/src/app.config.testing.ts index 17a1188..bc58413 100644 --- a/apps/core/src/app.config.testing.ts +++ b/apps/core/src/app.config.testing.ts @@ -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: [ diff --git a/apps/core/src/app.module.ts b/apps/core/src/app.module.ts index e100888..669e370 100644 --- a/apps/core/src/app.module.ts +++ b/apps/core/src/app.module.ts @@ -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' diff --git a/apps/core/src/common/filters/all-exception.filter.ts b/apps/core/src/common/filters/all-exception.filter.ts index a672ce0..e9525af 100644 --- a/apps/core/src/common/filters/all-exception.filter.ts +++ b/apps/core/src/common/filters/all-exception.filter.ts @@ -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 = { @@ -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 diff --git a/apps/core/src/common/guards/auth.guard.ts b/apps/core/src/common/guards/auth.guard.ts index 2644f97..1447574 100644 --- a/apps/core/src/common/guards/auth.guard.ts +++ b/apps/core/src/common/guards/auth.guard.ts @@ -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' @@ -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 diff --git a/apps/core/src/common/guards/spider.guard.ts b/apps/core/src/common/guards/spider.guard.ts index 80b84d7..3d0b8ea 100644 --- a/apps/core/src/common/guards/spider.guard.ts +++ b/apps/core/src/common/guards/spider.guard.ts @@ -3,13 +3,13 @@ * @description 禁止爬虫的守卫 * @author Innei */ -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' diff --git a/apps/core/src/common/interceptors/cache.interceptor.ts b/apps/core/src/common/interceptors/cache.interceptor.ts index 45056f0..6856d9f 100644 --- a/apps/core/src/common/interceptors/cache.interceptor.ts +++ b/apps/core/src/common/interceptors/cache.interceptor.ts @@ -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' diff --git a/apps/core/src/common/interceptors/idempotence.interceptor.ts b/apps/core/src/common/interceptors/idempotence.interceptor.ts index 8e2e2d9..52654d6 100644 --- a/apps/core/src/common/interceptors/idempotence.interceptor.ts +++ b/apps/core/src/common/interceptors/idempotence.interceptor.ts @@ -1,4 +1,4 @@ -import { FastifyRequest } from 'fastify' +import type { FastifyRequest } from 'fastify' import { catchError, tap } from 'rxjs' import { @@ -6,20 +6,20 @@ import { 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' diff --git a/apps/core/src/common/interceptors/json-transformer.interceptor.ts b/apps/core/src/common/interceptors/json-transformer.interceptor.ts index f348157..9daa8ae 100644 --- a/apps/core/src/common/interceptors/json-transformer.interceptor.ts +++ b/apps/core/src/common/interceptors/json-transformer.interceptor.ts @@ -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 { diff --git a/apps/core/src/common/interceptors/logging.interceptor.ts b/apps/core/src/common/interceptors/logging.interceptor.ts index 01ce344..40a3ba7 100644 --- a/apps/core/src/common/interceptors/logging.interceptor.ts +++ b/apps/core/src/common/interceptors/logging.interceptor.ts @@ -5,17 +5,17 @@ * @author Surmon * @author 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' diff --git a/apps/core/src/common/interceptors/response.interceptor.ts b/apps/core/src/common/interceptors/response.interceptor.ts index d9145d7..123fc7f 100644 --- a/apps/core/src/common/interceptors/response.interceptor.ts +++ b/apps/core/src/common/interceptors/response.interceptor.ts @@ -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 { data: T diff --git a/apps/core/src/modules/auth/auth.implement.deprated.ts b/apps/core/src/modules/auth/auth.implement.depredated.ts similarity index 100% rename from apps/core/src/modules/auth/auth.implement.deprated.ts rename to apps/core/src/modules/auth/auth.implement.depredated.ts diff --git a/apps/core/src/modules/auth/auth.service.ts b/apps/core/src/modules/auth/auth.service.ts index c7a38ed..efeea62 100644 --- a/apps/core/src/modules/auth/auth.service.ts +++ b/apps/core/src/modules/auth/auth.service.ts @@ -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() diff --git a/apps/core/src/modules/auth/auth.util.ts b/apps/core/src/modules/auth/auth.util.ts index e00fb72..c995455 100644 --- a/apps/core/src/modules/auth/auth.util.ts +++ b/apps/core/src/modules/auth/auth.util.ts @@ -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 { @@ -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((resolve) => { getSessionBase(req, { ...authConfig, diff --git a/apps/core/src/processors/cache/cache.config.service.ts b/apps/core/src/processors/cache/cache.config.service.ts index 0889a43..282badd 100755 --- a/apps/core/src/processors/cache/cache.config.service.ts +++ b/apps/core/src/processors/cache/cache.config.service.ts @@ -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() diff --git a/apps/core/src/processors/cache/cache.service.ts b/apps/core/src/processors/cache/cache.service.ts index 3459da3..88f6b1d 100755 --- a/apps/core/src/processors/cache/cache.service.ts +++ b/apps/core/src/processors/cache/cache.service.ts @@ -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' diff --git a/apps/core/src/processors/database/database.service.ts b/apps/core/src/processors/database/database.service.ts index 65e2540..8906f41 100644 --- a/apps/core/src/processors/database/database.service.ts +++ b/apps/core/src/processors/database/database.service.ts @@ -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, { diff --git a/apps/core/src/processors/gateway/shared/events.gateway.ts b/apps/core/src/processors/gateway/shared/events.gateway.ts index 4a1c81b..eba15e8 100644 --- a/apps/core/src/processors/gateway/shared/events.gateway.ts +++ b/apps/core/src/processors/gateway/shared/events.gateway.ts @@ -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 { diff --git a/apps/core/src/processors/gateway/web/events.gateway.ts b/apps/core/src/processors/gateway/web/events.gateway.ts index cace7d3..3c74153 100644 --- a/apps/core/src/processors/gateway/web/events.gateway.ts +++ b/apps/core/src/processors/gateway/web/events.gateway.ts @@ -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' diff --git a/apps/core/src/processors/helper/helper.http.service.ts b/apps/core/src/processors/helper/helper.http.service.ts index f0702de..c868f0a 100644 --- a/apps/core/src/processors/helper/helper.http.service.ts +++ b/apps/core/src/processors/helper/helper.http.service.ts @@ -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' @@ -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 { diff --git a/apps/core/src/processors/helper/helper.module.ts b/apps/core/src/processors/helper/helper.module.ts index 0f17c91..2abc361 100644 --- a/apps/core/src/processors/helper/helper.module.ts +++ b/apps/core/src/processors/helper/helper.module.ts @@ -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' diff --git a/biome.json b/biome.json index fc3b34e..2d6064e 100644 --- a/biome.json +++ b/biome.json @@ -3,6 +3,19 @@ "organizeImports": { "enabled": true }, + "files": { + "include": [ + "*.ts", + "*.tsx", + "*.mts", + "*.cts", + "*.js", + "*.jsx", + "*.mjs", + "*.cjs", + "*.json" + ] + }, "javascript": { "parser": { "unsafeParameterDecoratorsEnabled": true @@ -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": { @@ -139,6 +146,18 @@ } } }, + { + "include": [ + "apps/core/**/*" + ], + "linter": { + "rules": { + "correctness": { + "useHookAtTopLevel": "off" + } + } + } + }, { "include": [ "*.d.ts" diff --git a/package.json b/package.json index 3d39b0e..7d95bba 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/helper/redis-mock.helper.ts b/test/helper/redis-mock.helper.ts index 1d8173e..905e0b8 100644 --- a/test/helper/redis-mock.helper.ts +++ b/test/helper/redis-mock.helper.ts @@ -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'