From 7776249f873fdbe237b0c5f7dac1d32377ddbb1f Mon Sep 17 00:00:00 2001 From: Olivier Louvignes Date: Thu, 21 Nov 2024 11:59:41 +0100 Subject: [PATCH] fix(eslint): correct eslint issues --- src/DndProvider.tsx | 3 +++ src/features/sort/components/DraggableGrid.tsx | 4 ++-- src/features/sort/components/DraggableStack.tsx | 5 ++--- src/features/sort/hooks/useDraggableSort.ts | 1 + src/hooks/useDraggable.ts | 2 ++ src/hooks/useDraggableStyle.tsx | 2 ++ src/hooks/useDroppable.ts | 2 ++ src/hooks/useDroppableStyle.tsx | 1 + src/hooks/useNodeRef.ts | 1 + src/types/common.ts | 1 - src/utils/assert.ts | 2 +- src/utils/reanimated.ts | 1 + test/DndProvider.spec.tsx | 2 +- test/setup.ts | 6 +++++- 14 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/DndProvider.tsx b/src/DndProvider.tsx index 708104e..8011f41 100644 --- a/src/DndProvider.tsx +++ b/src/DndProvider.tsx @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions */ + import React, { forwardRef, PropsWithChildren, useImperativeHandle, useMemo, useRef } from "react"; import { LayoutRectangle, StyleProp, View, ViewStyle } from "react-native"; import { @@ -369,6 +371,7 @@ export const DndProvider = forwardRef Children.map(children, (child) => { if (React.isValidElement(child)) { - return child.props.id; + return (child.props as { id?: UniqueIdentifier }).id; } return null; - })?.filter(Boolean) as UniqueIdentifier[], + })?.filter(Boolean), [children], ); diff --git a/src/features/sort/components/DraggableStack.tsx b/src/features/sort/components/DraggableStack.tsx index e92729b..5c05759 100644 --- a/src/features/sort/components/DraggableStack.tsx +++ b/src/features/sort/components/DraggableStack.tsx @@ -21,12 +21,11 @@ export const DraggableStack: FunctionComponent Children.map(children, (child) => { - // console.log("in"); if (React.isValidElement(child)) { - return child.props.id; + return (child.props as { id?: UniqueIdentifier }).id; } return null; - })?.filter(Boolean) as UniqueIdentifier[], + })?.filter(Boolean), [children], ); diff --git a/src/features/sort/hooks/useDraggableSort.ts b/src/features/sort/hooks/useDraggableSort.ts index 5413dd6..e4c2c47 100644 --- a/src/features/sort/hooks/useDraggableSort.ts +++ b/src/features/sort/hooks/useDraggableSort.ts @@ -55,6 +55,7 @@ export const useDraggableSort = ({ if (itemId === activeId) { continue; } + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!layouts[itemId]) { console.warn(`Unexpected missing layout ${itemId} in layouts!`); continue; diff --git a/src/hooks/useDraggable.ts b/src/hooks/useDraggable.ts index 63758b5..b34b034 100644 --- a/src/hooks/useDraggable.ts +++ b/src/hooks/useDraggable.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-dynamic-delete */ + import { useLayoutEffect } from "react"; import { LayoutRectangle, ViewProps } from "react-native"; import { runOnUI, useSharedValue } from "react-native-reanimated"; diff --git a/src/hooks/useDraggableStyle.tsx b/src/hooks/useDraggableStyle.tsx index 9f4fbfd..8910b78 100644 --- a/src/hooks/useDraggableStyle.tsx +++ b/src/hooks/useDraggableStyle.tsx @@ -16,7 +16,9 @@ export const useDraggableStyle = ( const state = states.value[id]; return useAnimatedStyle(() => { const isActive = activeId.value === id; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition const isActing = state?.value === "acting"; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition const isDisabled = !options.value[id]?.disabled; return callback({ isActive, isActing, isDisabled }); }, [id, state]); diff --git a/src/hooks/useDroppable.ts b/src/hooks/useDroppable.ts index 41fa36e..d6d429f 100644 --- a/src/hooks/useDroppable.ts +++ b/src/hooks/useDroppable.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-dynamic-delete */ + import { useLayoutEffect } from "react"; import { type LayoutRectangle, type ViewProps } from "react-native"; import { runOnUI, useAnimatedReaction, useSharedValue } from "react-native-reanimated"; diff --git a/src/hooks/useDroppableStyle.tsx b/src/hooks/useDroppableStyle.tsx index c73e36b..c5f4c11 100644 --- a/src/hooks/useDroppableStyle.tsx +++ b/src/hooks/useDroppableStyle.tsx @@ -14,6 +14,7 @@ export const useDroppableStyle = ( const { droppableActiveId: activeId, droppableOptions: options } = useDndContext(); return useAnimatedStyle(() => { const isActive = activeId.value === id; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition const isDisabled = !options.value[id]?.disabled; return callback({ isActive, isDisabled }); }, []); diff --git a/src/hooks/useNodeRef.ts b/src/hooks/useNodeRef.ts index 790128d..f7ecda8 100644 --- a/src/hooks/useNodeRef.ts +++ b/src/hooks/useNodeRef.ts @@ -12,6 +12,7 @@ export const useNodeRef = (onChange?: NodeChangeHandler) => { const setNodeRef = useCallback( (element: U | null) => { if (element !== nodeRef.current) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition onChangeHandler?.(element, nodeRef.current); } nodeRef.current = element as T; diff --git a/src/types/common.ts b/src/types/common.ts index 3bd9779..e16e2b7 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -8,7 +8,6 @@ export type AnyData = Record; export type Data = T | SharedValue; export type SharedData = SharedValue; -// eslint-disable-next-line @typescript-eslint/no-explicit-any export type NativeElement = InstanceType>; export type AnimatedStyle = ReturnType; diff --git a/src/utils/assert.ts b/src/utils/assert.ts index e919230..652bf53 100644 --- a/src/utils/assert.ts +++ b/src/utils/assert.ts @@ -7,7 +7,7 @@ class AssertionError extends Error { public expected: unknown = "true", public operator = "==", ) { - super(message || `${actual} ${operator} ${expected}`); + super(message || `${String(actual)} ${operator} ${String(expected)}`); Object.setPrototypeOf(this, new.target.prototype); } } diff --git a/src/utils/reanimated.ts b/src/utils/reanimated.ts index 336fdab..9bc54ea 100644 --- a/src/utils/reanimated.ts +++ b/src/utils/reanimated.ts @@ -141,4 +141,5 @@ export const floorLayout = ({ x, y, width, height }: LayoutRectangle) => { * @returns {boolean} Whether the value is a `Reanimated` shared value */ export const isReanimatedSharedValue = (value: unknown): value is SharedValue => + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition typeof value === "object" && (value as { _isReanimatedSharedValue: boolean })?._isReanimatedSharedValue; diff --git a/test/DndProvider.spec.tsx b/test/DndProvider.spec.tsx index 5fdffcf..2233029 100644 --- a/test/DndProvider.spec.tsx +++ b/test/DndProvider.spec.tsx @@ -5,7 +5,7 @@ import { fireGestureHandler, getByGestureTestId } from "react-native-gesture-han import { DndProvider, Draggable, Droppable } from "../src"; describe("", () => { - test("basic example", async () => { + test("basic example", () => { const view = render( diff --git a/test/setup.ts b/test/setup.ts index 27265c7..830fa30 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -1,4 +1,8 @@ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ +/* eslint-disable @typescript-eslint/no-require-imports */ +/* eslint-disable @typescript-eslint/no-unsafe-call */ + import "@testing-library/jest-native/extend-expect"; -// eslint-disable-next-line @typescript-eslint/no-var-requires require("react-native-reanimated/lib/module/reanimated2/jestUtils").setUpTests(); jest.mock("react-native-reanimated", () => require("react-native-reanimated/mock"));