From c1384dd52045ad1b070621b7dbc1b138286c49f4 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 31 Aug 2021 23:13:43 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20make=20yarn=20lint=20wo?= =?UTF-8?q?rk=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 2 +- package.json | 2 +- src/factory/createBreakpoint.ts | 54 ++++++++++++++--------------- src/factory/createHTMLMediaHook.ts | 2 +- src/factory/createMemo.ts | 6 ++-- src/factory/createReducerContext.ts | 7 ++-- src/factory/createStateContext.ts | 5 ++- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index bc521369..a196da2e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['prettier/@typescript-eslint', 'react-app', 'plugin:prettier/recommended'], + extends: ['prettier', 'react-app', 'plugin:prettier/recommended'], plugins: ['prettier'], rules: { 'prettier/prettier': [ diff --git a/package.json b/package.json index 8fc52490..a111e70c 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "test:ssr": "jest --maxWorkers 2 --config ./jest.config.node.ts", "test:watch": "jest --watch", "test:coverage": "jest --coverage", - "lint": "eslint {src,tests,stories}/**/*.{ts,tsx}", + "lint": "eslint {src,tests}/**/*.ts", "lint:fix": "yarn lint --fix", "lint:types": "tsc --noEmit", "build:cjs": "tsc", diff --git a/src/factory/createBreakpoint.ts b/src/factory/createBreakpoint.ts index fb97896f..d6183282 100644 --- a/src/factory/createBreakpoint.ts +++ b/src/factory/createBreakpoint.ts @@ -1,33 +1,33 @@ import { useEffect, useMemo, useState } from 'react'; import { isBrowser, off, on } from '../misc/util'; -const createBreakpoint = ( - breakpoints: { [name: string]: number } = { laptopL: 1440, laptop: 1024, tablet: 768 } -) => () => { - const [screen, setScreen] = useState(isBrowser ? window.innerWidth : 0); +const createBreakpoint = + (breakpoints: { [name: string]: number } = { laptopL: 1440, laptop: 1024, tablet: 768 }) => + () => { + const [screen, setScreen] = useState(isBrowser ? window.innerWidth : 0); - useEffect(() => { - const setSideScreen = (): void => { - setScreen(window.innerWidth); - }; - setSideScreen(); - on(window, 'resize', setSideScreen); - return () => { - off(window, 'resize', setSideScreen); - }; - }); - const sortedBreakpoints = useMemo( - () => Object.entries(breakpoints).sort((a, b) => (a[1] >= b[1] ? 1 : -1)), - [breakpoints] - ); - const result = sortedBreakpoints.reduce((acc, [name, width]) => { - if (screen >= width) { - return name; - } else { - return acc; - } - }, sortedBreakpoints[0][0]); - return result; -}; + useEffect(() => { + const setSideScreen = (): void => { + setScreen(window.innerWidth); + }; + setSideScreen(); + on(window, 'resize', setSideScreen); + return () => { + off(window, 'resize', setSideScreen); + }; + }); + const sortedBreakpoints = useMemo( + () => Object.entries(breakpoints).sort((a, b) => (a[1] >= b[1] ? 1 : -1)), + [breakpoints] + ); + const result = sortedBreakpoints.reduce((acc, [name, width]) => { + if (screen >= width) { + return name; + } else { + return acc; + } + }, sortedBreakpoints[0][0]); + return result; + }; export default createBreakpoint; diff --git a/src/factory/createHTMLMediaHook.ts b/src/factory/createHTMLMediaHook.ts index 954a5bb8..92d62c9d 100644 --- a/src/factory/createHTMLMediaHook.ts +++ b/src/factory/createHTMLMediaHook.ts @@ -51,7 +51,7 @@ export default function createHTMLMediaHook(null); diff --git a/src/factory/createMemo.ts b/src/factory/createMemo.ts index 9b796877..8fe16ee9 100644 --- a/src/factory/createMemo.ts +++ b/src/factory/createMemo.ts @@ -1,6 +1,8 @@ import { useMemo } from 'react'; -const createMemo = any>(fn: T) => (...args: Parameters) => - useMemo>(() => fn(...args), args); +const createMemo = + any>(fn: T) => + (...args: Parameters) => + useMemo>(() => fn(...args), args); export default createMemo; diff --git a/src/factory/createReducerContext.ts b/src/factory/createReducerContext.ts index f07a0165..db24bfbb 100644 --- a/src/factory/createReducerContext.ts +++ b/src/factory/createReducerContext.ts @@ -4,9 +4,10 @@ const createReducerContext = >( reducer: R, defaultInitialState: React.ReducerState ) => { - const context = createContext< - [React.ReducerState, React.Dispatch>] | undefined - >(undefined); + const context = + createContext<[React.ReducerState, React.Dispatch>] | undefined>( + undefined + ); const providerFactory = (props, children) => createElement(context.Provider, props, children); const ReducerProvider: React.FC<{ initialState?: React.ReducerState }> = ({ diff --git a/src/factory/createStateContext.ts b/src/factory/createStateContext.ts index 3e73ef93..4c3919c5 100644 --- a/src/factory/createStateContext.ts +++ b/src/factory/createStateContext.ts @@ -1,9 +1,8 @@ import { createContext, createElement, useContext, useState } from 'react'; const createStateContext = (defaultInitialValue: T) => { - const context = createContext<[T, React.Dispatch>] | undefined>( - undefined - ); + const context = + createContext<[T, React.Dispatch>] | undefined>(undefined); const providerFactory = (props, children) => createElement(context.Provider, props, children); const StateProvider: React.FC<{ initialValue?: T }> = ({ children, initialValue }) => {