Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df72dbe

Browse files
committedJun 25, 2024··
chore: add hooks ESLint plugin
1 parent 6a40352 commit df72dbe

File tree

9 files changed

+42
-22
lines changed

9 files changed

+42
-22
lines changed
 

‎packages/client/eslint.config.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import js from "@eslint/js"
22
import react from "eslint-plugin-react"
3+
import hooks from "eslint-plugin-react-hooks"
34
import simpleImportSort from "eslint-plugin-simple-import-sort"
45
import globals from "globals"
56
import tseslint from "typescript-eslint"
@@ -15,10 +16,15 @@ export default [
1516
...tseslint.configs.recommended,
1617
{
1718
plugins: {
19+
// https://github.com/lydell/eslint-plugin-simple-import-sort
1820
"simple-import-sort": simpleImportSort,
21+
// https://typescript-eslint.io/getting-started/
1922
"@typescript-eslint": tseslint.plugin,
20-
// ref https://github.com/jsx-eslint/eslint-plugin-react
23+
// https://github.com/jsx-eslint/eslint-plugin-react
2124
react,
25+
// https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks
26+
// compat with ESLint v9, see https://github.com/facebook/react/issues/28313
27+
"react-hooks": hooks,
2228
},
2329
languageOptions: {
2430
parser: tseslint.parser,
@@ -69,6 +75,9 @@ export default [
6975
// ref https://github.com/lydell/eslint-plugin-simple-import-sort#usage
7076
"simple-import-sort/imports": "error",
7177
"simple-import-sort/exports": "error",
78+
79+
// as hooks plugin does not play well with Flat Config right now, do this
80+
...hooks.configs.recommended.rules,
7281
},
7382
},
7483
{

‎packages/client/package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/client/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"scripts": {
2727
"_runLocal": "cross-env VITE_HYDRA_URL=ws://localhost:8929 $npm_config_runcmd",
28-
"start": "cross-env TARGET=web vite",
28+
"start": "vite",
2929
"start:local": "npm run _runLocal --runcmd=\"TARGET=web vite\"",
3030
"typecheck": "tsc",
3131
"lint": "eslint src --max-warnings 0",
@@ -36,8 +36,8 @@
3636
"format:check": "npm run _format -- --check",
3737
"test": "vitest",
3838
"verify": "npm run typecheck && npm run lint && npm run format:check && npm run test -- run",
39-
"build": "cross-env TARGET=web vite build",
40-
"serve": "cross-env vite preview",
39+
"build": "vite build",
40+
"serve": "vite preview",
4141
"openfin:dev": "cross-env TARGET=openfin vite",
4242
"openfin:local": "npm run _runLocal --runcmd=\"TARGET=openfin vite\"",
4343
"_openfin:run": "cross-env-shell \"wait-on -l $npm_config_manifest_url && openfin -l -c $npm_config_manifest_url\"",
@@ -128,6 +128,7 @@
128128
"csstype": "^3.0.2",
129129
"eslint": "8.57.0",
130130
"eslint-plugin-react": "7.34.3",
131+
"eslint-plugin-react-hooks": "4.6.2",
131132
"eslint-plugin-simple-import-sort": "12.1.0",
132133
"globals": "15.6.0",
133134
"jest-styled-components": "7.2.0",

‎packages/client/src/client/App/Analytics/ProfitAndLoss/LineChart/Tooltip.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const Tooltip = ({ svgRef }: { svgRef: RefObject<SVGSVGElement> }) => {
116116
const tooltipDivRef = useDivRef()
117117

118118
const tooltipPositionRef = useRef<{ x: number; y: number }>({ x: 0, y: 0 })
119+
119120
useEffect(() => {
120121
if (!svgRef.current) return
121122
const svg = svgRef.current
@@ -139,7 +140,7 @@ export const Tooltip = ({ svgRef }: { svgRef: RefObject<SVGSVGElement> }) => {
139140
svg.removeEventListener("pointermove", onMove)
140141
svg.removeEventListener("pointerleave", onLeave)
141142
}
142-
}, [svgRef])
143+
}, [svgRef, tooltipDivRef])
143144

144145
useLayoutEffect(() => {
145146
// We have to correct the position of the tooltip when it overflows

‎packages/client/src/client/App/Credit/CreditRfqs/CreditRfqCards/CardFooter.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ACCEPTED_QUOTE_STATE } from "@/generated/TradingGateway"
77
import {
88
cancelCreditRfq$,
99
removeRfqs,
10-
useCreditDealerById,
10+
useDealerNameById,
1111
} from "@/services/credit"
1212
import { RfqDetails } from "@/services/credit/creditRfqs"
1313

@@ -49,11 +49,7 @@ export const AcceptedFooterContent = ({
4949
rfqId: number
5050
acceptedDealerId?: number
5151
}) => {
52-
const dealerName =
53-
(acceptedDealerId !== undefined
54-
? useCreditDealerById(acceptedDealerId)
55-
: undefined
56-
)?.name ?? "Unknown Dealer"
52+
const dealerName = useDealerNameById(acceptedDealerId)
5753

5854
return (
5955
<>

‎packages/client/src/client/App/Header/theme-switcher/ThemeSwitcher.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const ThemeStorageSwitch = ({
6767
/>
6868
</IconContainer>
6969
}
70-
handleDiameter={props.handleDiameter}
70+
handleDiameter={props.handleDiameter || 15}
7171
offColor={theme.primary.base}
7272
offHandleColor={theme.accents.primary.base}
7373
onColor={theme.primary[1]}
@@ -83,8 +83,4 @@ const ThemeStorageSwitch = ({
8383
)
8484
}
8585

86-
ThemeStorageSwitch.defaultProps = {
87-
handleDiameter: 15,
88-
}
89-
9086
export default withTheme(ThemeStorageSwitch)

‎packages/client/src/client/OpenFin/apps/Launcher/NlpSuggestions/executions/useMouseNextOnEnter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export const useMoveNextOnEnter = (onNext: () => void) => {
1212
return () => {
1313
window.removeEventListener("keydown", onKeyDown)
1414
}
15-
}, [])
15+
}, [onNext])
1616
}

‎packages/client/src/services/credit/creditDealers.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ export const [useCreditDealers, creditDealers$] = bind(
3232
),
3333
)
3434

35-
export const [useCreditDealerById, creditDealerById$] = bind(
36-
(dealerId: number) =>
37-
creditDealers$.pipe(
38-
map((dealers) => dealers.find((dealer) => dealer.id === dealerId)),
35+
export const [useDealerNameById, _] = bind((dealerId: number | undefined) =>
36+
creditDealers$.pipe(
37+
map(
38+
(dealers) =>
39+
dealers.find((dealer) => dealer.id === dealerId)?.name ||
40+
"Unknown Dealer",
3941
),
42+
),
4043
)
4144

4245
export const [useAdaptiveDealerId, adaptiveDealerId$] = bind(

‎packages/client/vite.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ const setConfig: (env: ConfigEnv) => UserConfigExport = ({ mode }) => {
353353

354354
const buildTarget: BuildTarget = (process.env.TARGET as BuildTarget) || "web"
355355
const isDev = mode === "development"
356-
// quick look-up (not using isServe atm, but expecting to optimise plugins later)
356+
// quick look-up (not using isServe = command === "serve" atm, command from 2nd arg of setConfig)
357+
// but expecting to optimise plugins later)
357358
// - vite .. isDev: true isServe: true (building with esbuild AND serving)
358359
// - vite preview .. isDev: false isServe: true (just running static, so don't need any plugins etc.)
359360
// - vitest .. isDev: false isServe: true (still need the plugins to e.g. switch in openfin code)

0 commit comments

Comments
 (0)
Please sign in to comment.