Browse Source

perf: 新包使用更严格的eslint

pull/2688/head
vben 3 years ago
parent
commit
6890dd7201
  1. 2
      internal/eslint-config/.eslintrc.js
  2. 53
      internal/eslint-config/src/strict.ts
  3. 2
      internal/stylelint-config/.eslintrc.js
  4. 2
      internal/vite-config/.eslintrc.js
  5. 12
      internal/vite-config/src/config/application.ts
  6. 4
      internal/vite-config/src/config/common.ts
  7. 9
      internal/vite-config/src/config/package.ts
  8. 5
      internal/vite-config/src/plugins/appConfig.ts
  9. 17
      internal/vite-config/src/plugins/index.ts
  10. 3
      internal/vite-config/src/plugins/svgSprite.ts
  11. 2
      internal/vite-config/src/plugins/visualizer.ts
  12. 3
      internal/vite-config/src/utils/env.ts
  13. 5
      internal/vite-config/src/utils/modifyVars.ts
  14. 2
      packages/hooks/.eslintrc.js
  15. 1
      packages/hooks/src/index.ts
  16. 2
      packages/hooks/src/onMountedOrActivated.ts
  17. 2
      packages/hooks/src/useAttrs.ts
  18. 2
      packages/hooks/src/useRefs.ts
  19. 2
      packages/types/.eslintrc.js
  20. 12
      packages/types/src/utils.ts

2
internal/eslint-config/.eslintrc.js

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

53
internal/eslint-config/src/strict.ts

@ -1,16 +1,55 @@
import baseLintConfig from './index';
export default {
extends: [baseLintConfig],
extends: ['@vben'],
plugins: ['simple-import-sort'],
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'@typescript-eslint/ban-types': 'error',
'@typescript-eslint/ban-ts-ignore': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/ban-ts-comment': [
'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/require-default-prop': 'error',

2
internal/stylelint-config/.eslintrc.js

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

2
internal/vite-config/.eslintrc.js

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

12
internal/vite-config/src/config/application.ts

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

4
internal/vite-config/src/config/common.ts

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

9
internal/vite-config/src/config/package.ts

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

5
internal/vite-config/src/plugins/appConfig.ts

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

17
internal/vite-config/src/plugins/index.ts

@ -1,15 +1,16 @@
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
// @ts-ignore: type unless
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 { configCompressPlugin } from './compress';
import { configVisualizerConfig } from './visualizer';
import { configSvgIconsPlugin } from './svgSprite';
import { createAppConfigPlugin } from './appConfig';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import purgeIcons from 'vite-plugin-purge-icons';
// @ts-ignore
import DefineOptions from 'unplugin-vue-define-options/vite';
import { configVisualizerConfig } from './visualizer';
interface Options {
isBuild: boolean;

3
internal/vite-config/src/plugins/svgSprite.ts

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

2
internal/vite-config/src/plugins/visualizer.ts

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

3
internal/vite-config/src/utils/env.ts

@ -1,6 +1,7 @@
import { join } from 'node:path';
import dotenv from 'dotenv';
import { readFile } from 'fs-extra';
import { join } from 'node:path';
/**
*

5
internal/vite-config/src/utils/modifyVars.ts

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

2
packages/hooks/.eslintrc.js

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

1
packages/hooks/src/index.ts

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

2
packages/hooks/src/onMountedOrActivated.ts

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

2
packages/hooks/src/useAttrs.ts

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

2
packages/hooks/src/useRefs.ts

@ -1,5 +1,5 @@
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] {
const refs = ref([]) as Ref<HTMLElement[]>;

2
packages/types/.eslintrc.js

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

12
packages/types/src/utils.ts

@ -31,9 +31,9 @@ type Recordable<T> = Record<string, T>;
/**
*
*/
type ReadonlyRecordable<T = any> = {
interface ReadonlyRecordable<T = any> {
readonly [key: string]: T;
};
}
/**
* setTimeout
@ -47,12 +47,12 @@ type IntervalHandle = ReturnType<typeof setInterval>;
export {
type AnyFunction,
type AnyPromiseFunction,
type AnyNormalFunction,
type Nullable,
type AnyPromiseFunction,
type IntervalHandle,
type NonNullable,
type Recordable,
type Nullable,
type ReadonlyRecordable,
type Recordable,
type TimeoutHandle,
type IntervalHandle,
};

Loading…
Cancel
Save