From 3ac89945c462f35f5400bec45fa9e4e1c26622f3 Mon Sep 17 00:00:00 2001 From: n0099 Date: Tue, 19 Dec 2023 00:17:13 +0800 Subject: [PATCH] * specify `parser` & `parserOptions.parser` on `*.vue` following https://github.com/vuejs/vue-eslint-parser/issues/104#issuecomment-1296267732 @ .eslintrc.cjs * re-order `overrides` to specify `settings.import/resolver.vite` over `*.vue`, `settings.import/resolver.typescript` over `*.ts` & rules over `.eslintrc.cjs`, * `eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call` @ main.ts * `eslint-disable` @ stats.js * fix the return type of `_.defaultsDeep()` is `any` @ `useQueryForm.fillParamDefaultValue()` - `shims-vue.d.ts` following https://github.com/vuejs/vue-eslint-parser/issues/104#issuecomment-1217306443 $ yarn add -D typescript-eslint-parser-for-extra-files @ fe --- fe/.eslintrc.cjs | 49 +++++++++++-------- fe/package.json | 1 + .../components/Post/queryForm/useQueryForm.ts | 2 +- fe/src/main.ts | 1 + fe/src/shims-vue.d.ts | 6 --- fe/src/stats.js | 1 + fe/yarn.lock | 23 +++++++++ 7 files changed, 55 insertions(+), 28 deletions(-) delete mode 100644 fe/src/shims-vue.d.ts diff --git a/fe/.eslintrc.cjs b/fe/.eslintrc.cjs index a41fda4b..cfa22fb7 100644 --- a/fe/.eslintrc.cjs +++ b/fe/.eslintrc.cjs @@ -1,32 +1,11 @@ module.exports = { root: true, overrides: [{ - // https://stackoverflow.com/questions/57107800/eslint-disable-extends-in-override - files: '.eslintrc.cjs', - plugins: ['@stylistic', '@stylistic/migrate'], - rules: { - '@stylistic/migrate/migrate-js': 'error', - '@stylistic/migrate/migrate-ts': 'error', - '@stylistic/quote-props': ['error', 'as-needed'], - '@stylistic/comma-dangle': ['error', 'always-multiline'], - '@stylistic/quotes': ['error', 'single', { avoidEscape: true }], - }, - }, { files: '*', - excludedFiles: '.eslintrc.cjs', - parser: 'vue-eslint-parser', parserOptions: { - parser: '@typescript-eslint/parser', project: ['./tsconfig.json', './tsconfig.node.json'], tsconfigRootDir: __dirname, }, - settings: { - 'import/resolver': { - typescript: true, - // https://github.com/pzmosquito/eslint-import-resolver-vite/issues/12#issuecomment-1858743165 - vite: { viteConfig: require('import-sync')('./vite.config.ts').default }, - }, - }, plugins: ['@stylistic'], extends: [ 'eslint:recommended', @@ -489,5 +468,33 @@ module.exports = { 'vue/no-unused-emit-declarations': 'error', 'vue/no-ref-object-reactivity-loss': 'error', }, + }, { // https://stackoverflow.com/questions/57107800/eslint-disable-extends-in-override + files: '.eslintrc.cjs', + plugins: ['@stylistic', '@stylistic/migrate'], + rules: { + '@stylistic/migrate/migrate-js': 'error', + '@stylistic/migrate/migrate-ts': 'error', + '@stylistic/comma-dangle': ['error', 'always-multiline'], + '@typescript-eslint/naming-convention': 'off', + }, + }, { + files: '*.ts', + parser: 'typescript-eslint-parser-for-extra-files', + settings: { 'import/resolver': { typescript: true } } + }, { + files: '*.vue', + parser: 'vue-eslint-parser', + parserOptions: { + parser: 'typescript-eslint-parser-for-extra-files', + project: ['./tsconfig.json', './tsconfig.node.json'], + tsconfigRootDir: __dirname, + }, + settings: { + 'import/resolver': { + typescript: true, + // https://github.com/pzmosquito/eslint-import-resolver-vite/issues/12#issuecomment-1858743165 + vite: { viteConfig: require('import-sync')('./vite.config.ts').default }, + }, + }, }], }; diff --git a/fe/package.json b/fe/package.json index 1875ff42..daa107a0 100644 --- a/fe/package.json +++ b/fe/package.json @@ -55,6 +55,7 @@ "import-sync": "^2.2.0", "stats.js": "^0.17.0", "typescript": "^5.3.3", + "typescript-eslint-parser-for-extra-files": "^0.5.0", "vite": "^5.0.10", "vue-tsc": "^1.8.25" }, diff --git a/fe/src/components/Post/queryForm/useQueryForm.ts b/fe/src/components/Post/queryForm/useQueryForm.ts index c279d4a5..43a40520 100644 --- a/fe/src/components/Post/queryForm/useQueryForm.ts +++ b/fe/src/components/Post/queryForm/useQueryForm.ts @@ -38,7 +38,7 @@ export default < defaultParam.subParam.not = false; // add subParam.not on every param // cloneDeep to prevent defaultsDeep mutates origin object if (resetToDefault) - return _.defaultsDeep(defaultParam, param); + return _.defaultsDeep(defaultParam, param) as T; return _.defaultsDeep(_.cloneDeep(param), defaultParam); }; const addParam = (name: string) => { diff --git a/fe/src/main.ts b/fe/src/main.ts index 17e2cb28..0ff84ad1 100644 --- a/fe/src/main.ts +++ b/fe/src/main.ts @@ -20,6 +20,7 @@ nprogress.configure({ trickleSpeed: 200 }); if (import.meta.env.DEV) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error // @ts-ignore + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call (await import('@/checkForUndefinedCSSClasses.js')).default(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error // @ts-ignore diff --git a/fe/src/shims-vue.d.ts b/fe/src/shims-vue.d.ts deleted file mode 100644 index 02ab5edb..00000000 --- a/fe/src/shims-vue.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -/* eslint-disable */ -declare module '*.vue' { - import type { DefineComponent } from 'vue'; - const component: DefineComponent<{}, {}, any>; - export default component; -} diff --git a/fe/src/stats.js b/fe/src/stats.js index e280714d..28491a61 100644 --- a/fe/src/stats.js +++ b/fe/src/stats.js @@ -1,3 +1,4 @@ +/* eslint-disable */ import Stats from 'stats.js'; const stats = new Stats(); stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom diff --git a/fe/yarn.lock b/fe/yarn.lock index 2c95437b..543322f9 100644 --- a/fe/yarn.lock +++ b/fe/yarn.lock @@ -3735,6 +3735,7 @@ __metadata: stats.js: "npm:^0.17.0" tippy.js: "npm:^6.3.7" typescript: "npm:^5.3.3" + typescript-eslint-parser-for-extra-files: "npm:^0.5.0" v-viewer: "npm:^3.0.11" vanilla-lazyload: "npm:^17.8.5" vite: "npm:^5.0.10" @@ -3816,6 +3817,28 @@ __metadata: languageName: node linkType: hard +"typescript-eslint-parser-for-extra-files@npm:^0.5.0": + version: 0.5.0 + resolution: "typescript-eslint-parser-for-extra-files@npm:0.5.0" + peerDependencies: + "@typescript-eslint/parser": ">=5.41.0" + astrojs-compiler-sync: ">=0.3.1" + svelte2tsx: ">=0.5.20" + typescript: ">=4.8.4" + vue: ^3.2.45 + peerDependenciesMeta: + astrojs-compiler-sync: + optional: true + svelte2tsx: + optional: true + typescript: + optional: true + vue: + optional: true + checksum: fdb0110e22cb9a11f4042e09afce2bf38b2abdb41288d609a347f0628412cc444dc8b8a041eec86f11079e6e437a98490bc0699549d0029342a1a99bfe2854aa + languageName: node + linkType: hard + "typescript@npm:^5.3.3": version: 5.3.3 resolution: "typescript@npm:5.3.3"