diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7eae02c..d305056 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,13 +1,16 @@ { "name": "ci_monitor", - "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", + "image": "mcr.microsoft.com/devcontainers/typescript-node:20", "customizations": { "vscode": { "settings": { "files.autoSave": "afterDelay", "editor.guides.bracketPairs": true, "editor.defaultFormatter": "esbenp.prettier-vscode", - "editor.formatOnSave": true + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "always" + } }, "extensions": [ "eamodio.gitlens", diff --git a/bun.lockb b/bun.lockb index db55d51..1e242db 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/controllers/managePipeLine/index.ts b/controllers/managePipeLine/index.ts index 8f65b05..b15af43 100644 --- a/controllers/managePipeLine/index.ts +++ b/controllers/managePipeLine/index.ts @@ -1,8 +1,9 @@ +import moment from "moment"; + import db from "../../db"; import service from "../../service"; -import moment from "moment"; -import { Gitlab } from "../../types/gitlab"; import { DB } from "../../types/db"; +import { Gitlab } from "../../types/gitlab"; /** * 获取全部的pipeline列表 diff --git a/db/index.ts b/db/index.ts index 164175f..c3d876b 100644 --- a/db/index.ts +++ b/db/index.ts @@ -1,5 +1,5 @@ -import project from "./project"; import pipeline from "./pipeline"; +import project from "./project"; import user from "./user"; import view from "./view"; diff --git a/db/pipeline/index.ts b/db/pipeline/index.ts index 32bbc1c..3f42a0f 100644 --- a/db/pipeline/index.ts +++ b/db/pipeline/index.ts @@ -1,6 +1,6 @@ -import pbClient from "../pbClient"; -import { managePb404 } from "../../utils/pbTools"; import { DB } from "../../types/db"; +import { managePb404 } from "../../utils/pbTools"; +import pbClient from "../pbClient"; /** * 通过其 ID 检索一个管道。 diff --git a/db/project/index.ts b/db/project/index.ts index cd008d6..71d318a 100644 --- a/db/project/index.ts +++ b/db/project/index.ts @@ -1,6 +1,6 @@ +import { DB } from "../../types/db"; import { managePb404 } from "../../utils/pbTools"; import pbClient from "../pbClient"; -import { DB } from "../../types/db"; /** * 通过其 ID 检索单个项目。 diff --git a/db/user/index.ts b/db/user/index.ts index b003673..685b2c3 100644 --- a/db/user/index.ts +++ b/db/user/index.ts @@ -1,6 +1,6 @@ +import { DB } from "../../types/db"; import { managePb404 } from "../../utils/pbTools"; import pbClient from "../pbClient"; -import { DB } from "../../types/db"; /** * 根据提供的ID从数据库检索单个用户。 diff --git a/db/view/index.ts b/db/view/index.ts index 4c0fb9f..4f74c04 100644 --- a/db/view/index.ts +++ b/db/view/index.ts @@ -1,6 +1,6 @@ +import { DB } from "../../types/db"; import { managePb404 } from "../../utils/pbTools"; import pbClient from "../pbClient"; -import { DB } from "../../types/db"; /** * 根据给定的周来检索完整的统计信息。 diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..4343203 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,22 @@ +import pluginJs from "@eslint/js"; +import simpleImportSort from "eslint-plugin-simple-import-sort"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + +export default [ + { files: ["**/*.{js,mjs,cjs,ts}"] }, + { languageOptions: { globals: globals.browser } }, + pluginJs.configs.recommended, + ...tseslint.configs.recommended, + { + plugins: { + "simple-import-sort": simpleImportSort, + }, + rules: { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-namespace": "off", + "simple-import-sort/imports": "error", + "simple-import-sort/exports": "error", + }, + }, +]; diff --git a/package.json b/package.json index a2bf4d6..dd3952c 100644 --- a/package.json +++ b/package.json @@ -3,20 +3,26 @@ "module": "index.ts", "type": "module", "scripts": { - "start": "bun run index.ts" + "start": "bun run index.ts", + "lint": "eslint --fix ." }, "devDependencies": { - "bun-types": "latest" + "@eslint/js": "^9.7.0", + "@types/lodash": "^4.14.202", + "@types/node-schedule": "^2.1.6", + "bun-types": "latest", + "eslint": "9.x", + "eslint-plugin-simple-import-sort": "^12.1.1", + "globals": "^15.8.0", + "typescript-eslint": "^7.17.0" }, "peerDependencies": { "typescript": "^5.0.0" }, "dependencies": { - "@types/node-schedule": "^2.1.6", - "@types/lodash": "^4.14.202", "lodash": "^4.17.21", "moment": "^2.30.1", "node-schedule": "^2.1.1", "pocketbase": "^0.21.1" } -} +} \ No newline at end of file diff --git a/schedule/index.ts b/schedule/index.ts index 79bb937..9e83cd0 100644 --- a/schedule/index.ts +++ b/schedule/index.ts @@ -1,4 +1,5 @@ import { scheduleJob } from "node-schedule"; + import manageRobot from "../controllers/manageRobot"; import syncPipLine from "./syncPipLine"; diff --git a/service/gitlab/tools.ts b/service/gitlab/tools.ts index 622706b..48ec540 100644 --- a/service/gitlab/tools.ts +++ b/service/gitlab/tools.ts @@ -1,7 +1,7 @@ import { Gitlab } from "../../types/gitlab"; export const gitlabReqWarp = async ( - func: Function, + func: () => Promise, default_value: any ): Promise => { try { diff --git a/service/netTool.ts b/service/netTool.ts index cdd2d46..190dcce 100644 --- a/service/netTool.ts +++ b/service/netTool.ts @@ -84,7 +84,9 @@ const netTool = async ({ try { resText = await res.text(); resData = JSON.parse(resText); - } catch {} + } catch { + /* empty */ + } // 记录响应 logResponse(res, method, headers, payload, resData || resText); diff --git a/utils/pbTools.ts b/utils/pbTools.ts index 3d8a903..f7e8026 100644 --- a/utils/pbTools.ts +++ b/utils/pbTools.ts @@ -1,4 +1,6 @@ -export const managePb404 = async (dbFunc: Function): Promise => { +export const managePb404 = async ( + dbFunc: () => Promise +): Promise => { try { return await dbFunc(); } catch (err: any) {