From 9f4f763e463951103b81d853db859522cee41af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fork=CE=A8KILLET?= Date: Sun, 10 Dec 2023 04:43:46 +0800 Subject: [PATCH] chore: eslint --- frontend/.eslintrc.yml | 31 ++ frontend/package.json | 10 +- frontend/scripts/compress.ts | 17 +- frontend/src/components/ActionPanel.vue | 7 +- frontend/src/components/ArchiveEdition.vue | 7 +- frontend/src/components/ArchiveInfo.vue | 63 +++- frontend/src/components/ArchiveList.vue | 48 ++- frontend/src/components/AuthState.vue | 5 +- frontend/src/components/Correctness.vue | 70 ++-- frontend/src/components/LongPressButton.vue | 4 +- frontend/src/components/MiniSearcher.vue | 18 +- frontend/src/components/Modal.vue | 21 +- frontend/src/components/NyaCheckbox.vue | 7 +- frontend/src/components/NyaConfirmInput.vue | 38 ++- frontend/src/components/NyaDate.vue | 5 +- frontend/src/components/NyaList.vue | 15 +- frontend/src/components/NyaScroller.vue | 23 +- frontend/src/components/NyaSwitch.vue | 7 +- frontend/src/components/NyaTab.vue | 20 +- frontend/src/components/NyaTemplate.vue | 1 + frontend/src/components/NyaTitle.vue | 5 +- frontend/src/components/Pager.vue | 18 +- frontend/src/components/ShortcutList.vue | 1 + frontend/src/components/StatisticsItem.vue | 13 +- frontend/src/components/TestEntry.vue | 14 +- frontend/src/components/TestList.vue | 10 +- frontend/src/components/Topbar.vue | 5 +- frontend/src/components/Word.vue | 2 +- frontend/src/components/WordAdder.vue | 20 +- frontend/src/components/WordDetail.vue | 60 +++- frontend/src/components/WordDocument.vue | 41 ++- frontend/src/components/WordDocumentAdder.vue | 7 +- frontend/src/components/WordDocumentEntry.vue | 9 +- .../src/components/WordDocumentLabels.vue | 2 +- frontend/src/components/WordDocumentList.vue | 3 +- frontend/src/components/WordEntry.vue | 8 +- frontend/src/components/WordFilter.vue | 21 +- frontend/src/components/WordGraphChart.vue | 25 +- frontend/src/components/WordLink.vue | 4 +- .../src/components/WordLinkRelationship.vue | 8 +- frontend/src/components/WordList.vue | 6 +- frontend/src/components/WordMemCalendar.vue | 12 +- frontend/src/components/WordNavigator.vue | 8 +- frontend/src/components/WordSorter.vue | 3 +- frontend/src/components/WordSub.vue | 6 +- frontend/src/components/charts/Arrow.vue | 13 +- frontend/src/components/charts/Calendar.vue | 3 +- .../src/components/charts/EllipsisText.vue | 4 +- frontend/src/components/charts/PieChart.vue | 30 +- frontend/src/components/charts/TimeChart.vue | 15 +- frontend/src/components/config/ConfigItem.vue | 4 +- frontend/src/components/config/ConfigView.vue | 8 +- .../src/components/config/ShortcutItem.vue | 8 +- .../src/components/notifications/Noti.vue | 4 +- .../transitions/ListTransitionGroup.vue | 7 +- frontend/src/components/views/AboutView.vue | 14 +- .../views/ArchiveEditionTreeView.vue | 6 +- .../src/components/views/AutomationView.vue | 20 +- frontend/src/components/views/DebugView.vue | 31 +- frontend/src/components/views/HomeView.vue | 8 +- .../src/components/views/SettingsView.vue | 2 +- frontend/src/components/views/SignInView.vue | 14 +- frontend/src/components/views/SignUpView.vue | 21 +- .../src/components/views/StatisticsView.vue | 25 +- .../src/components/views/TestCreateView.vue | 24 +- frontend/src/components/views/TestGoView.vue | 66 +++- frontend/src/components/views/WordsView.vue | 40 ++- frontend/src/stores/config.ts | 3 +- frontend/src/stores/modal.ts | 2 +- frontend/src/stores/wordGraph.ts | 2 +- frontend/src/stores/words.ts | 2 +- .../src/utils/nyatalk/components/NtAst.vue | 16 +- .../utils/nyatalk/components/NtAstProp.vue | 2 +- .../utils/nyatalk/components/NtParseError.vue | 5 +- frontend/src/utils/nyatalk/functions.ts | 4 +- frontend/src/utils/nyatalk/index.ts | 11 +- frontend/src/utils/storage.ts | 2 +- pnpm-lock.yaml | 316 +++++++++++++----- 78 files changed, 1040 insertions(+), 420 deletions(-) create mode 100644 frontend/.eslintrc.yml diff --git a/frontend/.eslintrc.yml b/frontend/.eslintrc.yml new file mode 100644 index 0000000..13cb528 --- /dev/null +++ b/frontend/.eslintrc.yml @@ -0,0 +1,31 @@ +extends: + - 'plugin:vue/vue3-recommended' + - 'eslint:recommended' + - 'plugin:@typescript-eslint/recommended' + - '@vue/eslint-config-typescript' + +ignorePatterns: + - dist/* + +parser: 'vue-eslint-parser' + +parserOptions: + parser: '@typescript-eslint/parser' + +rules: + 'semi': [ 'warn', 'never' ] + 'no-empty': 'off' + 'no-unused-vars': 'off' + 'no-constant-condition': [ 'error', { checkLoops: false } ] + 'vue/html-indent': [ 'warn', 4 ] + 'vue/no-mutating-props': 'off' + 'vue/multi-word-component-names': 'off' + 'vue/require-v-for-key': 'off' + 'vue/no-deprecated-filter': 'off' + 'vue/valid-v-model': 'off' + 'vue/no-template-shadow': 'off' + '@typescript-eslint/no-unused-vars': [ 'error', { varsIgnorePattern: '^_' } ] + '@typescript-eslint/no-non-null-assertion': 'off' + '@typescript-eslint/no-empty-interface': 'off' + '@typescript-eslint/ban-types': 'off' + '@typescript-eslint/no-explicit-any': 'off' diff --git a/frontend/package.json b/frontend/package.json index 89edabc..d6ef7af 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,19 +7,22 @@ "dev": "VITE_BUILD_ENV=\"$(uname -sr)\" VITE_LAST_COMMIT=\"$(git log -1 HEAD --oneline --no-color --no-decorate)\" vite --port 1635", "check": "vue-tsc --noEmit", "build": "vue-tsc --noEmit && VITE_BUILD_TIME=\"$(date -R)\" VITE_BUILD_ENV=\"$(uname -sr)\" VITE_LAST_COMMIT=\"$(git log -1 HEAD --oneline --no-color --no-decorate)\" vite build", - "preview": "vite preview", - "compress": "pnpm -F nyadict-frontend-script compress -i ../src/types/index.ts -b @type -o ../src/utils/compress.ts" + "preview": "vite preview", + "compress": "pnpm -F nyadict-frontend-script compress -i ../src/types/index.ts -b @type -o ../src/utils/compress.ts", + "lint": "eslint --ext .ts,.vue ." }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.4.2", "@fortawesome/free-solid-svg-icons": "^6.4.2", "@fortawesome/vue-fontawesome": "^3.0.3", + "@typescript-eslint/parser": "^5.62.0", "@vueuse/components": "^10.5.0", "@vueuse/core": "^10.5.0", "axios": "^1.5.1", "d3-force": "^3.0.0", "d3-interpolate": "^3.0.1", "dayjs": "^1.11.10", + "eslint-plugin-vue": "^9.19.2", "json5": "^2.2.3", "jwt-decode": "^3.1.2", "mitt": "^3.0.1", @@ -34,8 +37,11 @@ "@types/d3-force": "^3.0.6", "@types/d3-interpolate": "^3.0.2", "@types/wanakana": "^4.0.4", + "@typescript-eslint/eslint-plugin": "^5.62.0", "@vitejs/plugin-vue": "^4.4.0", + "@vue/eslint-config-typescript": "^12.0.0", "@vue/runtime-core": "^3.3.4", + "eslint": "^8.51.0", "typescript": "^5.2.2", "vite": "^4.4.11", "vue-tsc": "^1.8.19" diff --git a/frontend/scripts/compress.ts b/frontend/scripts/compress.ts index 06a3e53..5ca3055 100644 --- a/frontend/scripts/compress.ts +++ b/frontend/scripts/compress.ts @@ -32,7 +32,7 @@ type TypeToCompress = { } function compress(file: string, base: string): string { - let program = ts.createProgram([ file ], {}) + const program = ts.createProgram([ file ], {}) const f = program.getSourceFile(file) const typeDefs: Record = {} @@ -105,7 +105,7 @@ function compress(file: string, base: string): string { log('Generating', typeName) - let compressTypes: string[] = [] + const compressTypes: string[] = [] let typeCode = '' let serCode = '' let deserCode = '' @@ -113,10 +113,10 @@ function compress(file: string, base: string): string { const typeDef = typeDefs[typeName] if (typeDef.kind === ts.SyntaxKind.TypeLiteral) { - let serInputs: string[] = [] - let deserInputs: string[] = [] - let serOutputs: string[] = [] - let deserOutputs: string[] = [] + const serInputs: string[] = [] + const deserInputs: string[] = [] + const serOutputs: string[] = [] + const deserOutputs: string[] = [] for (const propName in typeDef.propMap) { const { newName, question, typeNode } = typeDef.propMap[propName] @@ -172,13 +172,12 @@ function compress(file: string, base: string): string { } else if (typeDef.kind === ts.SyntaxKind.UnionType) { - let branches: { branchTypeText: string, tagTypeText: string }[] = [] + const branches: { branchTypeText: string, tagTypeText: string }[] = [] const tagName = typeDef.tag let newTagName: string typeDef.node.forEachChild(branch => { - let branchIndex = 0 if (ts.isTypeReferenceNode(branch)) { const branchTypeText = branch.getText(f) const branchTypeDef = typeDefs[branchTypeText] @@ -191,8 +190,6 @@ function compress(file: string, base: string): string { const tagTypeText = tagProp.typeNode.getText(f) branches.push({ branchTypeText, tagTypeText }) } - - branchIndex ++ } }) diff --git a/frontend/src/components/ActionPanel.vue b/frontend/src/components/ActionPanel.vue index b862c1b..f1d054b 100644 --- a/frontend/src/components/ActionPanel.vue +++ b/frontend/src/components/ActionPanel.vue @@ -15,9 +15,12 @@ const onSubmit = () => {

{{ title }}

- +
-