From c192c1648ff71d3bfb42c9f38fc95b08fd129f3e Mon Sep 17 00:00:00 2001 From: SukkaW Date: Fri, 12 Jul 2024 17:55:53 +0800 Subject: [PATCH] chore: make eslint happy --- eslint.config.js | 4 +++- src/compose-context-provider/index.ts | 2 +- src/create-storage-hook/index.ts | 1 - src/rem/index.ts | 4 ++-- src/request-idle-callback/index.ts | 9 ++++----- src/types/index.ts | 2 +- src/use-composition-input/index.ts | 1 - src/use-debounced-value/index.ts | 1 - src/use-error-boundary/index.ts | 2 +- src/use-next-link/index.ts | 4 ++-- .../index.ts | 2 -- src/use-url-hash-state/index.ts | 2 -- src/use/index.ts | 3 +++ 13 files changed, 17 insertions(+), 20 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 2ec11c75..571523fb 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -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 diff --git a/src/compose-context-provider/index.ts b/src/compose-context-provider/index.ts index 187ffef8..3bfa55b3 100644 --- a/src/compose-context-provider/index.ts +++ b/src/compose-context-provider/index.ts @@ -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[] } diff --git a/src/create-storage-hook/index.ts b/src/create-storage-hook/index.ts index 195408ce..647080db 100644 --- a/src/create-storage-hook/index.ts +++ b/src/create-storage-hook/index.ts @@ -20,7 +20,6 @@ export type Serializer = (value: T) => string; export type Deserializer = (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; diff --git a/src/rem/index.ts b/src/rem/index.ts index 095c7114..d4d7332d 100644 --- a/src/rem/index.ts +++ b/src/rem/index.ts @@ -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(' '); } @@ -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; diff --git a/src/request-idle-callback/index.ts b/src/request-idle-callback/index.ts index 4ca28213..9ab94a17 100644 --- a/src/request-idle-callback/index.ts +++ b/src/request-idle-callback/index.ts @@ -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(() => { @@ -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); }; diff --git a/src/types/index.ts b/src/types/index.ts index 3d6e6619..1b631ea3 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,7 +2,7 @@ export namespace Foxact { export type PropsWithRef

= Readonly>; export type PropsWithoutRef

= Readonly>; export type PropsWithChildren

= Readonly>; - export type ComponentProps> = Readonly>; + export type ComponentProps> = Readonly>; export type CustomComponentProps = Readonly>; export type ComponentPropsWithRef = Readonly>; export type CustomComponentPropsWithRef = Readonly>; diff --git a/src/use-composition-input/index.ts b/src/use-composition-input/index.ts index 9399e79b..f3c275f0 100644 --- a/src/use-composition-input/index.ts +++ b/src/use-composition-input/index.ts @@ -27,7 +27,6 @@ export const useCompositionInput = = T extends Function ? never : T; /** @see https://foxact.skk.moe/use-debounced-value */ diff --git a/src/use-error-boundary/index.ts b/src/use-error-boundary/index.ts index ad48d998..187469ef 100644 --- a/src/use-error-boundary/index.ts +++ b/src/use-error-boundary/index.ts @@ -5,7 +5,7 @@ import { useState } from 'react'; type ErrorLike = Error | undefined | null | boolean; -const isTruthy = (value: ErrorLike): value is NonNullable => { +const isTruthy = (value: ErrorLike): value is Error => { if (value === false) return false; if (value == null) return false; diff --git a/src/use-next-link/index.ts b/src/use-next-link/index.ts index 20d5af90..0af212f8 100644 --- a/src/use-next-link/index.ts +++ b/src/use-next-link/index.ts @@ -37,7 +37,7 @@ export interface UseNextLinkOptions extends Omit | React.RefCallback | null } -export interface UseNextLinkReturnProps extends Partial { +export interface UseNextLinkReturnProps extends Partial { ref: React.RefCallback, onTouchStart: React.TouchEventHandler, onMouseEnter: React.MouseEventHandler, @@ -55,6 +55,7 @@ const isModifiedEvent = (event: React.MouseEvent) => { || event.ctrlKey || event.shiftKey || event.altKey // triggers resource download + // eslint-disable-next-line deprecation/deprecation -- back compat || (event.nativeEvent && event.nativeEvent.which === 2) ); }; @@ -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).current = el; } }, [ref, setIntersectionRef]), diff --git a/src/use-react-router-enable-concurrent-navigation/index.ts b/src/use-react-router-enable-concurrent-navigation/index.ts index 4e3c5faa..4c337521 100644 --- a/src/use-react-router-enable-concurrent-navigation/index.ts +++ b/src/use-react-router-enable-concurrent-navigation/index.ts @@ -11,7 +11,6 @@ import type { Foxact } from '../types'; export const useReactRouterEnableConcurrentNavigation = () => { const { navigator } = useContext>(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 or a Router component (e.g. )'); } @@ -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) => startTransition(() => originalNavigatorGo.apply(navigator, args)); navigator.push = (...args: Parameters) => startTransition(() => originalNavigatorPush.apply(navigator, args)); navigator.replace = (...args: Parameters) => startTransition(() => originalNavigatorReplace.apply(navigator, args)); diff --git a/src/use-url-hash-state/index.ts b/src/use-url-hash-state/index.ts index 243da698..18bf8922 100644 --- a/src/use-url-hash-state/index.ts +++ b/src/use-url-hash-state/index.ts @@ -38,7 +38,6 @@ const subscribe: Parameters[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 = (value: T) => string; @@ -110,7 +109,6 @@ function useUrlHashState( return; } - // eslint-disable-next-line react-compiler/react-compiler -- sync external state location.hash = newHash; }, [defaultValue, deserialized, key, serializer]); diff --git a/src/use/index.ts b/src/use/index.ts index d1a2fe1d..1b82a7c8 100644 --- a/src/use/index.ts +++ b/src/use/index.ts @@ -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': { @@ -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'; @@ -35,6 +37,7 @@ export const use promise.reason = e; } ); + // eslint-disable-next-line @typescript-eslint/only-throw-error -- React.use throw promise; } }