Skip to content

Commit

Permalink
chore: make eslint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jul 12, 2024
1 parent d113bff commit c192c16
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 20 deletions.
4 changes: 3 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module.exports = require('eslint-config-sukka').sukka({
ignores: {
customGlobs: ['dist/**/*', 'docs/**/*', ...require('eslint-config-sukka').constants.GLOB_EXCLUDE]
},
react: true,
react: {
nextjs: false
},
ts: {
enable: true,
tsconfigPath
Expand Down
2 changes: 1 addition & 1 deletion src/compose-context-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cloneElement, memo } from 'react';
import type { Foxact } from '../types';

export interface ContextComposeProviderProps extends Foxact.PropsWithChildren {
// eslint-disable-next-line @typescript-eslint/ban-types -- cloneElement
// eslint-disable-next-line @typescript-eslint/no-restricted-types -- cloneElement
contexts: React.ReactElement[]
}

Expand Down
1 change: 0 additions & 1 deletion src/create-storage-hook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type Serializer<T> = (value: T) => string;
export type Deserializer<T> = (value: string) => T;

// This type utility is only used for workaround https://github.com/microsoft/TypeScript/issues/37663
// eslint-disable-next-line @typescript-eslint/ban-types -- workaround TypeScript bug
const isFunction = (x: unknown): x is Function => typeof x === 'function';

const identity = (x: any) => x;
Expand Down
4 changes: 2 additions & 2 deletions src/rem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function scaleRem(remValue: string, shouldScaleTo: string) {
}

function createConverter(units: string, shouldScaleTo: string | null = null) {
return function converter(value: number | string | number[] | string[]): string {
return function converter(value: number | string | number[]): string {
if (Array.isArray(value)) {
return value.map((val) => converter(val)).join(' ');
}
Expand Down Expand Up @@ -35,7 +35,7 @@ function createConverter(units: string, shouldScaleTo: string | null = null) {
}

const replaced = Number(value.replace('px', ''));
// eslint-disable-next-line no-self-compare -- faster isNaN check

if (replaced === replaced) {
const val = `${replaced / 16}${units}`;
return (shouldScaleTo && shouldScaleTo !== SIXTEEN_PX) ? scaleRem(val, shouldScaleTo) : val;
Expand Down
9 changes: 4 additions & 5 deletions src/request-idle-callback/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable ssr-friendly/no-dom-globals-in-module-scope -- polyfilllg */
/* eslint-disable @typescript-eslint/no-unnecessary-condition -- polyfill */

/** @see https://foxact.skk.moe/request-idle-callback */
export const requestIdleCallback = (
typeof self !== 'undefined'
&& self.requestIdleCallback
&& self.requestIdleCallback.bind(self)
&& self.requestIdleCallback
&& self.requestIdleCallback.bind(self)
) || function (cb: IdleRequestCallback): number {
const start = Date.now();
return self.setTimeout(() => {
Expand All @@ -21,8 +20,8 @@ export const requestIdleCallback = (
/** @see https://foxact.skk.moe/request-idle-callback */
export const cancelIdleCallback = (
typeof self !== 'undefined'
&& self.cancelIdleCallback
&& self.cancelIdleCallback.bind(self)
&& self.cancelIdleCallback
&& self.cancelIdleCallback.bind(self)
) || function (id: number) {
return clearTimeout(id);
};
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export namespace Foxact {
export type PropsWithRef<P> = Readonly<React.PropsWithRef<P>>;
export type PropsWithoutRef<P> = Readonly<React.PropsWithoutRef<P>>;
export type PropsWithChildren<P = unknown> = Readonly<React.PropsWithChildren<P>>;
export type ComponentProps<T extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>> = Readonly<React.ComponentProps<T>>;
export type ComponentProps<T extends keyof React.JSX.IntrinsicElements | React.JSXElementConstructor<any>> = Readonly<React.ComponentProps<T>>;
export type CustomComponentProps<T extends React.ComponentType> = Readonly<React.ComponentProps<T>>;
export type ComponentPropsWithRef<T extends React.ElementType> = Readonly<React.ComponentPropsWithRef<T>>;
export type CustomComponentPropsWithRef<T extends React.ComponentType> = Readonly<React.ComponentPropsWithRef<T>>;
Expand Down
1 change: 0 additions & 1 deletion src/use-composition-input/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const useCompositionInput = <T extends HTMLInputElement | HTMLTextAreaEle
if (!internalState.current.c) {
cb(userInputValue);

// eslint-disable-next-line react-compiler/react-compiler -- useSingleton returns a ref
internalState.current.e = true;
} else {
internalState.current.e = false;
Expand Down
1 change: 0 additions & 1 deletion src/use-debounced-value/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'client-only';
import { useEffect, useState, useRef } from 'react';

// eslint-disable-next-line @typescript-eslint/ban-types -- explicitly banning ALL functions
type NotFunction<T> = T extends Function ? never : T;

/** @see https://foxact.skk.moe/use-debounced-value */
Expand Down
2 changes: 1 addition & 1 deletion src/use-error-boundary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useState } from 'react';

type ErrorLike = Error | undefined | null | boolean;

const isTruthy = (value: ErrorLike): value is NonNullable<ErrorLike> => {
const isTruthy = (value: ErrorLike): value is Error => {
if (value === false) return false;
if (value == null) return false;

Expand Down
4 changes: 2 additions & 2 deletions src/use-next-link/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface UseNextLinkOptions extends Omit<LinkProps,
ref?: React.RefObject<HTMLAnchorElement> | React.RefCallback<HTMLAnchorElement> | null
}

export interface UseNextLinkReturnProps extends Partial<JSX.IntrinsicElements['a']> {
export interface UseNextLinkReturnProps extends Partial<React.JSX.IntrinsicElements['a']> {
ref: React.RefCallback<HTMLAnchorElement>,
onTouchStart: React.TouchEventHandler<HTMLAnchorElement>,
onMouseEnter: React.MouseEventHandler<HTMLAnchorElement>,
Expand All @@ -55,6 +55,7 @@ const isModifiedEvent = (event: React.MouseEvent<HTMLAnchorElement>) => {
|| event.ctrlKey
|| event.shiftKey
|| event.altKey // triggers resource download
// eslint-disable-next-line deprecation/deprecation -- back compat
|| (event.nativeEvent && event.nativeEvent.which === 2)
);
};
Expand Down Expand Up @@ -161,7 +162,6 @@ const useNextLink = (
if (typeof ref === 'function') {
ref(el);
} else if (ref && el) {
// eslint-disable-next-line react-compiler/react-compiler -- We are acting on React behalf to assign the passed-in ref
(ref as React.MutableRefObject<HTMLAnchorElement>).current = el;
}
}, [ref, setIntersectionRef]),
Expand Down
2 changes: 0 additions & 2 deletions src/use-react-router-enable-concurrent-navigation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { Foxact } from '../types';
export const useReactRouterEnableConcurrentNavigation = () => {
const { navigator } = useContext<React.ContextType<typeof UNSAFE_NavigationContext>>(UNSAFE_NavigationContext);

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- type check
if (!navigator) {
throw new TypeError('[foxact/use-react-router-enable-concurrent-navigation] must be used under <RouterProvider /> or a Router component (e.g. <BrowserRouter />)');
}
Expand All @@ -21,7 +20,6 @@ export const useReactRouterEnableConcurrentNavigation = () => {
const originalNavigatorPush = navigator.push.bind(navigator);
const originalNavigatorReplace = navigator.replace.bind(navigator);

// eslint-disable-next-line react-compiler/react-compiler -- mutate context global
navigator.go = (...args: Parameters<Navigator['go']>) => startTransition(() => originalNavigatorGo.apply(navigator, args));
navigator.push = (...args: Parameters<Navigator['push']>) => startTransition(() => originalNavigatorPush.apply(navigator, args));
navigator.replace = (...args: Parameters<Navigator['replace']>) => startTransition(() => originalNavigatorReplace.apply(navigator, args));
Expand Down
2 changes: 0 additions & 2 deletions src/use-url-hash-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const subscribe: Parameters<typeof useSyncExternalStore>[0] = (() => {
})();

// This type utility is only used for workaround https://github.com/microsoft/TypeScript/issues/37663
// eslint-disable-next-line @typescript-eslint/ban-types -- workaround TypeScript bug
const isFunction = (x: unknown): x is Function => typeof x === 'function';

export type Serializer<T> = (value: T) => string;
Expand Down Expand Up @@ -110,7 +109,6 @@ function useUrlHashState<T>(
return;
}

// eslint-disable-next-line react-compiler/react-compiler -- sync external state
location.hash = newHash;
}, [defaultValue, deserialized, key, serializer]);

Expand Down
3 changes: 3 additions & 0 deletions src/use/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const use
): T => {
switch (promise.status) {
case 'pending': {
// eslint-disable-next-line @typescript-eslint/only-throw-error -- React.use
throw promise;
}
case 'fulfilled': {
Expand All @@ -25,6 +26,7 @@ export const use
}
default: {
promise.status = 'pending';
// eslint-disable-next-line promise/catch-or-return -- React.use
promise.then(
(v) => {
promise.status = 'fulfilled';
Expand All @@ -35,6 +37,7 @@ export const use
promise.reason = e;
}
);
// eslint-disable-next-line @typescript-eslint/only-throw-error -- React.use
throw promise;
}
}
Expand Down

0 comments on commit c192c16

Please sign in to comment.