Commit 6890dd720135b52e2d810fd85ae44062bec0c661
1 parent
762e5dee
perf: 新包使用更严格的eslint
Showing
20 changed files
with
96 additions
and
46 deletions
internal/eslint-config/.eslintrc.js
internal/eslint-config/src/strict.ts
1 | -import baseLintConfig from './index'; | ||
2 | - | ||
3 | export default { | 1 | export default { |
4 | - extends: [baseLintConfig], | 2 | + extends: ['@vben'], |
5 | plugins: ['simple-import-sort'], | 3 | plugins: ['simple-import-sort'], |
6 | rules: { | 4 | rules: { |
7 | 'simple-import-sort/imports': 'error', | 5 | 'simple-import-sort/imports': 'error', |
8 | 'simple-import-sort/exports': 'error', | 6 | 'simple-import-sort/exports': 'error', |
9 | 7 | ||
10 | - '@typescript-eslint/ban-types': 'error', | ||
11 | - '@typescript-eslint/ban-ts-ignore': 'error', | ||
12 | - '@typescript-eslint/ban-ts-comment': 'error', | ||
13 | - '@typescript-eslint/no-explicit-any': 'error', | 8 | + '@typescript-eslint/ban-ts-comment': [ |
9 | + 'error', | ||
10 | + { | ||
11 | + 'ts-expect-error': 'allow-with-description', | ||
12 | + 'ts-ignore': 'allow-with-description', | ||
13 | + 'ts-nocheck': 'allow-with-description', | ||
14 | + 'ts-check': false, | ||
15 | + }, | ||
16 | + ], | ||
17 | + | ||
18 | + /** | ||
19 | + * 【强制】关键字前后有一个空格 | ||
20 | + * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/keyword-spacing.md | ||
21 | + */ | ||
22 | + 'keyword-spacing': 'off', | ||
23 | + '@typescript-eslint/keyword-spacing': [ | ||
24 | + 'error', | ||
25 | + { | ||
26 | + before: true, | ||
27 | + after: true, | ||
28 | + overrides: { | ||
29 | + return: { after: true }, | ||
30 | + throw: { after: true }, | ||
31 | + case: { after: true }, | ||
32 | + }, | ||
33 | + }, | ||
34 | + ], | ||
35 | + | ||
36 | + /** | ||
37 | + * 禁止出现空函数,普通函数(非 async/await/generator)、箭头函数、类上的方法除外 | ||
38 | + * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md | ||
39 | + */ | ||
40 | + 'no-empty-function': 'off', | ||
41 | + '@typescript-eslint/no-empty-function': [ | ||
42 | + 'error', | ||
43 | + { | ||
44 | + allow: ['arrowFunctions', 'functions', 'methods'], | ||
45 | + }, | ||
46 | + ], | ||
47 | + | ||
48 | + /** | ||
49 | + * 优先使用 interface 而不是 type 定义对象类型 | ||
50 | + * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-definitions.md | ||
51 | + */ | ||
52 | + '@typescript-eslint/consistent-type-definitions': ['warn', 'interface'], | ||
14 | 53 | ||
15 | 'vue/attributes-order': 'error', | 54 | 'vue/attributes-order': 'error', |
16 | 'vue/require-default-prop': 'error', | 55 | 'vue/require-default-prop': 'error', |
internal/stylelint-config/.eslintrc.js
internal/vite-config/.eslintrc.js
internal/vite-config/src/config/application.ts
1 | -import { type UserConfig, defineConfig, mergeConfig, loadEnv } from 'vite'; | ||
2 | import { resolve } from 'node:path'; | 1 | import { resolve } from 'node:path'; |
2 | + | ||
3 | +import dayjs from 'dayjs'; | ||
3 | import { readPackageJSON } from 'pkg-types'; | 4 | import { readPackageJSON } from 'pkg-types'; |
5 | +import { defineConfig, loadEnv, mergeConfig, type UserConfig } from 'vite'; | ||
6 | + | ||
7 | +import { createPlugins } from '../plugins'; | ||
4 | import { generateModifyVars } from '../utils/modifyVars'; | 8 | import { generateModifyVars } from '../utils/modifyVars'; |
5 | import { commonConfig } from './common'; | 9 | import { commonConfig } from './common'; |
6 | -import { createPlugins } from '../plugins'; | ||
7 | -import dayjs from 'dayjs'; | ||
8 | 10 | ||
9 | interface DefineOptions { | 11 | interface DefineOptions { |
10 | overrides?: UserConfig; | 12 | overrides?: UserConfig; |
11 | - options?: {}; | 13 | + options?: { |
14 | + // | ||
15 | + }; | ||
12 | } | 16 | } |
13 | 17 | ||
14 | function defineApplicationConfig(defineOptions: DefineOptions = {}) { | 18 | function defineApplicationConfig(defineOptions: DefineOptions = {}) { |
internal/vite-config/src/config/common.ts
1 | -import { type UserConfig } from 'vite'; | ||
2 | -import UnoCSS from 'unocss/vite'; | ||
3 | import { presetTypography, presetUno } from 'unocss'; | 1 | import { presetTypography, presetUno } from 'unocss'; |
2 | +import UnoCSS from 'unocss/vite'; | ||
3 | +import { type UserConfig } from 'vite'; | ||
4 | 4 | ||
5 | const commonConfig: UserConfig = { | 5 | const commonConfig: UserConfig = { |
6 | server: { | 6 | server: { |
internal/vite-config/src/config/package.ts
1 | -import { type UserConfig, defineConfig, mergeConfig } from 'vite'; | ||
2 | import { readPackageJSON } from 'pkg-types'; | 1 | import { readPackageJSON } from 'pkg-types'; |
3 | -import { commonConfig } from './common'; | 2 | +import { defineConfig, mergeConfig, type UserConfig } from 'vite'; |
4 | import dts from 'vite-plugin-dts'; | 3 | import dts from 'vite-plugin-dts'; |
5 | 4 | ||
5 | +import { commonConfig } from './common'; | ||
6 | + | ||
6 | interface DefineOptions { | 7 | interface DefineOptions { |
7 | overrides?: UserConfig; | 8 | overrides?: UserConfig; |
8 | - options?: {}; | 9 | + options?: { |
10 | + // | ||
11 | + }; | ||
9 | } | 12 | } |
10 | 13 | ||
11 | function definePackageConfig(defineOptions: DefineOptions = {}) { | 14 | function definePackageConfig(defineOptions: DefineOptions = {}) { |
internal/vite-config/src/plugins/appConfig.ts
1 | +import colors from 'picocolors'; | ||
2 | +import { readPackageJSON } from 'pkg-types'; | ||
1 | import { type PluginOption } from 'vite'; | 3 | import { type PluginOption } from 'vite'; |
4 | + | ||
2 | import { getEnvConfig } from '../utils/env'; | 5 | import { getEnvConfig } from '../utils/env'; |
3 | import { createContentHash } from '../utils/hash'; | 6 | import { createContentHash } from '../utils/hash'; |
4 | -import { readPackageJSON } from 'pkg-types'; | ||
5 | -import colors from 'picocolors'; | ||
6 | 7 | ||
7 | const GLOBAL_CONFIG_FILE_NAME = '_app.config.js'; | 8 | const GLOBAL_CONFIG_FILE_NAME = '_app.config.js'; |
8 | const PLUGIN_NAME = 'app-config'; | 9 | const PLUGIN_NAME = 'app-config'; |
internal/vite-config/src/plugins/index.ts
1 | +import vue from '@vitejs/plugin-vue'; | ||
2 | +import vueJsx from '@vitejs/plugin-vue-jsx'; | ||
3 | +// @ts-ignore: type unless | ||
4 | +import DefineOptions from 'unplugin-vue-define-options/vite'; | ||
1 | import { type PluginOption } from 'vite'; | 5 | import { type PluginOption } from 'vite'; |
6 | +import purgeIcons from 'vite-plugin-purge-icons'; | ||
7 | + | ||
8 | +import { createAppConfigPlugin } from './appConfig'; | ||
9 | +import { configCompressPlugin } from './compress'; | ||
2 | import { configHtmlPlugin } from './html'; | 10 | import { configHtmlPlugin } from './html'; |
3 | import { configMockPlugin } from './mock'; | 11 | import { configMockPlugin } from './mock'; |
4 | -import { configCompressPlugin } from './compress'; | ||
5 | -import { configVisualizerConfig } from './visualizer'; | ||
6 | import { configSvgIconsPlugin } from './svgSprite'; | 12 | import { configSvgIconsPlugin } from './svgSprite'; |
7 | -import { createAppConfigPlugin } from './appConfig'; | ||
8 | -import vue from '@vitejs/plugin-vue'; | ||
9 | -import vueJsx from '@vitejs/plugin-vue-jsx'; | ||
10 | -import purgeIcons from 'vite-plugin-purge-icons'; | ||
11 | -// @ts-ignore | ||
12 | -import DefineOptions from 'unplugin-vue-define-options/vite'; | 13 | +import { configVisualizerConfig } from './visualizer'; |
13 | 14 | ||
14 | interface Options { | 15 | interface Options { |
15 | isBuild: boolean; | 16 | isBuild: boolean; |
internal/vite-config/src/plugins/svgSprite.ts
@@ -3,9 +3,10 @@ | @@ -3,9 +3,10 @@ | ||
3 | * https://github.com/anncwb/vite-plugin-svg-icons | 3 | * https://github.com/anncwb/vite-plugin-svg-icons |
4 | */ | 4 | */ |
5 | 5 | ||
6 | -import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'; | ||
7 | import { resolve } from 'node:path'; | 6 | import { resolve } from 'node:path'; |
7 | + | ||
8 | import type { PluginOption } from 'vite'; | 8 | import type { PluginOption } from 'vite'; |
9 | +import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'; | ||
9 | 10 | ||
10 | export function configSvgIconsPlugin({ isBuild }: { isBuild: boolean }) { | 11 | export function configSvgIconsPlugin({ isBuild }: { isBuild: boolean }) { |
11 | const svgIconsPlugin = createSvgIconsPlugin({ | 12 | const svgIconsPlugin = createSvgIconsPlugin({ |
internal/vite-config/src/plugins/visualizer.ts
1 | /** | 1 | /** |
2 | * Package file volume analysis | 2 | * Package file volume analysis |
3 | */ | 3 | */ |
4 | -import { type PluginOption } from 'vite'; | ||
5 | import visualizer from 'rollup-plugin-visualizer'; | 4 | import visualizer from 'rollup-plugin-visualizer'; |
5 | +import { type PluginOption } from 'vite'; | ||
6 | 6 | ||
7 | export function configVisualizerConfig() { | 7 | export function configVisualizerConfig() { |
8 | return visualizer({ | 8 | return visualizer({ |
internal/vite-config/src/utils/env.ts
internal/vite-config/src/utils/modifyVars.ts
1 | -import { generate } from '@ant-design/colors'; | ||
2 | import { resolve } from 'node:path'; | 1 | import { resolve } from 'node:path'; |
3 | -// @ts-ignore | 2 | + |
3 | +import { generate } from '@ant-design/colors'; | ||
4 | +// @ts-ignore: typo | ||
4 | import { getThemeVariables } from 'ant-design-vue/dist/theme'; | 5 | import { getThemeVariables } from 'ant-design-vue/dist/theme'; |
5 | 6 | ||
6 | const primaryColor = '#0960bd'; | 7 | const primaryColor = '#0960bd'; |
packages/hooks/.eslintrc.js
packages/hooks/src/index.ts
packages/hooks/src/onMountedOrActivated.ts
1 | import { type AnyFunction } from '@vben/types'; | 1 | import { type AnyFunction } from '@vben/types'; |
2 | -import { nextTick, onMounted, onActivated } from 'vue'; | 2 | +import { nextTick, onActivated, onMounted } from 'vue'; |
3 | 3 | ||
4 | /** | 4 | /** |
5 | * 在 OnMounted 或者 OnActivated 时触发 | 5 | * 在 OnMounted 或者 OnActivated 时触发 |
packages/hooks/src/useAttrs.ts
1 | -import { getCurrentInstance, reactive, shallowRef, watchEffect } from 'vue'; | ||
2 | import { type Recordable } from '@vben/types'; | 1 | import { type Recordable } from '@vben/types'; |
2 | +import { getCurrentInstance, reactive, shallowRef, watchEffect } from 'vue'; | ||
3 | 3 | ||
4 | interface Options { | 4 | interface Options { |
5 | excludeListeners?: boolean; | 5 | excludeListeners?: boolean; |
packages/hooks/src/useRefs.ts
1 | import type { Ref } from 'vue'; | 1 | import type { Ref } from 'vue'; |
2 | -import { ref, onBeforeUpdate } from 'vue'; | 2 | +import { onBeforeUpdate, ref } from 'vue'; |
3 | 3 | ||
4 | export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] { | 4 | export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] { |
5 | const refs = ref([]) as Ref<HTMLElement[]>; | 5 | const refs = ref([]) as Ref<HTMLElement[]>; |
packages/types/.eslintrc.js
packages/types/src/utils.ts
@@ -31,9 +31,9 @@ type Recordable<T> = Record<string, T>; | @@ -31,9 +31,9 @@ type Recordable<T> = Record<string, T>; | ||
31 | /** | 31 | /** |
32 | * 字符串类型对象(只读) | 32 | * 字符串类型对象(只读) |
33 | */ | 33 | */ |
34 | -type ReadonlyRecordable<T = any> = { | 34 | +interface ReadonlyRecordable<T = any> { |
35 | readonly [key: string]: T; | 35 | readonly [key: string]: T; |
36 | -}; | 36 | +} |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * setTimeout 返回值类型 | 39 | * setTimeout 返回值类型 |
@@ -47,12 +47,12 @@ type IntervalHandle = ReturnType<typeof setInterval>; | @@ -47,12 +47,12 @@ type IntervalHandle = ReturnType<typeof setInterval>; | ||
47 | 47 | ||
48 | export { | 48 | export { |
49 | type AnyFunction, | 49 | type AnyFunction, |
50 | - type AnyPromiseFunction, | ||
51 | type AnyNormalFunction, | 50 | type AnyNormalFunction, |
52 | - type Nullable, | 51 | + type AnyPromiseFunction, |
52 | + type IntervalHandle, | ||
53 | type NonNullable, | 53 | type NonNullable, |
54 | - type Recordable, | 54 | + type Nullable, |
55 | type ReadonlyRecordable, | 55 | type ReadonlyRecordable, |
56 | + type Recordable, | ||
56 | type TimeoutHandle, | 57 | type TimeoutHandle, |
57 | - type IntervalHandle, | ||
58 | }; | 58 | }; |