Skip to content

Commit

Permalink
fix(eslint): correct eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcrea committed Nov 21, 2024
1 parent c71f945 commit 7776249
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/DndProvider.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -369,6 +371,7 @@ export const DndProvider = forwardRef<DndProviderHandle, PropsWithChildren<DndPr
) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (states[activeId]) {
states[activeId].value = "resting";
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/sort/components/DraggableGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const DraggableGrid: FunctionComponent<PropsWithChildren<DraggableGridPro
() =>
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],
);

Expand Down
5 changes: 2 additions & 3 deletions src/features/sort/components/DraggableStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ export const DraggableStack: FunctionComponent<PropsWithChildren<DraggableStackP
const initialOrder = useMemo(
() =>
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],
);

Expand Down
1 change: 1 addition & 0 deletions src/features/sort/hooks/useDraggableSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useDraggable.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useDraggableStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const useDraggableStyle = <StyleT extends AnimatedStyle>(
const state = states.value[id];
return useAnimatedStyle<StyleT>(() => {
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]);
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useDroppable.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useDroppableStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useDroppableStyle = <StyleT extends AnimatedStyle>(
const { droppableActiveId: activeId, droppableOptions: options } = useDndContext();
return useAnimatedStyle<StyleT>(() => {
const isActive = activeId.value === id;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const isDisabled = !options.value[id]?.disabled;
return callback({ isActive, isDisabled });
}, []);
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useNodeRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const useNodeRef = <T, U = T>(onChange?: NodeChangeHandler<T>) => {
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;
Expand Down
1 change: 0 additions & 1 deletion src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type AnyData = Record<string, any>;
export type Data<T = AnyData> = T | SharedValue<T>;
export type SharedData<T = AnyData> = SharedValue<T>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type NativeElement = InstanceType<HostComponent<ViewProps>>;

export type AnimatedStyle = ReturnType<typeof useAnimatedStyle>;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/reanimated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyData> =>
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
typeof value === "object" && (value as { _isReanimatedSharedValue: boolean })?._isReanimatedSharedValue;
2 changes: 1 addition & 1 deletion test/DndProvider.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fireGestureHandler, getByGestureTestId } from "react-native-gesture-han
import { DndProvider, Draggable, Droppable } from "../src";

describe("<DndProvider />", () => {
test("basic example", async () => {
test("basic example", () => {
const view = render(
<GestureHandlerRootView>
<DndProvider>
Expand Down
6 changes: 5 additions & 1 deletion test/setup.ts
Original file line number Diff line number Diff line change
@@ -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"));

0 comments on commit 7776249

Please sign in to comment.