From 26455cd5c699bd20fb89c8626bf051045079b1d8 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 11 Jun 2025 17:28:04 +0800 Subject: [PATCH] perf: EsLint & Auto format --- frontend/.editorconfig | 13 +++++++++++++ frontend/.eslintignore | 8 ++++++++ frontend/.eslintrc.js | 33 +++++++++++++++++++++++++++++++++ frontend/.prettierrc | 8 ++++++++ frontend/package.json | 7 +++++++ frontend/src/stores/user.ts | 23 ++++++++++------------- 6 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 frontend/.editorconfig create mode 100644 frontend/.eslintignore create mode 100644 frontend/.eslintrc.js create mode 100644 frontend/.prettierrc diff --git a/frontend/.editorconfig b/frontend/.editorconfig new file mode 100644 index 00000000..a20656db --- /dev/null +++ b/frontend/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false \ No newline at end of file diff --git a/frontend/.eslintignore b/frontend/.eslintignore new file mode 100644 index 00000000..653c9a55 --- /dev/null +++ b/frontend/.eslintignore @@ -0,0 +1,8 @@ +/node_modules/ +/dist/ +/public/ +*.md +*.woff +*.ttf +.vscode/ +.DS_Store \ No newline at end of file diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js new file mode 100644 index 00000000..c382badf --- /dev/null +++ b/frontend/.eslintrc.js @@ -0,0 +1,33 @@ +module.exports = { + root: true, + env: { + node: true, + }, + extends: [ + 'plugin:vue/vue3-recommended', + 'eslint:recommended', + '@vue/typescript/recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', + ], + parserOptions: { + ecmaVersion: 2020, + }, + rules: { + 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', + 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', + 'vue/multi-word-component-names': 'off', + '@typescript-eslint/no-explicit-any': 'off', + 'prettier/prettier': [ + 'warn', + { + singleQuote: true, + semi: false, + trailingComma: 'es5', + printWidth: 100, + tabWidth: 2, + endOfLine: 'auto', + }, + ], + }, +} \ No newline at end of file diff --git a/frontend/.prettierrc b/frontend/.prettierrc new file mode 100644 index 00000000..63bb028e --- /dev/null +++ b/frontend/.prettierrc @@ -0,0 +1,8 @@ +{ + "singleQuote": true, + "semi": false, + "trailingComma": "es5", + "printWidth": 100, + "tabWidth": 2, + "endOfLine": "auto" +} \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 041a7350..32b888a6 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -31,12 +31,19 @@ "@types/crypto-js": "^4.2.2", "@types/element-resize-detector": "^1.1.6", "@types/node": "^22.14.1", + "@typescript-eslint/eslint-plugin": "^8.34.0", + "@typescript-eslint/parser": "^8.34.0", "@vitejs/plugin-vue": "^5.2.2", "@vue/tsconfig": "^0.7.0", "axios": "^1.8.4", "crypto-js": "^4.2.0", + "eslint": "^9.28.0", + "eslint-config-prettier": "^10.1.5", + "eslint-plugin-prettier": "^5.4.1", + "eslint-plugin-vue": "^10.2.0", "less": "^4.3.0", "pinia": "^3.0.2", + "prettier": "^3.5.3", "typescript": "~5.7.2", "unplugin-auto-import": "^19.1.2", "unplugin-vue-components-secondary": "^0.24.6", diff --git a/frontend/src/stores/user.ts b/frontend/src/stores/user.ts index 39c262cd..4d046091 100644 --- a/frontend/src/stores/user.ts +++ b/frontend/src/stores/user.ts @@ -7,8 +7,6 @@ import { store } from './index' const { wsCache } = useCache() - - interface UserState { token: string uid: string @@ -17,7 +15,7 @@ interface UserState { language: string exp: number time: number - [key: string]: string | number + [key: string]: string | number } export const UserStore = defineStore('user', { @@ -29,7 +27,7 @@ export const UserStore = defineStore('user', { oid: '', language: 'zh-CN', exp: 0, - time: 0 + time: 0, } }, getters: { @@ -53,10 +51,9 @@ export const UserStore = defineStore('user', { }, getTime(): number { return this.time - } + }, }, actions: { - async login(formData: { username: string; password: string }) { const res: any = await AuthApi.login(formData) this.setToken(res.access_token) @@ -66,13 +63,13 @@ export const UserStore = defineStore('user', { this.clear() }, - async info () { + async info() { const res: any = await AuthApi.info() const res_data = res || {} const keys = ['uid', 'name', 'oid', 'language', 'exp', 'time'] as const - - keys.forEach(key => { + + keys.forEach((key) => { const dkey = key === 'uid' ? 'id' : key const value = res_data[dkey] if (key === 'exp' || key === 'time') { @@ -122,11 +119,11 @@ export const UserStore = defineStore('user', { }, clear() { const keys: string[] = ['token', 'uid', 'name', 'oid', 'language', 'exp', 'time'] - keys.forEach(key => wsCache.delete('user.' + key)) - } - } + keys.forEach((key) => wsCache.delete('user.' + key)) + }, + }, }) export const useUserStore = () => { return UserStore(store) -} \ No newline at end of file +}