From 6cc3b4de9fb2e1c8ffd55fcf7f63a503572561de Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Sat, 11 May 2024 14:20:56 +0800 Subject: [PATCH] style: sort imports (#746) --- eslint.config.mjs | 60 ++++++++++++------- package.json | 1 + pnpm-lock.yaml | 12 ++++ scripts/client.ts | 2 +- scripts/manifest.ts | 1 + scripts/prepare.ts | 4 +- scripts/utils.ts | 1 + src/background/index.ts | 1 + src/background/messageListeners/index.ts | 6 +- src/background/utils.ts | 14 ++--- src/components/Dialog.vue | 1 + src/components/Dock/Dock.vue | 7 ++- src/components/HorizontalScrollView.vue | 1 + .../LongCoverCard/LongCoverCard.vue | 2 +- .../RightSideButtons/RightSideButtons.vue | 5 +- src/components/SearchBar/SearchBar.vue | 8 ++- src/components/Settings/Settings.vue | 5 +- src/components/Settings/components/About.vue | 6 +- .../Settings/components/Appearance.vue | 8 ++- .../Settings/components/Compatibility.vue | 7 ++- .../Settings/components/General.vue | 6 +- src/components/Settings/components/Home.vue | 16 ++--- .../Settings/components/SearchPage.vue | 7 ++- src/components/TopBar/TopBar.vue | 20 ++++--- .../TopBar/components/ChannelsPop.vue | 1 + .../TopBar/components/FavoritesPop.vue | 8 ++- .../TopBar/components/HistoryPop.vue | 13 ++-- .../TopBar/components/MomentsPop.vue | 9 +-- src/components/TopBar/components/MorePop.vue | 1 + .../TopBar/components/NotificationsPop.vue | 3 +- .../TopBar/components/UserPanelPop.vue | 8 ++- .../TopBar/components/WatchLaterPop.vue | 7 ++- src/components/VideoCard/VideoCard.vue | 3 +- src/composables/useAppProvider.ts | 1 + src/composables/useDark.ts | 1 + src/composables/useStorageLocal.ts | 2 +- src/contentScripts/index.ts | 15 ++--- src/contentScripts/views/Anime/Anime.vue | 13 ++-- .../views/Anime/components/AnimeTimeTable.vue | 5 +- src/contentScripts/views/App.vue | 1 + .../views/Favorites/Favorites.vue | 13 ++-- src/contentScripts/views/History/History.vue | 11 ++-- src/contentScripts/views/Home/Home.vue | 5 +- .../views/Home/components/Following.vue | 5 +- .../views/Home/components/ForYou.vue | 19 +++--- .../views/Home/components/Ranking.vue | 16 ++--- .../Home/components/SubscribedSeries.vue | 5 +- .../views/Home/components/Trending.vue | 5 +- src/contentScripts/views/Search/Search.vue | 2 +- .../views/WatchLater/WatchLater.vue | 7 ++- src/logic/common-setup.ts | 8 ++- src/logic/storage.ts | 2 +- src/manifest.ts | 1 + src/options/main.ts | 4 +- src/popup/Popup.vue | 2 +- src/popup/main.ts | 4 +- src/stores/mainStore.ts | 1 + src/stores/topBarStore.ts | 1 + src/styles/adaptedStyles/index.ts | 1 + src/tests/uriParse.spec.ts | 1 + src/utils/authProvider.ts | 3 +- src/utils/dataFormatter.ts | 3 +- src/utils/i18n.ts | 2 +- src/utils/mitt.ts | 2 +- tsup.config.ts | 1 + unocss.config.ts | 2 +- vite-mv3-hmr.ts | 4 +- vite.config.content.ts | 5 +- vite.config.ts | 12 ++-- 69 files changed, 268 insertions(+), 171 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 4913738c4f..9d8dfc33a7 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,28 +1,42 @@ import antfu from '@antfu/eslint-config' +import simpleImportSort from 'eslint-plugin-simple-import-sort' -export default antfu({ - rules: { - 'vue/max-attributes-per-line': [ - 'error', - { - singleline: { - max: 5, +export default antfu( + { + rules: { + 'vue/max-attributes-per-line': [ + 'error', + { + singleline: { + max: 5, + }, + multiline: { + max: 5, + }, }, - multiline: { - max: 5, - }, - }, - ], - 'no-alert': 'off', - 'style/quote-props': 'off', + ], + 'no-alert': 'off', + 'style/quote-props': 'off', + }, + eslint: { + ignorePatterns: [ + 'dist', + 'node_modules', + 'public', + 'extension', + 'extension-firefox', + ], + }, }, - eslint: { - ignorePatterns: [ - 'dist', - 'node_modules', - 'public', - 'extension', - 'extension-firefox', - ], + { + plugins: { + 'simple-import-sort': simpleImportSort, + }, + rules: { + 'import/order': 'off', + 'sort-imports': 'off', + 'simple-import-sort/imports': 'error', + 'simple-import-sort/exports': 'error', + }, }, -}) +) diff --git a/package.json b/package.json index c034e01afe..193a5ced55 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "cross-env": "^7.0.3", "crx": "^5.0.1", "eslint": "^9.2.0", + "eslint-plugin-simple-import-sort": "^12.1.0", "esno": "^4.7.0", "fs-extra": "^11.2.0", "jsdom": "^24.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4cb397a11d..8b26a11255 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,6 +81,9 @@ importers: eslint: specifier: ^9.2.0 version: 9.2.0 + eslint-plugin-simple-import-sort: + specifier: ^12.1.0 + version: 12.1.0(eslint@9.2.0) esno: specifier: ^4.7.0 version: 4.7.0 @@ -2367,6 +2370,11 @@ packages: vue-eslint-parser: optional: true + eslint-plugin-simple-import-sort@12.1.0: + resolution: {integrity: sha512-Y2fqAfC11TcG/WP3TrI1Gi3p3nc8XJyEOJYHyEPEGI/UAgNx6akxxlX74p7SbAQdLcgASKhj8M0GKvH3vq/+ig==} + peerDependencies: + eslint: '>=5.0.0' + eslint-plugin-toml@0.11.0: resolution: {integrity: sha512-sau+YvPU4fWTjB+qtBt3n8WS87aoDCs+BVbSUAemGaIsRNbvR9uEk+Tt892iLHTGvp/DPWYoCX4/8DoyAbB+sQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -7934,6 +7942,10 @@ snapshots: - supports-color - typescript + eslint-plugin-simple-import-sort@12.1.0(eslint@9.2.0): + dependencies: + eslint: 9.2.0 + eslint-plugin-toml@0.11.0(eslint@9.2.0): dependencies: debug: 4.3.4 diff --git a/scripts/client.ts b/scripts/client.ts index 88b4b181fd..5a12d23b06 100644 --- a/scripts/client.ts +++ b/scripts/client.ts @@ -1,6 +1,6 @@ import type { ErrorPayload, HMRPayload, Update } from 'vite' -import type { ViteHotContext } from 'vite/types/hot' import type { InferCustomEventPayload } from 'vite/types/customEvent' +import type { ViteHotContext } from 'vite/types/hot' // Vite v3 doesn't export overlay // import { ErrorOverlay, overlayId } from 'vite/src/client/overlay' diff --git a/scripts/manifest.ts b/scripts/manifest.ts index dbe354b710..7cca6b73ea 100644 --- a/scripts/manifest.ts +++ b/scripts/manifest.ts @@ -1,4 +1,5 @@ import fs from 'fs-extra' + import { getManifest } from '../src/manifest' import { isFirefox, log, r } from './utils' diff --git a/scripts/prepare.ts b/scripts/prepare.ts index c36835c220..f3abbab188 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -1,7 +1,9 @@ // generate stub index.html files for dev entry import { execSync } from 'node:child_process' -import fs from 'fs-extra' + import chokidar from 'chokidar' +import fs from 'fs-extra' + import { isDev, isFirefox, log, r } from './utils' /** diff --git a/scripts/utils.ts b/scripts/utils.ts index 8d573b0acc..818d516e71 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -1,6 +1,7 @@ import { dirname, resolve } from 'node:path' import process from 'node:process' import { fileURLToPath } from 'node:url' + import { bgCyan, black } from 'kolorist' export const port = Number.parseInt(process.env.PORT || '') || 3303 diff --git a/src/background/index.ts b/src/background/index.ts index fc1968ac98..c31a1a9699 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -1,4 +1,5 @@ import browser from 'webextension-polyfill' + import { setupAllMsgLstnrs } from './messageListeners' browser.runtime.onInstalled.addListener((): void => { diff --git a/src/background/messageListeners/index.ts b/src/background/messageListeners/index.ts index bf9850e19b..9d3f6ee0f0 100644 --- a/src/background/messageListeners/index.ts +++ b/src/background/messageListeners/index.ts @@ -1,10 +1,10 @@ import browser from 'webextension-polyfill' -import { apiListenerFactory } from '../utils' -import API_AUTH from './auth' +import { apiListenerFactory } from '../utils' import API_ANIME from './anime' -import API_HISTORY from './history' +import API_AUTH from './auth' import API_FAVORITE from './favorite' +import API_HISTORY from './history' import API_MOMENT from './moment' import API_NOTIFICATION from './notification' import API_RANKING from './ranking' diff --git a/src/background/utils.ts b/src/background/utils.ts index e6a2d9d7e3..2ad6b86e84 100644 --- a/src/background/utils.ts +++ b/src/background/utils.ts @@ -119,14 +119,14 @@ function apiListenerFactory(API_MAP: APIMAP) { } export { - type FetchAfterHandler, - toJsonHandler, - toData, - sendResponseHandler, - AHS, - type Message, type _FETCH, + AHS, type API, - type APIMAP, apiListenerFactory, + type APIMAP, + type FetchAfterHandler, + type Message, + sendResponseHandler, + toData, + toJsonHandler, } diff --git a/src/components/Dialog.vue b/src/components/Dialog.vue index 2343a735dc..78d38509d3 100644 --- a/src/components/Dialog.vue +++ b/src/components/Dialog.vue @@ -1,5 +1,6 @@