perf: 新包使用更严格的eslint

This commit is contained in:
vben
2023-04-06 23:28:37 +08:00
parent 762e5dee14
commit 6890dd7201
20 changed files with 99 additions and 49 deletions

View File

@@ -1,4 +1,4 @@
module.exports = { module.exports = {
root: true, root: true,
extends: ['@vben'], extends: ['@vben/eslint-config/strict'],
}; };

View File

@@ -1,16 +1,55 @@
import baseLintConfig from './index';
export default { export default {
extends: [baseLintConfig], extends: ['@vben'],
plugins: ['simple-import-sort'], plugins: ['simple-import-sort'],
rules: { rules: {
'simple-import-sort/imports': 'error', 'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error', 'simple-import-sort/exports': 'error',
'@typescript-eslint/ban-types': 'error', '@typescript-eslint/ban-ts-comment': [
'@typescript-eslint/ban-ts-ignore': 'error', 'error',
'@typescript-eslint/ban-ts-comment': 'error', {
'@typescript-eslint/no-explicit-any': 'error', 'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': 'allow-with-description',
'ts-check': false,
},
],
/**
* 【强制】关键字前后有一个空格
* @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/keyword-spacing.md
*/
'keyword-spacing': 'off',
'@typescript-eslint/keyword-spacing': [
'error',
{
before: true,
after: true,
overrides: {
return: { after: true },
throw: { after: true },
case: { after: true },
},
},
],
/**
* 禁止出现空函数,普通函数(非 async/await/generator、箭头函数、类上的方法除外
* @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md
*/
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': [
'error',
{
allow: ['arrowFunctions', 'functions', 'methods'],
},
],
/**
* 优先使用 interface 而不是 type 定义对象类型
* @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
*/
'@typescript-eslint/consistent-type-definitions': ['warn', 'interface'],
'vue/attributes-order': 'error', 'vue/attributes-order': 'error',
'vue/require-default-prop': 'error', 'vue/require-default-prop': 'error',

View File

@@ -1,4 +1,4 @@
module.exports = { module.exports = {
root: true, root: true,
extends: ['@vben'], extends: ['@vben/eslint-config/strict'],
}; };

View File

@@ -1,4 +1,4 @@
module.exports = { module.exports = {
root: true, root: true,
extends: ['@vben'], extends: ['@vben/eslint-config/strict'],
}; };

View File

@@ -1,14 +1,18 @@
import { type UserConfig, defineConfig, mergeConfig, loadEnv } from 'vite';
import { resolve } from 'node:path'; import { resolve } from 'node:path';
import dayjs from 'dayjs';
import { readPackageJSON } from 'pkg-types'; import { readPackageJSON } from 'pkg-types';
import { defineConfig, loadEnv, mergeConfig, type UserConfig } from 'vite';
import { createPlugins } from '../plugins';
import { generateModifyVars } from '../utils/modifyVars'; import { generateModifyVars } from '../utils/modifyVars';
import { commonConfig } from './common'; import { commonConfig } from './common';
import { createPlugins } from '../plugins';
import dayjs from 'dayjs';
interface DefineOptions { interface DefineOptions {
overrides?: UserConfig; overrides?: UserConfig;
options?: {}; options?: {
//
};
} }
function defineApplicationConfig(defineOptions: DefineOptions = {}) { function defineApplicationConfig(defineOptions: DefineOptions = {}) {

View File

@@ -1,6 +1,6 @@
import { type UserConfig } from 'vite';
import UnoCSS from 'unocss/vite';
import { presetTypography, presetUno } from 'unocss'; import { presetTypography, presetUno } from 'unocss';
import UnoCSS from 'unocss/vite';
import { type UserConfig } from 'vite';
const commonConfig: UserConfig = { const commonConfig: UserConfig = {
server: { server: {

View File

@@ -1,11 +1,14 @@
import { type UserConfig, defineConfig, mergeConfig } from 'vite';
import { readPackageJSON } from 'pkg-types'; import { readPackageJSON } from 'pkg-types';
import { commonConfig } from './common'; import { defineConfig, mergeConfig, type UserConfig } from 'vite';
import dts from 'vite-plugin-dts'; import dts from 'vite-plugin-dts';
import { commonConfig } from './common';
interface DefineOptions { interface DefineOptions {
overrides?: UserConfig; overrides?: UserConfig;
options?: {}; options?: {
//
};
} }
function definePackageConfig(defineOptions: DefineOptions = {}) { function definePackageConfig(defineOptions: DefineOptions = {}) {

View File

@@ -1,8 +1,9 @@
import colors from 'picocolors';
import { readPackageJSON } from 'pkg-types';
import { type PluginOption } from 'vite'; import { type PluginOption } from 'vite';
import { getEnvConfig } from '../utils/env'; import { getEnvConfig } from '../utils/env';
import { createContentHash } from '../utils/hash'; import { createContentHash } from '../utils/hash';
import { readPackageJSON } from 'pkg-types';
import colors from 'picocolors';
const GLOBAL_CONFIG_FILE_NAME = '_app.config.js'; const GLOBAL_CONFIG_FILE_NAME = '_app.config.js';
const PLUGIN_NAME = 'app-config'; const PLUGIN_NAME = 'app-config';

View File

@@ -1,15 +1,16 @@
import { type PluginOption } from 'vite';
import { configHtmlPlugin } from './html';
import { configMockPlugin } from './mock';
import { configCompressPlugin } from './compress';
import { configVisualizerConfig } from './visualizer';
import { configSvgIconsPlugin } from './svgSprite';
import { createAppConfigPlugin } from './appConfig';
import vue from '@vitejs/plugin-vue'; import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx'; import vueJsx from '@vitejs/plugin-vue-jsx';
import purgeIcons from 'vite-plugin-purge-icons'; // @ts-ignore: type unless
// @ts-ignore
import DefineOptions from 'unplugin-vue-define-options/vite'; import DefineOptions from 'unplugin-vue-define-options/vite';
import { type PluginOption } from 'vite';
import purgeIcons from 'vite-plugin-purge-icons';
import { createAppConfigPlugin } from './appConfig';
import { configCompressPlugin } from './compress';
import { configHtmlPlugin } from './html';
import { configMockPlugin } from './mock';
import { configSvgIconsPlugin } from './svgSprite';
import { configVisualizerConfig } from './visualizer';
interface Options { interface Options {
isBuild: boolean; isBuild: boolean;

View File

@@ -3,9 +3,10 @@
* https://github.com/anncwb/vite-plugin-svg-icons * https://github.com/anncwb/vite-plugin-svg-icons
*/ */
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { resolve } from 'node:path'; import { resolve } from 'node:path';
import type { PluginOption } from 'vite'; import type { PluginOption } from 'vite';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
export function configSvgIconsPlugin({ isBuild }: { isBuild: boolean }) { export function configSvgIconsPlugin({ isBuild }: { isBuild: boolean }) {
const svgIconsPlugin = createSvgIconsPlugin({ const svgIconsPlugin = createSvgIconsPlugin({

View File

@@ -1,8 +1,8 @@
/** /**
* Package file volume analysis * Package file volume analysis
*/ */
import { type PluginOption } from 'vite';
import visualizer from 'rollup-plugin-visualizer'; import visualizer from 'rollup-plugin-visualizer';
import { type PluginOption } from 'vite';
export function configVisualizerConfig() { export function configVisualizerConfig() {
return visualizer({ return visualizer({

View File

@@ -1,6 +1,7 @@
import { join } from 'node:path';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import { readFile } from 'fs-extra'; import { readFile } from 'fs-extra';
import { join } from 'node:path';
/** /**
* 获取当前环境下生效的配置文件名 * 获取当前环境下生效的配置文件名

View File

@@ -1,6 +1,7 @@
import { generate } from '@ant-design/colors';
import { resolve } from 'node:path'; import { resolve } from 'node:path';
// @ts-ignore
import { generate } from '@ant-design/colors';
// @ts-ignore: typo
import { getThemeVariables } from 'ant-design-vue/dist/theme'; import { getThemeVariables } from 'ant-design-vue/dist/theme';
const primaryColor = '#0960bd'; const primaryColor = '#0960bd';

View File

@@ -1,4 +1,4 @@
module.exports = { module.exports = {
root: true, root: true,
extends: ['@vben'], extends: ['@vben/eslint-config/strict'],
}; };

View File

@@ -1,5 +1,4 @@
export * from './onMountedOrActivated'; export * from './onMountedOrActivated';
export * from './useAttrs'; export * from './useAttrs';
export * from './useRefs'; export * from './useRefs';
export { useTimeoutFn } from '@vueuse/core'; export { useTimeoutFn } from '@vueuse/core';

View File

@@ -1,5 +1,5 @@
import { type AnyFunction } from '@vben/types'; import { type AnyFunction } from '@vben/types';
import { nextTick, onMounted, onActivated } from 'vue'; import { nextTick, onActivated, onMounted } from 'vue';
/** /**
* 在 OnMounted 或者 OnActivated 时触发 * 在 OnMounted 或者 OnActivated 时触发

View File

@@ -1,5 +1,5 @@
import { getCurrentInstance, reactive, shallowRef, watchEffect } from 'vue';
import { type Recordable } from '@vben/types'; import { type Recordable } from '@vben/types';
import { getCurrentInstance, reactive, shallowRef, watchEffect } from 'vue';
interface Options { interface Options {
excludeListeners?: boolean; excludeListeners?: boolean;

View File

@@ -1,5 +1,5 @@
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { ref, onBeforeUpdate } from 'vue'; import { onBeforeUpdate, ref } from 'vue';
export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] { export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] {
const refs = ref([]) as Ref<HTMLElement[]>; const refs = ref([]) as Ref<HTMLElement[]>;

View File

@@ -1,4 +1,4 @@
module.exports = { module.exports = {
root: true, root: true,
extends: ['@vben'], extends: ['@vben/eslint-config/strict'],
}; };

View File

@@ -31,9 +31,9 @@ type Recordable<T> = Record<string, T>;
/** /**
* 字符串类型对象(只读) * 字符串类型对象(只读)
*/ */
type ReadonlyRecordable<T = any> = { interface ReadonlyRecordable<T = any> {
readonly [key: string]: T; readonly [key: string]: T;
}; }
/** /**
* setTimeout 返回值类型 * setTimeout 返回值类型
@@ -47,12 +47,12 @@ type IntervalHandle = ReturnType<typeof setInterval>;
export { export {
type AnyFunction, type AnyFunction,
type AnyPromiseFunction,
type AnyNormalFunction, type AnyNormalFunction,
type Nullable, type AnyPromiseFunction,
type NonNullable,
type Recordable,
type ReadonlyRecordable,
type TimeoutHandle,
type IntervalHandle, type IntervalHandle,
type NonNullable,
type Nullable,
type ReadonlyRecordable,
type Recordable,
type TimeoutHandle,
}; };