From 44b641c4a7be6e43f683f40e4a84deba2a3f12f3 Mon Sep 17 00:00:00 2001 From: JeremyWuuuuu <591440570@qq.com> Date: Wed, 29 Jul 2020 15:09:29 +0800 Subject: [PATCH] fix(project):fix gc.sh generating wrong format templates fix(utils):fix utils linting issues --- packages/utils/isDef.ts | 4 ++-- packages/utils/menu/menu-item.ts | 2 +- packages/utils/menu/submenu.ts | 2 +- packages/utils/merge.ts | 7 ------- packages/utils/resize-event.ts | 10 +++++----- packages/utils/scroll-into-view.ts | 2 +- packages/utils/scrollbar-width.ts | 2 +- packages/utils/tests/aria.test.ts | 2 +- packages/utils/util.ts | 4 +++- scripts/gc.sh | 24 +++++++++++++----------- 10 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 packages/utils/merge.ts diff --git a/packages/utils/isDef.ts b/packages/utils/isDef.ts index 38fca34c72..a1ca8a624a 100644 --- a/packages/utils/isDef.ts +++ b/packages/utils/isDef.ts @@ -1,7 +1,7 @@ -export function isDef(val) { +export function isDef(val: unknown): boolean { return val !== undefined && val !== null } -export function isKorean(text: string) { +export function isKorean(text: string): boolean { const reg = /([(\uAC00-\uD7AF)|(\u3130-\u318F)])+/gi return reg.test(text) } diff --git a/packages/utils/menu/menu-item.ts b/packages/utils/menu/menu-item.ts index f853870642..0da5e990e8 100644 --- a/packages/utils/menu/menu-item.ts +++ b/packages/utils/menu/menu-item.ts @@ -1,4 +1,4 @@ -import {eventKeys, triggerEvent} from '../aria' +import { eventKeys, triggerEvent } from '../aria' import SubMenu from './submenu' diff --git a/packages/utils/menu/submenu.ts b/packages/utils/menu/submenu.ts index c0731c3a7f..e2f97ffdcf 100644 --- a/packages/utils/menu/submenu.ts +++ b/packages/utils/menu/submenu.ts @@ -1,4 +1,4 @@ -import {eventKeys, triggerEvent } from '../aria' +import { eventKeys, triggerEvent } from '../aria' import MenuItem from './menu-item' class SubMenu { diff --git a/packages/utils/merge.ts b/packages/utils/merge.ts deleted file mode 100644 index 4b9b296b8d..0000000000 --- a/packages/utils/merge.ts +++ /dev/null @@ -1,7 +0,0 @@ -export default function(target: Object, ...args: Array) { - target = { ...target } - for (let i = 0; i < args.length; i++) { - Object.assign(target, args[i]) - } - return target -} diff --git a/packages/utils/resize-event.ts b/packages/utils/resize-event.ts index 67be84c024..a3b4197fe5 100644 --- a/packages/utils/resize-event.ts +++ b/packages/utils/resize-event.ts @@ -2,7 +2,7 @@ import ResizeObserver from 'resize-observer-polyfill' import isServer from './isServer' type ResizableElement = CustomizedHTMLElement<{ - __resizeListeners__: Array; + __resizeListeners__: Array<(...args: unknown[]) => unknown>; __ro__: ResizeObserver; }>; @@ -22,8 +22,8 @@ const resizeHandler = function(entries: ResizeObserverEntry[]) { /* istanbul ignore next */ export const addResizeListener = function( element: ResizableElement, - fn: Function, -) { + fn: (...args: unknown[]) => unknown, +): void { if (isServer) return if (!element.__resizeListeners__) { element.__resizeListeners__ = [] @@ -36,8 +36,8 @@ export const addResizeListener = function( /* istanbul ignore next */ export const removeResizeListener = function( element: ResizableElement, - fn: Function, -) { + fn: (...args: unknown[]) => unknown, +): void { if (!element || !element.__resizeListeners__) return element.__resizeListeners__.splice( element.__resizeListeners__.indexOf(fn), diff --git a/packages/utils/scroll-into-view.ts b/packages/utils/scroll-into-view.ts index 0d7b93c2b8..4a172d8f43 100644 --- a/packages/utils/scroll-into-view.ts +++ b/packages/utils/scroll-into-view.ts @@ -3,7 +3,7 @@ import isServer from './isServer' export default function scrollIntoView( container: HTMLElement, selected: HTMLElement, -) { +): void { if (isServer) return if (!selected) { diff --git a/packages/utils/scrollbar-width.ts b/packages/utils/scrollbar-width.ts index 634bf7ba76..c89d2d46b7 100644 --- a/packages/utils/scrollbar-width.ts +++ b/packages/utils/scrollbar-width.ts @@ -2,7 +2,7 @@ import isServer from './isServer' let scrollBarWidth: number -export default function() { +export default function(): number { if (isServer) return 0 if (scrollBarWidth !== undefined) return scrollBarWidth diff --git a/packages/utils/tests/aria.test.ts b/packages/utils/tests/aria.test.ts index 695587255a..9af1e9938a 100644 --- a/packages/utils/tests/aria.test.ts +++ b/packages/utils/tests/aria.test.ts @@ -1,4 +1,4 @@ -import Utils, {triggerEvent, isFocusable, attemptFocus} from '../aria' +import { triggerEvent, isFocusable } from '../aria' const CE = (tag: string) => document.createElement(tag) diff --git a/packages/utils/util.ts b/packages/utils/util.ts index 081c495193..0077a3c12e 100644 --- a/packages/utils/util.ts +++ b/packages/utils/util.ts @@ -132,7 +132,7 @@ export { capitalize, } -export function rafThrottle(fn: (args: Record) => unknown): (...args: any[]) => any { +export function rafThrottle(fn: (args: Record) => unknown): (...args: unknown[]) => unknown { let locked = false return function(...args) { if (locked) return @@ -145,3 +145,5 @@ export function rafThrottle(fn: (args: Record) => unknown): (.. } export const objToArray = castArray + +export { isVNode } from 'vue' diff --git a/scripts/gc.sh b/scripts/gc.sh index 2bbb4839be..9b2eceaf1d 100755 --- a/scripts/gc.sh +++ b/scripts/gc.sh @@ -33,16 +33,18 @@ mkdir -p "$DIRNAME/__tests__" cat > $DIRNAME/src/index.vue <
- +
@@ -51,7 +53,7 @@ EOF cat <"$DIRNAME/index.ts" import { App } from 'vue' import ${NAME} from './src/index.vue' -export default (app: App) => { +export default (app: App): void => { app.component(${NAME}.name, ${NAME}) } EOF @@ -72,7 +74,7 @@ cat > $DIRNAME/package.json < $DIRNAME/__tests__/$INPUT_NAME.spec.ts < { test('render test', () => { const wrapper = mount($NAME, { slots: { - default: AXIOM + default: AXIOM, }, }) expect(wrapper.text()).toEqual(AXIOM) @@ -93,7 +95,7 @@ cat <"$DIRNAME/doc/index.stories.ts" import El${NAME} from '../index' export default { - title: "${NAME}" + title: '${NAME}', } EOF