Skip to content

Commit

Permalink
chore(api): lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kuizuo committed Nov 23, 2023
1 parent 4b56306 commit 6c8fb30
Show file tree
Hide file tree
Showing 107 changed files with 1,627 additions and 1,138 deletions.
11 changes: 0 additions & 11 deletions apps/api/.editorconfig

This file was deleted.

68 changes: 0 additions & 68 deletions apps/api/.eslintrc.js

This file was deleted.

11 changes: 0 additions & 11 deletions apps/api/.prettierrc

This file was deleted.

41 changes: 41 additions & 0 deletions apps/api/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml"
]
}
17 changes: 17 additions & 0 deletions apps/api/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const antfu = require('@antfu/eslint-config').default

module.exports = antfu({
stylistic: true,
stylistic: {
indent: 2,
quotes: 'single',
},
}, {
rules: {
'no-console': 'off',

'ts/consistent-type-imports': 'off',
'node/prefer-global/process': 'off',
'node/prefer-global/buffer': 'off',
},
})
28 changes: 15 additions & 13 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"private": true,
"packageManager": "pnpm@8.10.2",
"license": "MIT",
"engines": {
"node": ">=18",
"pnpm": ">=8.1.0"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
Expand Down Expand Up @@ -64,13 +68,15 @@
"dotenv": "16.3.1",
"fastify": "^4.24.3",
"fastify-multer": "^2.0.3",
"handlebars": "^4.7.8",
"helmet": "^7.1.0",
"ioredis": "^5.3.2",
"lodash": "^4.17.21",
"mysql": "^2.18.1",
"nanoid": "^3.3.6",
"nodemailer": "^6.9.7",
"passport": "^0.6.0",
"passport-google-oauth20": "^2.0.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"reflect-metadata": "^0.1.13",
Expand All @@ -86,6 +92,7 @@
"winston-daily-rotate-file": "^4.7.1"
},
"devDependencies": {
"@antfu/eslint-config": "^2.1.0",
"@compodoc/compodoc": "^1.1.22",
"@nestjs/cli": "^10.2.1",
"@nestjs/schematics": "^10.0.3",
Expand All @@ -96,18 +103,11 @@
"@types/node": "^20.9.0",
"@types/supertest": "^2.0.16",
"@types/ua-parser-js": "^0.7.39",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"cross-env": "7.0.3",
"cross-env": "^7.0.3",
"eslint": "^8.53.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-unused-imports": "^3.0.0",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"lint-staged": "^15.1.0",
"simple-git-hooks": "^2.9.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
Expand Down Expand Up @@ -136,8 +136,10 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"engines": {
"node": ">=18",
"pnpm": ">=8.1.0"
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
5 changes: 2 additions & 3 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { APP_FILTER, APP_GUARD } from '@nestjs/core'

import * as config from '@/config'
import { SharedModule } from '@/shared/shared.module'

import { AllExceptionsFilter } from './common/filters/any-exception.filter'

import { AuthModule } from './modules/auth/auth.module'
Expand All @@ -18,6 +15,8 @@ import { TasksModule } from './modules/tasks/tasks.module'
import { TodoModule } from './modules/todo/todo.module'
import { ToolsModule } from './modules/tools/tools.module'
import { DatabaseModule } from './shared/database/database.module'
import { SharedModule } from '@/shared/shared.module'
import * as config from '@/config'

@Module({
imports: [
Expand Down
10 changes: 4 additions & 6 deletions apps/api/src/common/adapters/fastify.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,23 @@ app.register(FastifyCookie as any, {
app.getInstance().addHook('onRequest', (request, reply, done) => {
// set undefined origin
const { origin } = request.headers
if (!origin) {
if (!origin)
request.headers.origin = request.headers.host
}

// forbidden php

const { url } = request

if (url.endsWith('.php')) {
reply.raw.statusMessage =
'Eh. PHP is not support on this machine. Yep, I also think PHP is bestest programming language. But for me it is beyond my reach.'
reply.raw.statusMessage
= 'Eh. PHP is not support on this machine. Yep, I also think PHP is bestest programming language. But for me it is beyond my reach.'

return reply.code(418).send()
}

// skip favicon request
if (url.match(/favicon.ico$/) || url.match(/manifest.json$/)) {
if (url.match(/favicon.ico$/) || url.match(/manifest.json$/))
return reply.code(204).send()
}

done()
})
20 changes: 11 additions & 9 deletions apps/api/src/common/decorators/api-result.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type, applyDecorators, HttpStatus } from '@nestjs/common'
import { HttpStatus, Type, applyDecorators } from '@nestjs/common'
import { ApiExtraModels, ApiResponse, getSchemaPath } from '@nestjs/swagger'

import { ResOp } from '@/common/model/response.model'
Expand All @@ -8,15 +8,15 @@ const baseTypeNames = ['String', 'Number', 'Boolean']
/**
* @description: 生成返回结果装饰器
*/
export const ApiResult = <TModel extends Type<any>>({
export function ApiResult<TModel extends Type<any>>({
type,
isPage,
status,
}: {
type?: TModel | TModel[]
isPage?: boolean
status?: HttpStatus
}) => {
}) {
let prop = null

if (Array.isArray(type)) {
Expand All @@ -40,19 +40,21 @@ export const ApiResult = <TModel extends Type<any>>({
},
},
}
} else {
}
else {
prop = {
type: 'array',
items: { $ref: getSchemaPath(type[0]) },
}
}
} else if (type) {
if (type && baseTypeNames.includes(type.name)) {
}
else if (type) {
if (type && baseTypeNames.includes(type.name))
prop = { type: type.name.toLocaleLowerCase() }
} else {
else
prop = { $ref: getSchemaPath(type) }
}
} else {
}
else {
prop = { type: 'null', default: null }
}

Expand Down
Loading

0 comments on commit 6c8fb30

Please sign in to comment.