From 6aa38e74c7960465db4cf4377e26abb3a205f5d9 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Mon, 12 Sep 2022 16:22:50 -0400 Subject: [PATCH] Flow: enable unsafe-addition error (#25242) --- packages/react-devtools-shared/src/devtools/store.js | 1 + .../src/devtools/views/Components/TreeContext.js | 1 + .../src/devtools/views/Profiler/SnapshotSelector.js | 5 ++++- packages/react-reconciler/src/ReactFiberCompleteWork.new.js | 3 +++ packages/react-reconciler/src/ReactFiberCompleteWork.old.js | 3 +++ packages/react-reconciler/src/ReactFiberWorkLoop.new.js | 1 + packages/react-reconciler/src/ReactFiberWorkLoop.old.js | 1 + packages/react-reconciler/src/ReactProfilerTimer.new.js | 2 ++ packages/react-reconciler/src/ReactProfilerTimer.old.js | 2 ++ scripts/flow/config/flowconfig | 4 ---- 10 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/store.js b/packages/react-devtools-shared/src/devtools/store.js index 4c9131c896785..b51597f43a528 100644 --- a/packages/react-devtools-shared/src/devtools/store.js +++ b/packages/react-devtools-shared/src/devtools/store.js @@ -681,6 +681,7 @@ export default class Store extends EventEmitter<{ let depth = 0; while (parentID > 0) { if (parentID === ownerID || unsortedIDs.has(parentID)) { + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value depth = depthMap.get(parentID) + 1; depthMap.set(id, depth); break; diff --git a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js index 1103cc0f6c830..e975bd16fab63 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js @@ -505,6 +505,7 @@ function reduceSearchState(store: Store, state: State, action: Action): State { if (numPrevSearchResults > 0) { didRequestSearch = true; searchIndex = + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value searchIndex + 1 < numPrevSearchResults ? searchIndex + 1 : 0; } break; diff --git a/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js b/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js index 1d4fd41d798a7..faf124b5c97ae 100644 --- a/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js +++ b/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js @@ -126,7 +126,10 @@ export default function SnapshotSelector(_: Props) { type="text" inputMode="numeric" pattern="[0-9]*" - value={selectedFilteredCommitIndex + 1} + value={ + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value + selectedFilteredCommitIndex + 1 + } size={`${numFilteredCommits}`.length} onChange={handleCommitInputChange} onClick={handleClick} diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.new.js b/packages/react-reconciler/src/ReactFiberCompleteWork.new.js index 135e9290f549f..592bef4fbd25d 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.new.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.new.js @@ -662,8 +662,10 @@ function bubbleProperties(completedWork: Fiber) { // this value will reflect the amount of time spent working on a previous // render. In that case it should not bubble. We determine whether it was // cloned by comparing the child pointer. + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value actualDuration += child.actualDuration; + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value treeBaseDuration += child.treeBaseDuration; child = child.sibling; } @@ -712,6 +714,7 @@ function bubbleProperties(completedWork: Fiber) { subtreeFlags |= child.subtreeFlags & StaticMask; subtreeFlags |= child.flags & StaticMask; + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value treeBaseDuration += child.treeBaseDuration; child = child.sibling; } diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.old.js b/packages/react-reconciler/src/ReactFiberCompleteWork.old.js index 3fd1bffbc3a99..f3ba7bf0799a0 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.old.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.old.js @@ -662,8 +662,10 @@ function bubbleProperties(completedWork: Fiber) { // this value will reflect the amount of time spent working on a previous // render. In that case it should not bubble. We determine whether it was // cloned by comparing the child pointer. + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value actualDuration += child.actualDuration; + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value treeBaseDuration += child.treeBaseDuration; child = child.sibling; } @@ -712,6 +714,7 @@ function bubbleProperties(completedWork: Fiber) { subtreeFlags |= child.subtreeFlags & StaticMask; subtreeFlags |= child.flags & StaticMask; + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value treeBaseDuration += child.treeBaseDuration; child = child.sibling; } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index a40b5ac480728..5e9edf7945653 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -2217,6 +2217,7 @@ function completeUnitOfWork(unitOfWork: Fiber): void { let actualDuration = completedWork.actualDuration; let child = completedWork.child; while (child !== null) { + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value actualDuration += child.actualDuration; child = child.sibling; } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 3db85b0b9b23b..d8a0bc883f4d7 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -2217,6 +2217,7 @@ function completeUnitOfWork(unitOfWork: Fiber): void { let actualDuration = completedWork.actualDuration; let child = completedWork.child; while (child !== null) { + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value actualDuration += child.actualDuration; child = child.sibling; } diff --git a/packages/react-reconciler/src/ReactProfilerTimer.new.js b/packages/react-reconciler/src/ReactProfilerTimer.new.js index a5a14eae1c244..de88e711cbf76 100644 --- a/packages/react-reconciler/src/ReactProfilerTimer.new.js +++ b/packages/react-reconciler/src/ReactProfilerTimer.new.js @@ -122,6 +122,7 @@ function stopProfilerTimerIfRunningAndRecordDelta( if (profilerStartTime >= 0) { const elapsedTime = now() - profilerStartTime; + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value fiber.actualDuration += elapsedTime; if (overrideBaseTime) { fiber.selfBaseDuration = elapsedTime; @@ -215,6 +216,7 @@ function transferActualDuration(fiber: Fiber): void { // where we should count the work of multiple passes. let child = fiber.child; while (child) { + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value fiber.actualDuration += child.actualDuration; child = child.sibling; } diff --git a/packages/react-reconciler/src/ReactProfilerTimer.old.js b/packages/react-reconciler/src/ReactProfilerTimer.old.js index a5a14eae1c244..de88e711cbf76 100644 --- a/packages/react-reconciler/src/ReactProfilerTimer.old.js +++ b/packages/react-reconciler/src/ReactProfilerTimer.old.js @@ -122,6 +122,7 @@ function stopProfilerTimerIfRunningAndRecordDelta( if (profilerStartTime >= 0) { const elapsedTime = now() - profilerStartTime; + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value fiber.actualDuration += elapsedTime; if (overrideBaseTime) { fiber.selfBaseDuration = elapsedTime; @@ -215,6 +216,7 @@ function transferActualDuration(fiber: Fiber): void { // where we should count the work of multiple passes. let child = fiber.child; while (child) { + // $FlowFixMe[unsafe-addition] addition with possible null/undefined value fiber.actualDuration += child.actualDuration; child = child.sibling; } diff --git a/scripts/flow/config/flowconfig b/scripts/flow/config/flowconfig index 30ecf58e7e67d..9b47998da9880 100644 --- a/scripts/flow/config/flowconfig +++ b/scripts/flow/config/flowconfig @@ -38,10 +38,6 @@ [lints] untyped-type-import=error -# TODO: We might want to enable this this as a error (the default), it -# disallows adding undefined and numbers. -unsafe-addition=off - [options] server.max_workers=4 esproposal.class_static_fields=enable