From f7afb9ac2b6e3ea9ec1d7c6865e72f4efc958156 Mon Sep 17 00:00:00 2001 From: Utku Bakir <74243531+utkubakir@users.noreply.github.com> Date: Wed, 14 Dec 2022 13:10:42 +0300 Subject: [PATCH] Add eslint to @sd/client & fix types --- packages/client/.eslintrc.js | 7 +++++++ packages/client/package.json | 2 +- packages/client/src/hooks/useCurrentLibrary.tsx | 4 ++-- packages/client/src/normi/index.ts | 2 +- packages/client/src/normi/types.ts | 4 ++-- packages/client/src/normi/utils.ts | 4 ++-- 6 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 packages/client/.eslintrc.js diff --git a/packages/client/.eslintrc.js b/packages/client/.eslintrc.js new file mode 100644 index 000000000..b3e0f403d --- /dev/null +++ b/packages/client/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + ...require('@sd/config/eslint-react.js'), + parserOptions: { + tsconfigRootDir: __dirname, + project: './tsconfig.json' + } +}; diff --git a/packages/client/package.json b/packages/client/package.json index 70ab2ec59..05919df7c 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -8,7 +8,7 @@ ], "scripts": { "test": "jest", - "lint": "TIMING=1 eslint src --fix", + "lint": "eslint src/**/*.{ts,tsx} && tsc --noEmit", "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" }, "dependencies": { diff --git a/packages/client/src/hooks/useCurrentLibrary.tsx b/packages/client/src/hooks/useCurrentLibrary.tsx index 5c3c120bd..be13e387a 100644 --- a/packages/client/src/hooks/useCurrentLibrary.tsx +++ b/packages/client/src/hooks/useCurrentLibrary.tsx @@ -1,5 +1,5 @@ import { PropsWithChildren, createContext, useCallback, useContext, useMemo } from 'react'; -import { proxy, subscribe, useSnapshot } from 'valtio'; +import { subscribe, useSnapshot } from 'valtio'; import { useBridgeQuery } from '../rspc'; import { valtioPersist } from '../stores'; @@ -81,7 +81,7 @@ export const useCurrentLibrary = () => { } return current; - }, [libraries, currentLibraryUuid]); // TODO: This runs when the 'libraries' change causing the whole app to re-render which is cringe. + }, [libraries, currentLibraryUuid, switchLibrary]); // TODO: This runs when the 'libraries' change causing the whole app to re-render which is cringe. return { library, diff --git a/packages/client/src/normi/index.ts b/packages/client/src/normi/index.ts index b150ab6fb..515af3039 100644 --- a/packages/client/src/normi/index.ts +++ b/packages/client/src/normi/index.ts @@ -10,7 +10,7 @@ export function normiCustomHooks( { contextSharing }: NormiOptions, nextHooks?: () => CustomHooks ): () => CustomHooks { - let normiCache = getNormiCache(contextSharing ?? false); + const normiCache = getNormiCache(contextSharing ?? false); const next = nextHooks?.(); // TODO: Handle manual modifications to the query cache diff --git a/packages/client/src/normi/types.ts b/packages/client/src/normi/types.ts index c87b3432b..445d73eb4 100644 --- a/packages/client/src/normi/types.ts +++ b/packages/client/src/normi/types.ts @@ -6,8 +6,8 @@ export type OmitDistributive = T extends any ? Id> : T : never; -export type Id = {} & { [P in keyof T]: T[P] }; // Cosmetic use only makes the tooltips expand the type can be removed -export type OmitRecursively = Omit< +export type Id = object & { [P in keyof T]: T[P] }; // Cosmetic use only makes the tooltips expand the type can be removed +export type OmitRecursively = Omit< { [P in keyof T]: OmitDistributive }, K >; diff --git a/packages/client/src/normi/utils.ts b/packages/client/src/normi/utils.ts index afa8b46e8..a37126d36 100644 --- a/packages/client/src/normi/utils.ts +++ b/packages/client/src/normi/utils.ts @@ -59,7 +59,7 @@ export function normaliseValueForStorage(value: any, rootElem: boolean): any { } else if (typeof value === 'object') { if ('$id' in value && '$type' in value) { if (rootElem) { - let v = Object.assign({}, value); + const v = Object.assign({}, value); delete v.$id; delete v.$type; @@ -144,7 +144,7 @@ export function loadDataFromCache(value: any, normiCache: NormiCache): any { } else if (typeof value === 'object') { if ('$id' in value && '$type' in value) { // if (rootElem) { - let v = Object.assign({}, value); + const v = Object.assign({}, value); delete v.$id; delete v.$type;