Commit 6890dd720135b52e2d810fd85ae44062bec0c661

Authored by vben
1 parent 762e5dee

perf: 新包使用更严格的eslint

internal/eslint-config/.eslintrc.js
1 1 module.exports = {
2 2 root: true,
3   - extends: ['@vben'],
  3 + extends: ['@vben/eslint-config/strict'],
4 4 };
... ...
internal/eslint-config/src/strict.ts
1   -import baseLintConfig from './index';
2   -
3 1 export default {
4   - extends: [baseLintConfig],
  2 + extends: ['@vben'],
5 3 plugins: ['simple-import-sort'],
6 4 rules: {
7 5 'simple-import-sort/imports': 'error',
8 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 54 'vue/attributes-order': 'error',
16 55 'vue/require-default-prop': 'error',
... ...
internal/stylelint-config/.eslintrc.js
1 1 module.exports = {
2 2 root: true,
3   - extends: ['@vben'],
  3 + extends: ['@vben/eslint-config/strict'],
4 4 };
... ...
internal/vite-config/.eslintrc.js
1 1 module.exports = {
2 2 root: true,
3   - extends: ['@vben'],
  3 + extends: ['@vben/eslint-config/strict'],
4 4 };
... ...
internal/vite-config/src/config/application.ts
1   -import { type UserConfig, defineConfig, mergeConfig, loadEnv } from 'vite';
2 1 import { resolve } from 'node:path';
  2 +
  3 +import dayjs from 'dayjs';
3 4 import { readPackageJSON } from 'pkg-types';
  5 +import { defineConfig, loadEnv, mergeConfig, type UserConfig } from 'vite';
  6 +
  7 +import { createPlugins } from '../plugins';
4 8 import { generateModifyVars } from '../utils/modifyVars';
5 9 import { commonConfig } from './common';
6   -import { createPlugins } from '../plugins';
7   -import dayjs from 'dayjs';
8 10  
9 11 interface DefineOptions {
10 12 overrides?: UserConfig;
11   - options?: {};
  13 + options?: {
  14 + //
  15 + };
12 16 }
13 17  
14 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 1 import { presetTypography, presetUno } from 'unocss';
  2 +import UnoCSS from 'unocss/vite';
  3 +import { type UserConfig } from 'vite';
4 4  
5 5 const commonConfig: UserConfig = {
6 6 server: {
... ...
internal/vite-config/src/config/package.ts
1   -import { type UserConfig, defineConfig, mergeConfig } from 'vite';
2 1 import { readPackageJSON } from 'pkg-types';
3   -import { commonConfig } from './common';
  2 +import { defineConfig, mergeConfig, type UserConfig } from 'vite';
4 3 import dts from 'vite-plugin-dts';
5 4  
  5 +import { commonConfig } from './common';
  6 +
6 7 interface DefineOptions {
7 8 overrides?: UserConfig;
8   - options?: {};
  9 + options?: {
  10 + //
  11 + };
9 12 }
10 13  
11 14 function definePackageConfig(defineOptions: DefineOptions = {}) {
... ...
internal/vite-config/src/plugins/appConfig.ts
  1 +import colors from 'picocolors';
  2 +import { readPackageJSON } from 'pkg-types';
1 3 import { type PluginOption } from 'vite';
  4 +
2 5 import { getEnvConfig } from '../utils/env';
3 6 import { createContentHash } from '../utils/hash';
4   -import { readPackageJSON } from 'pkg-types';
5   -import colors from 'picocolors';
6 7  
7 8 const GLOBAL_CONFIG_FILE_NAME = '_app.config.js';
8 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 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 10 import { configHtmlPlugin } from './html';
3 11 import { configMockPlugin } from './mock';
4   -import { configCompressPlugin } from './compress';
5   -import { configVisualizerConfig } from './visualizer';
6 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 15 interface Options {
15 16 isBuild: boolean;
... ...
internal/vite-config/src/plugins/svgSprite.ts
... ... @@ -3,9 +3,10 @@
3 3 * https://github.com/anncwb/vite-plugin-svg-icons
4 4 */
5 5  
6   -import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
7 6 import { resolve } from 'node:path';
  7 +
8 8 import type { PluginOption } from 'vite';
  9 +import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
9 10  
10 11 export function configSvgIconsPlugin({ isBuild }: { isBuild: boolean }) {
11 12 const svgIconsPlugin = createSvgIconsPlugin({
... ...
internal/vite-config/src/plugins/visualizer.ts
1 1 /**
2 2 * Package file volume analysis
3 3 */
4   -import { type PluginOption } from 'vite';
5 4 import visualizer from 'rollup-plugin-visualizer';
  5 +import { type PluginOption } from 'vite';
6 6  
7 7 export function configVisualizerConfig() {
8 8 return visualizer({
... ...
internal/vite-config/src/utils/env.ts
  1 +import { join } from 'node:path';
  2 +
1 3 import dotenv from 'dotenv';
2 4 import { readFile } from 'fs-extra';
3   -import { join } from 'node:path';
4 5  
5 6 /**
6 7 * 获取当前环境下生效的配置文件名
... ...
internal/vite-config/src/utils/modifyVars.ts
1   -import { generate } from '@ant-design/colors';
2 1 import { resolve } from 'node:path';
3   -// @ts-ignore
  2 +
  3 +import { generate } from '@ant-design/colors';
  4 +// @ts-ignore: typo
4 5 import { getThemeVariables } from 'ant-design-vue/dist/theme';
5 6  
6 7 const primaryColor = '#0960bd';
... ...
packages/hooks/.eslintrc.js
1 1 module.exports = {
2 2 root: true,
3   - extends: ['@vben'],
  3 + extends: ['@vben/eslint-config/strict'],
4 4 };
... ...
packages/hooks/src/index.ts
1 1 export * from './onMountedOrActivated';
2 2 export * from './useAttrs';
3 3 export * from './useRefs';
4   -
5 4 export { useTimeoutFn } from '@vueuse/core';
... ...
packages/hooks/src/onMountedOrActivated.ts
1 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 5 * 在 OnMounted 或者 OnActivated 时触发
... ...
packages/hooks/src/useAttrs.ts
1   -import { getCurrentInstance, reactive, shallowRef, watchEffect } from 'vue';
2 1 import { type Recordable } from '@vben/types';
  2 +import { getCurrentInstance, reactive, shallowRef, watchEffect } from 'vue';
3 3  
4 4 interface Options {
5 5 excludeListeners?: boolean;
... ...
packages/hooks/src/useRefs.ts
1 1 import type { Ref } from 'vue';
2   -import { ref, onBeforeUpdate } from 'vue';
  2 +import { onBeforeUpdate, ref } from 'vue';
3 3  
4 4 export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] {
5 5 const refs = ref([]) as Ref<HTMLElement[]>;
... ...
packages/types/.eslintrc.js
1 1 module.exports = {
2 2 root: true,
3   - extends: ['@vben'],
  3 + extends: ['@vben/eslint-config/strict'],
4 4 };
... ...
packages/types/src/utils.ts
... ... @@ -31,9 +31,9 @@ type Recordable&lt;T&gt; = Record&lt;string, T&gt;;
31 31 /**
32 32 * 字符串类型对象(只读)
33 33 */
34   -type ReadonlyRecordable<T = any> = {
  34 +interface ReadonlyRecordable<T = any> {
35 35 readonly [key: string]: T;
36   -};
  36 +}
37 37  
38 38 /**
39 39 * setTimeout 返回值类型
... ... @@ -47,12 +47,12 @@ type IntervalHandle = ReturnType&lt;typeof setInterval&gt;;
47 47  
48 48 export {
49 49 type AnyFunction,
50   - type AnyPromiseFunction,
51 50 type AnyNormalFunction,
52   - type Nullable,
  51 + type AnyPromiseFunction,
  52 + type IntervalHandle,
53 53 type NonNullable,
54   - type Recordable,
  54 + type Nullable,
55 55 type ReadonlyRecordable,
  56 + type Recordable,
56 57 type TimeoutHandle,
57   - type IntervalHandle,
58 58 };
... ...