diff --git a/.eslintrc.js b/.eslintrc.js index 46239631..f25357b3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,6 +32,8 @@ module.exports = { es6: true, }, rules: { + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', 'accessor-pairs': 'off', 'brace-style': ['error', '1tbs'], 'func-style': ['warn', 'declaration', { allowArrowFunctions: true }], diff --git a/libs/horizon/src/renderer/TreeBuilder.ts b/libs/horizon/src/renderer/TreeBuilder.ts index 721bbff6..ec86db16 100644 --- a/libs/horizon/src/renderer/TreeBuilder.ts +++ b/libs/horizon/src/renderer/TreeBuilder.ts @@ -165,7 +165,7 @@ function getChildByIndex(vNode: VNode, idx: number) { // 从多个更新节点中,计算出开始节点。即:找到最近的共同的父辈节点 export function calcStartUpdateVNode(treeRoot: VNode) { - const toUpdateNodes = Array.from(treeRoot.toUpdateNodes); + const toUpdateNodes = [...treeRoot.toUpdateNodes]; if (toUpdateNodes.length === 0) { return treeRoot; diff --git a/libs/horizon/src/renderer/hooks/BaseHook.ts b/libs/horizon/src/renderer/hooks/BaseHook.ts index 8c3f3605..54e180c8 100644 --- a/libs/horizon/src/renderer/hooks/BaseHook.ts +++ b/libs/horizon/src/renderer/hooks/BaseHook.ts @@ -1,7 +1,7 @@ import type { VNode } from '../Types'; import type { Hook } from './HookType'; -let processingVNode: VNode = null; +let processingVNode: VNode | null = null; // lastTimeHook是上一次执行func时产生的hooks中,与currentHook对应的hook let lastTimeHook: Hook | null = null; @@ -13,7 +13,7 @@ export function getProcessingVNode() { return processingVNode; } -export function setProcessingVNode(vNode: VNode) { +export function setProcessingVNode(vNode: VNode | null) { processingVNode = vNode; } @@ -21,11 +21,11 @@ export function getLastTimeHook() { return lastTimeHook; } -export function setLastTimeHook(hook: Hook) { +export function setLastTimeHook(hook: Hook | null) { lastTimeHook = hook; } -export function setCurrentHook(hook: Hook) { +export function setCurrentHook(hook: Hook | null) { currentHook = hook; } diff --git a/libs/horizon/src/renderer/hooks/HookMain.ts b/libs/horizon/src/renderer/hooks/HookMain.ts index e8992e5a..f4c568ea 100644 --- a/libs/horizon/src/renderer/hooks/HookMain.ts +++ b/libs/horizon/src/renderer/hooks/HookMain.ts @@ -15,17 +15,17 @@ import { setProcessingVNode, setCurrentHook, getNextHook } from './BaseHook'; -import {useStateImpl,} from './UseStateHook'; -import {useReducerImpl,} from './UseReducerHook'; +import {useStateImpl} from './UseStateHook'; +import {useReducerImpl} from './UseReducerHook'; import {HookStage, setHookStage} from './HookStage'; // hook对外入口 -export function exeFunctionHook( - funcComp: (props: Object, arg: Object) => any, - props: Object, - arg: Object, +export function exeFunctionHook, Arg>( + funcComp: (props: Props, arg: Arg) => any, + props: Props, + arg: Arg, processing: VNode, -): any { +) { // 重置全局变量 resetGlobalVariable(); @@ -39,13 +39,13 @@ export function exeFunctionHook( processing.effectList = []; // 设置hook阶段 - if (processing.isCreated || !processing.oldHooks.length) { + if (processing.isCreated || !processing.oldHooks!.length) { setHookStage(HookStage.Init); } else { setHookStage(HookStage.Update); } - let comp = funcComp(props, arg); + const comp = funcComp(props, arg); // 设置hook阶段为null,用于判断hook是否在函数组件中调用 setHookStage(null); diff --git a/libs/horizon/src/renderer/hooks/HookStage.ts b/libs/horizon/src/renderer/hooks/HookStage.ts index c3e9622a..4819554d 100644 --- a/libs/horizon/src/renderer/hooks/HookStage.ts +++ b/libs/horizon/src/renderer/hooks/HookStage.ts @@ -10,6 +10,6 @@ export function getHookStage() { return hookStage; } -export function setHookStage(phase: HookStage) { +export function setHookStage(phase: HookStage| null) { hookStage = phase; } diff --git a/package.json b/package.json index d3da90aa..5ef9d520 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "libs/*" ], "scripts": { + "lint": "eslint . --ext .ts", "build": " webpack --config ./scripts/webpack/webpack.config.js", "build-3rdLib": "node ./scripts/gen3rdLib.js", "build-3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js --dev",