fix: lint

This commit is contained in:
Innei
2024-04-29 16:19:39 +08:00
parent c6980f98c2
commit 358a5e6135
21 changed files with 41 additions and 48 deletions

View File

@@ -26,7 +26,7 @@
"start:debug": "cross-env NODE_ENV=development nest start --debug --watch",
"start:cluster": "cross-env NODE_ENV=development nest start --watch -- --cluster --cluster_workers 2",
"start:prod": "cross-env NODE_ENV=production node dist/src/main",
"lint": "eslint \"{src,apps,libs,test,packages}/**/*.ts\" --fix",
"lint": "eslint src/**/*.ts --fix",
"prod": "cross-env NODE_ENV=production pm2-runtime start ecosystem.config.js",
"prod:pm2": "cross-env NODE_ENV=production pm2 restart ecosystem.config.js",
"prod:stop": "pm2 stop ecosystem.config.js",

View File

@@ -1,10 +1,3 @@
import type { ModuleMetadata } from '@nestjs/common'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import type {
BeAnObject,
ReturnModelType,
} from '@typegoose/typegoose/lib/types'
import { APP_INTERCEPTOR } from '@nestjs/core'
import { HttpCacheInterceptor } from '~/common/interceptors/cache.interceptor'
@@ -16,6 +9,12 @@ import { getModelToken } from '~/transformers/model.transformer'
import { dbHelper } from './db-mock.helper'
import { redisHelper } from './redis-mock.helper'
import { setupE2EApp } from './setup-e2e'
import type {
BeAnObject,
ReturnModelType,
} from '@typegoose/typegoose/lib/types'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import type { ModuleMetadata } from '@nestjs/common'
type ClassType = new (...args: any[]) => any
@@ -64,9 +63,8 @@ export const createE2EApp = (module: ModuleMetadata & E2EAppMetaData) => {
provide: APP_INTERCEPTOR,
useClass: ResponseInterceptor, // 1
},
{ provide: token, useValue: CacheService },
)
nestModule.providers.push({ provide: token, useValue: CacheService })
const modelMap = new Map() as ModelMap
if (models) {
models.forEach((model) => {

View File

@@ -1,6 +1,5 @@
import type { Provider } from '@nestjs/common'
import { Global, Module } from '@nestjs/common'
import type { Provider } from '@nestjs/common'
export const createMockGlobalModule = (providers: Provider[]) => {
@Global()

View File

@@ -1,5 +1,6 @@
import { MongoMemoryServer } from 'mongodb-memory-server'
import mongoose from 'mongoose'
import { getModelForClass } from '@typegoose/typegoose'
import type {
AnyParamConstructor,
BeAnObject,
@@ -7,8 +8,6 @@ import type {
ReturnModelType,
} from '@typegoose/typegoose/lib/types'
import { getModelForClass } from '@typegoose/typegoose'
let mongod: MongoMemoryServer
/**

View File

@@ -1,8 +1,7 @@
import IORedis from 'ioredis'
import RedisMemoryServer from 'redis-memory-server'
import type { Redis } from 'ioredis'
import { CacheService } from '~/processors/redis/cache.service'
import type { Redis } from 'ioredis'
export class MockCacheService {
private client: Redis

View File

@@ -1,10 +1,9 @@
import type { ModuleMetadata } from '@nestjs/common'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import { ValidationPipe } from '@nestjs/common'
import { Test, TestingModule } from '@nestjs/testing'
import { fastifyApp } from '~/common/adapters/fastify.adapter'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import type { ModuleMetadata } from '@nestjs/common'
export const setupE2EApp = async (module: TestingModule | ModuleMetadata) => {
let nextModule: TestingModule

View File

@@ -1,4 +1,4 @@
import { applyDecorators, UseGuards } from '@nestjs/common'
import { UseGuards, applyDecorators } from '@nestjs/common'
import { AuthTestingGuard } from '../guard/auth.guard'

View File

@@ -1,10 +1,8 @@
import { UnauthorizedException } from '@nestjs/common'
import { authJWTToken } from '../constants/token'
import type { ExecutionContext } from '@nestjs/common'
import type { UserModel } from '~/modules/user/user.model'
import { UnauthorizedException } from '@nestjs/common'
import { authJWTToken } from '../constants/token'
export const mockUser1: UserModel = {
id: '1',
name: 'John Doe',

View File

@@ -1,17 +1,17 @@
import { map } from 'rxjs'
import { Inject, Injectable } from '@nestjs/common'
import { HTTP_RES_UPDATE_DOC_COUNT_TYPE } from '~/constants/meta.constant'
import { REFLECTOR } from '~/constants/system.constant'
import type { Reflector } from '@nestjs/core'
import type { CountingService } from '~/processors/helper/helper.counting.service'
import type {
CallHandler,
ExecutionContext,
NestInterceptor,
} from '@nestjs/common'
import { Inject, Injectable } from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import { HTTP_RES_UPDATE_DOC_COUNT_TYPE } from '~/constants/meta.constant'
import { REFLECTOR } from '~/constants/system.constant'
import { CountingService } from '~/processors/helper/helper.counting.service'
@Injectable()
export class MockingCountingInterceptor<T> implements NestInterceptor<T> {
constructor(

View File

@@ -1,5 +1,3 @@
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import { Test } from '@nestjs/testing'
import { AppController } from '~/app.controller'
@@ -7,6 +5,7 @@ import { fastifyApp } from '~/common/adapters/fastify.adapter'
import { OptionModel } from '~/modules/configs/configs.model'
import { CacheService } from '~/processors/redis/cache.service'
import { getModelToken } from '~/transformers/model.transformer'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
describe('AppController (e2e)', () => {
let app: NestFastifyApplication

View File

@@ -1,7 +1,7 @@
import { vi } from 'vitest'
import { configProvider } from '@/mock/modules/config.mock'
import { Test } from '@nestjs/testing'
import { configProvider } from '@/mock/modules/config.mock'
import { AuthService } from '~/modules/auth/auth.service'
import { UserModel } from '~/modules/user/user.model'

View File

@@ -1,6 +1,5 @@
import { redisHelper } from 'test/helper/redis-mock.helper'
import { vi } from 'vitest'
import type { MockCacheService } from 'test/helper/redis-mock.helper'
import { UnprocessableEntityException } from '@nestjs/common'
import { Test } from '@nestjs/testing'
@@ -17,6 +16,7 @@ import { CacheService } from '~/processors/redis/cache.service'
import { SubPubBridgeService } from '~/processors/redis/subpub.service'
import { getModelToken } from '~/transformers/model.transformer'
import { getRedisKey } from '~/utils/redis.util'
import type { MockCacheService } from 'test/helper/redis-mock.helper'
describe('Test ConfigsService', () => {
let service: ConfigsService

View File

@@ -1,8 +1,8 @@
import 'reflect-metadata'
import {
decryptObject,
Encrypt,
decryptObject,
encryptObject,
encryptProperty,
isEncryptProperty,

View File

@@ -3,7 +3,6 @@ import { gatewayProviders } from 'test/mock/modules/gateway.mock'
import { userProvider } from 'test/mock/modules/user.mock'
import { emailProvider } from 'test/mock/processors/email.mock'
import { eventEmitterProvider } from 'test/mock/processors/event.mock'
import type { ReturnModelType } from '@typegoose/typegoose'
import { ExtendedValidationPipe } from '~/common/pipes/validation.pipe'
import { VALIDATION_PIPE_INJECTION } from '~/constants/system.constant'
@@ -16,6 +15,7 @@ import {
import { LinkModel, LinkState } from '~/modules/link/link.model'
import { LinkService } from '~/modules/link/link.service'
import { HttpService } from '~/processors/helper/helper.http.service'
import type { ReturnModelType } from '@typegoose/typegoose'
describe('Test LinkController(E2E)', () => {
const proxy = createE2EApp({

View File

@@ -78,7 +78,7 @@ describe('test serverless function service', () => {
Object.assign<SnippetModel, Partial<SnippetModel>>(model, {
type: SnippetType.Function,
raw: async function handler(context, require) {
return (await require('path')).join('1', '1')
return (await require('node:path')).join('1', '1')
}.toString(),
})
const data = await service.injectContextIntoServerlessFunctionAndCall(
@@ -108,7 +108,7 @@ describe('test serverless function service', () => {
Object.assign<SnippetModel, Partial<SnippetModel>>(model, {
type: SnippetType.Function,
raw: async function handler(context, require) {
return await require('os')
return await require('node:os')
}.toString(),
})

View File

@@ -1,7 +1,5 @@
import { createE2EApp } from 'test/helper/create-e2e-app'
import { authPassHeader } from 'test/mock/guard/auth.guard'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import type { ReturnModelType } from '@typegoose/typegoose'
import { ServerlessService } from '~/modules/serverless/serverless.service'
import { SnippetController } from '~/modules/snippet/snippet.controller'
@@ -9,6 +7,8 @@ import { SnippetModel, SnippetType } from '~/modules/snippet/snippet.model'
import { SnippetService } from '~/modules/snippet/snippet.service'
import { DatabaseService } from '~/processors/database/database.service'
import { EventManagerService } from '~/processors/helper/helper.event.service'
import type { ReturnModelType } from '@typegoose/typegoose'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
describe('test /snippets', () => {
let app: NestFastifyApplication

View File

@@ -1,10 +1,9 @@
import { dbHelper } from 'test/helper/db-mock.helper'
import { redisHelper } from 'test/helper/redis-mock.helper'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import { Test } from '@nestjs/testing'
import { createMockGlobalModule } from '@/helper/create-mock-global-module'
import { configProvider } from '@/mock/modules/config.mock'
import { Test } from '@nestjs/testing'
import { fastifyApp } from '~/common/adapters/fastify.adapter'
import { AuthService } from '~/modules/auth/auth.service'
@@ -13,6 +12,7 @@ import { UserController } from '~/modules/user/user.controller'
import { UserModel } from '~/modules/user/user.model'
import { UserService } from '~/modules/user/user.service'
import { getModelToken } from '~/transformers/model.transformer'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
describe('AppController (e2e)', () => {
let app: NestFastifyApplication

View File

@@ -1,6 +1,6 @@
import { Test } from '@nestjs/testing'
import { createMockGlobalModule } from '@/helper/create-mock-global-module'
import { configProvider } from '@/mock/modules/config.mock'
import { Test } from '@nestjs/testing'
import { AuthService } from '~/modules/auth/auth.service'
import { AuthnService } from '~/modules/authn/authn.service'

View File

@@ -1,13 +1,13 @@
import { IsDefined, IsNumber } from 'class-validator'
import { eventEmitterProvider } from 'test/mock/processors/event.mock'
import type { ReturnModelType } from '@typegoose/typegoose'
import { modelOptions, prop } from '@typegoose/typegoose'
import { createE2EApp } from '@/helper/create-e2e-app'
import { authPassHeader } from '@/mock/guard/auth.guard'
import { modelOptions, prop } from '@typegoose/typegoose'
import { BaseModel } from '~/shared/model/base.model'
import { BaseCrudFactory } from '~/transformers/crud-factor.transformer'
import type { ReturnModelType } from '@typegoose/typegoose'
@modelOptions({
options: {

View File

@@ -20,6 +20,8 @@ export default sxzz(
'packages/*/esm',
'packages/*/types',
'test/**/*.db.ts',
'apps/core/test/**/*',
],
languageOptions: {
parserOptions: {

View File

@@ -27,7 +27,7 @@
"dev": "pnpm run build:external && pnpm -C \"apps/core\" run start",
"bundle": "pnpm run build:external && pnpm -C \"apps/core\" run bundle",
"test": "pnpm run build:external && pnpm -C \"apps/core\" run test",
"lint": "eslint --cache --ext .ts,.tsx --ignore-path .gitignore . --fix",
"lint": "pnpm -C \"apps/core\" run lint",
"publish:core": "cd apps/core && npm run publish"
},
"dependencies": {