From 6233c8dc4211f21a8c4e169adc5f9d13394d0703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lord=20Andr=C3=A9=20Groseth?= Date: Tue, 20 Aug 2024 12:03:03 +0200 Subject: [PATCH] Update typescript eslint (#953) * REFACTOR: To IF statement Co-authored-by: Jeremiah Uy Co-authored-by: Rebecca Gjerstad * UPDATE: eslint Co-authored-by: Jeremiah Uy Co-authored-by: Rebecca Gjerstad * FIX: type script errors Co-authored-by: Jeremiah Uy * UPDATE: disabling and enabling of eslint rules Co-authored-by: andregroseth Co-authored-by: beeccy Co-authored-by: PaulMartinKokseter --------- Co-authored-by: Jeremiah Uy Co-authored-by: Rebecca Gjerstad Co-authored-by: PaulMartinKokseter --- apps/frontend/package.json | 4 +-- apps/frontend/src/api/EtterlevelseApi.ts | 4 ++- apps/frontend/src/api/TeamApi.ts | 29 ++++++++++++++----- apps/frontend/src/components/Lov.tsx | 4 +-- .../src/components/admin/audit/AuditPage.tsx | 7 +++-- .../admin/audit/AuditRecentTable.tsx | 4 ++- .../etterlevelse/EtterlevelseKravView.tsx | 4 +-- .../edit/EtterlevelseDokumentasjonForm.tsx | 4 ++- .../GjenbrukEtterlevelseDokumentasjonForm.tsx | 4 ++- .../krav/Edit/EditKravRelasjoner.tsx | 4 ++- .../components/krav/Edit/KravBegreperEdit.tsx | 4 ++- .../src/components/krav/Etterlevelser.tsx | 6 ++-- .../krav/tilbakemelding/Tilbakemelding.tsx | 12 ++++++-- .../VarslingsadresserEdit.tsx | 12 ++++++-- apps/frontend/src/pages/EtterlevelsePage.tsx | 14 ++++----- .../query/EtterlevelseDokumentasjonQuery.ts | 2 +- apps/frontend/src/query/KravQuery.ts | 2 +- apps/frontend/src/util/hooks/customHooks.ts | 12 ++++++-- apps/frontend/src/util/network.tsx | 4 ++- 19 files changed, 92 insertions(+), 44 deletions(-) diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 7c99b1c00..ad7f60b70 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -105,8 +105,8 @@ "@types/react-helmet": "^6.1.7", "@types/react-router-dom": "^5.3.3", "@types/yup": "^0.32.0", - "@typescript-eslint/eslint-plugin": "^7.1.1", - "@typescript-eslint/parser": "^7.1.1", + "@typescript-eslint/eslint-plugin": "^8.1.0", + "@typescript-eslint/parser": "^8.1.0", "autoprefixer": "^10.4.16", "eslint-config-react-app": "^7.0.1", "eslint-plugin-jsx-a11y": "^6.8.0", diff --git a/apps/frontend/src/api/EtterlevelseApi.ts b/apps/frontend/src/api/EtterlevelseApi.ts index 18ef0a9ca..d36e69a8a 100644 --- a/apps/frontend/src/api/EtterlevelseApi.ts +++ b/apps/frontend/src/api/EtterlevelseApi.ts @@ -74,7 +74,9 @@ export const useEtterlevelse = (id?: string, behandlingId?: string, kravId?: TKr ) useEffect(() => { - id && !isCreateNew && getEtterlevelse(id).then(setData) + if (id && !isCreateNew) { + getEtterlevelse(id).then(setData) + } }, [id]) return [data, setData] as [IEtterlevelse | undefined, (k: IEtterlevelse) => void] diff --git a/apps/frontend/src/api/TeamApi.ts b/apps/frontend/src/api/TeamApi.ts index 1023ff475..f4f756f8d 100644 --- a/apps/frontend/src/api/TeamApi.ts +++ b/apps/frontend/src/api/TeamApi.ts @@ -107,13 +107,24 @@ const addTeam = (team: ITeam) => { } const pSubscribe = (id: string, done: () => void) => { - !people.has(id) && people.set(id, { f: false, v: id }) - psubs.has(id) ? psubs.set(id, [...psubs.get(id)!, done]) : psubs.set(id, [done]) + if (!people.has(id)) { + people.set(id, { f: false, v: id }) + } + if (psubs.has(id)) { + psubs.set(id, [...psubs.get(id)!, done]) + } else { + psubs.set(id, [done]) + } } const tSubscribe = (id: string, done: () => void) => { - !teams.has(id) && + if (!teams.has(id)) { teams.set(id, { f: false, v: { id, name: id, description: '', members: [], tags: [] } }) - tsubs.has(id) ? tsubs.set(id, [...tsubs.get(id)!, done]) : tsubs.set(id, [done]) + } + if (tsubs.has(id)) { + tsubs.set(id, [...tsubs.get(id)!, done]) + } else { + tsubs.set(id, [done]) + } } export const usePersonName = () => { @@ -165,7 +176,7 @@ export const useMyTeams = () => { const ident = user.getIdent() useEffect(() => { - ident && + if (ident) { myTeams() .then((teamListe) => { if (teamListe.length === 0) { @@ -194,7 +205,9 @@ export const useMyTeams = () => { setLoading(false) console.error("couldn't find teams", error) }) - !ident && setLoading(false) + } else { + setLoading(false) + } }, [ident, productAreas]) return [data, loading] as [ITeam[], boolean] @@ -206,7 +219,7 @@ export const useMyProductAreas = () => { const ident = user.getIdent() useEffect(() => { - ident && + if (ident) { myProductArea() .then((r) => { setData(r) @@ -217,7 +230,7 @@ export const useMyProductAreas = () => { setLoading(false) console.error('couldn\t find product area', e) }) - !ident && setLoading(false) + } else setLoading(false) }, [ident]) return [data, loading] as [IProductArea[], boolean] diff --git a/apps/frontend/src/components/Lov.tsx b/apps/frontend/src/components/Lov.tsx index 9f0a2caaa..23c435f9b 100644 --- a/apps/frontend/src/components/Lov.tsx +++ b/apps/frontend/src/components/Lov.tsx @@ -4,9 +4,9 @@ import { EListName, codelist } from '../services/Codelist' import { env } from '../util/env' // unsure how to refactor code -// eslint-disable-next-line @typescript-eslint/no-var-requires +// eslint-disable-next-line @typescript-eslint/no-require-imports const reactProcessString = require('react-process-string') -// eslint-enable-next-line @typescript-eslint/no-var-requires +// eslint-enable-next-line @typescript-eslint/no-require-imports const processString = reactProcessString as ( converters: { regex: RegExp; fn: (key: string, result: string[]) => JSX.Element | string }[] ) => (input?: string) => JSX.Element[] diff --git a/apps/frontend/src/components/admin/audit/AuditPage.tsx b/apps/frontend/src/components/admin/audit/AuditPage.tsx index 4caf682b9..c46606a64 100644 --- a/apps/frontend/src/components/admin/audit/AuditPage.tsx +++ b/apps/frontend/src/components/admin/audit/AuditPage.tsx @@ -29,8 +29,11 @@ export const AuditPage = () => { setAuditLog(undefined) setError(undefined) if (!id) { - !!params.id && navigate('/admin/audit') - return + if (params.id) { + navigate('/admin/audit') + } else { + return + } } setLoading(true) try { diff --git a/apps/frontend/src/components/admin/audit/AuditRecentTable.tsx b/apps/frontend/src/components/admin/audit/AuditRecentTable.tsx index 7bb409007..6a82f7395 100644 --- a/apps/frontend/src/components/admin/audit/AuditRecentTable.tsx +++ b/apps/frontend/src/components/admin/audit/AuditRecentTable.tsx @@ -62,7 +62,9 @@ export const AuditRecentTable = (props: { show: boolean; tableType?: EObjectType useEffect(() => { ;(async () => { - props.show && setAudits(await getAudits(page - 1, limit, table)) + if (props.show) { + setAudits(await getAudits(page - 1, limit, table)) + } })() }, [page, limit, props.show, table]) diff --git a/apps/frontend/src/components/etterlevelse/EtterlevelseKravView.tsx b/apps/frontend/src/components/etterlevelse/EtterlevelseKravView.tsx index 526e459fa..d2b19063b 100644 --- a/apps/frontend/src/components/etterlevelse/EtterlevelseKravView.tsx +++ b/apps/frontend/src/components/etterlevelse/EtterlevelseKravView.tsx @@ -123,8 +123,7 @@ export const EtterlevelseKravView = (props: IProps) => { useEffect(() => { ;(async () => { - etterlevelseDokumentasjon?.id && - kravId.kravNummer && + if (etterlevelseDokumentasjon?.id && kravId.kravNummer) { getEtterlevelseMetadataByEtterlevelseDokumentasjonAndKravNummerAndKravVersion( etterlevelseDokumentasjon?.id, kravId.kravNummer, @@ -143,6 +142,7 @@ export const EtterlevelseKravView = (props: IProps) => { ) } }) + } })() if ( diff --git a/apps/frontend/src/components/etterlevelseDokumentasjon/edit/EtterlevelseDokumentasjonForm.tsx b/apps/frontend/src/components/etterlevelseDokumentasjon/edit/EtterlevelseDokumentasjonForm.tsx index b2dbb2839..9f8db3fc9 100644 --- a/apps/frontend/src/components/etterlevelseDokumentasjon/edit/EtterlevelseDokumentasjonForm.tsx +++ b/apps/frontend/src/components/etterlevelseDokumentasjon/edit/EtterlevelseDokumentasjonForm.tsx @@ -302,7 +302,9 @@ export const EtterlevelseDokumentasjonForm = (props: TEditEtterlevelseDokumentas isClearable={false} loadOptions={searchBehandlingOptions} onChange={(value) => { - value && fieldArrayRenderProps.push(value) + if (value) { + fieldArrayRenderProps.push(value) + } if (value && !values.avdeling && values.behandlinger?.length === 0) { const behandling = value as IBehandling const newAvdeling = { diff --git a/apps/frontend/src/components/etterlevelseDokumentasjon/edit/GjenbrukEtterlevelseDokumentasjonForm.tsx b/apps/frontend/src/components/etterlevelseDokumentasjon/edit/GjenbrukEtterlevelseDokumentasjonForm.tsx index 2d137b67c..b7bb2e617 100644 --- a/apps/frontend/src/components/etterlevelseDokumentasjon/edit/GjenbrukEtterlevelseDokumentasjonForm.tsx +++ b/apps/frontend/src/components/etterlevelseDokumentasjon/edit/GjenbrukEtterlevelseDokumentasjonForm.tsx @@ -133,7 +133,9 @@ export const GjenbrukEtterlevelseDokumentasjonForm = (props: IProps) => { isClearable={false} loadOptions={searchBehandlingOptions} onChange={(value) => { - value && fieldArrayRenderProps.push(value) + if (value) { + fieldArrayRenderProps.push(value) + } if (value && !values.avdeling && values.behandlinger?.length === 0) { const behandling = value as IBehandling const newAvdeling = { diff --git a/apps/frontend/src/components/krav/Edit/EditKravRelasjoner.tsx b/apps/frontend/src/components/krav/Edit/EditKravRelasjoner.tsx index 1703034c5..2dfcbf3fd 100644 --- a/apps/frontend/src/components/krav/Edit/EditKravRelasjoner.tsx +++ b/apps/frontend/src/components/krav/Edit/EditKravRelasjoner.tsx @@ -29,7 +29,9 @@ export const EditKravRelasjoner = () => { isClearable={false} loadOptions={useSearchKrav} onChange={(krav) => { - krav && fieldArrayRenderProps.push(krav) + if (krav) { + fieldArrayRenderProps.push(krav) + } }} styles={selectOverrides} /> diff --git a/apps/frontend/src/components/krav/Edit/KravBegreperEdit.tsx b/apps/frontend/src/components/krav/Edit/KravBegreperEdit.tsx index 9209a0785..0a10b4748 100644 --- a/apps/frontend/src/components/krav/Edit/KravBegreperEdit.tsx +++ b/apps/frontend/src/components/krav/Edit/KravBegreperEdit.tsx @@ -39,7 +39,9 @@ export const EditBegreper = () => { isClearable={false} loadOptions={useBegrepSearch} onChange={(begrep) => { - begrep && fieldArrayRenderProps.push(begrep) + if (begrep) { + fieldArrayRenderProps.push(begrep) + } }} styles={selectOverrides} /> diff --git a/apps/frontend/src/components/krav/Etterlevelser.tsx b/apps/frontend/src/components/krav/Etterlevelser.tsx index a9142da94..7844e7f49 100644 --- a/apps/frontend/src/components/krav/Etterlevelser.tsx +++ b/apps/frontend/src/components/krav/Etterlevelser.tsx @@ -67,15 +67,15 @@ export const Etterlevelser = ({ }, ] } - - etterlevelse.etterlevelseDokumentasjon.teamsData && + if (etterlevelse.etterlevelseDokumentasjon.teamsData) { etterlevelse.etterlevelseDokumentasjon.teamsData.forEach((t) => { if (!t.productAreaId && !t.productAreaName) { t.productAreaId = 'INGEN_PO' t.productAreaName = 'Ingen produktområde' } }) - return etterlevelse + return etterlevelse + } }) const filteredEtterlevelse = etterlevelser.filter((e) => { diff --git a/apps/frontend/src/components/krav/tilbakemelding/Tilbakemelding.tsx b/apps/frontend/src/components/krav/tilbakemelding/Tilbakemelding.tsx index 3b450a801..409d18f14 100644 --- a/apps/frontend/src/components/krav/tilbakemelding/Tilbakemelding.tsx +++ b/apps/frontend/src/components/krav/tilbakemelding/Tilbakemelding.tsx @@ -72,7 +72,9 @@ export const Tilbakemeldinger = ({ const refs = useRefs(tilbakemeldinger.map((tilbakemelding) => tilbakemelding.id)) useEffect(() => { - !loading && focusNr && setTimeout(() => refs[focusNr]?.current?.scrollIntoView(), 100) + if (!loading && focusNr) { + setTimeout(() => refs[focusNr]?.current?.scrollIntoView(), 100) + } }, [loading]) const setFocus = (id: string) => { @@ -178,7 +180,9 @@ export const Tilbakemeldinger = ({ setFocusNummer={setFocusNr} ubesvartOgKraveier={ubesvartOgKraveier} close={(t) => { - t && replace(t) + if (t) { + replace(t) + } }} remove={remove} replace={replace} @@ -243,7 +247,9 @@ export const Tilbakemeldinger = ({ krav={krav} open={addTilbakemelding} close={(t) => { - t && add(t) + if (t) { + add(t) + } setAddTilbakemelding(false) }} /> diff --git a/apps/frontend/src/components/varslingsadresse/VarslingsadresserEdit.tsx b/apps/frontend/src/components/varslingsadresse/VarslingsadresserEdit.tsx index 606641eca..4fa05503b 100644 --- a/apps/frontend/src/components/varslingsadresse/VarslingsadresserEdit.tsx +++ b/apps/frontend/src/components/varslingsadresse/VarslingsadresserEdit.tsx @@ -220,7 +220,9 @@ export const SlackChannelSearch = ({ add, close }: TAddVarslingsadresseProps) => onChange={(slackKanal) => { const channel = slackKanal as ISlackChannel if (channel) add({ type: EAdresseType.SLACK, adresse: channel.id }) - close && close() + if (close) { + close() + } }} styles={selectOverrides} /> @@ -237,7 +239,9 @@ export const SlackUserSearch = ({ add, close }: TAddVarslingsadresseProps) => { add({ type: EAdresseType.SLACK_USER, adresse: user.id }) setLoadingSlackId(false) setError('') - close && close() + if (close) { + close() + } }) .catch((e) => { setError('Fant ikke slack for bruker, error: ' + e.toString()) @@ -306,7 +310,9 @@ export const AddEmail = ({ added, add: doAdd, close }: TAddVarslingsadresseProps doAdd({ type: EAdresseType.EPOST, adresse: toAdd }) setVal('') } - close && close() + if (close) { + close() + } } const onKey = (e: React.KeyboardEvent) => e.key === 'Enter' && add() diff --git a/apps/frontend/src/pages/EtterlevelsePage.tsx b/apps/frontend/src/pages/EtterlevelsePage.tsx index 9e32c4cb9..c52a45b38 100644 --- a/apps/frontend/src/pages/EtterlevelsePage.tsx +++ b/apps/frontend/src/pages/EtterlevelsePage.tsx @@ -37,7 +37,13 @@ export const EtterlevelsePage = () => { } useEffect(() => { - etterlevelse && + if (etterlevelse) { + ampli.logEvent('sidevisning', { + side: 'Etterlevelse side', + sidetittel: getPageTitle(), + ...userRoleEventProp, + }) + getKravByKravNumberAndVersion(etterlevelse?.kravNummer, etterlevelse?.kravVersjon).then( (res) => { if (res) { @@ -49,12 +55,6 @@ export const EtterlevelsePage = () => { } } ) - if (etterlevelse) { - ampli.logEvent('sidevisning', { - side: 'Etterlevelse side', - sidetittel: getPageTitle(), - ...userRoleEventProp, - }) } }, [etterlevelse]) diff --git a/apps/frontend/src/query/EtterlevelseDokumentasjonQuery.ts b/apps/frontend/src/query/EtterlevelseDokumentasjonQuery.ts index 6c09bb01e..241a0f342 100644 --- a/apps/frontend/src/query/EtterlevelseDokumentasjonQuery.ts +++ b/apps/frontend/src/query/EtterlevelseDokumentasjonQuery.ts @@ -1,6 +1,6 @@ import { gql } from '@apollo/client' -// eslint-disable-next-line @typescript-eslint/ban-types +// eslint-disable-next-line "@typescript-eslint/no-restricted-types" export const getEtterlevelseDokumentasjonListQuery = gql` query getEtterlevelseDokumentasjoner( $pageNumber: NonNegativeInt diff --git a/apps/frontend/src/query/KravQuery.ts b/apps/frontend/src/query/KravQuery.ts index b648e3c92..d83880760 100644 --- a/apps/frontend/src/query/KravQuery.ts +++ b/apps/frontend/src/query/KravQuery.ts @@ -22,7 +22,7 @@ export const useKravCounter = ( }) } -// eslint-disable-next-line @typescript-eslint/ban-types +// eslint-disable-next-line "@typescript-eslint/no-restricted-types" const getKravtableQuery = gql` query getKravByFilter( $relevans: [String!] diff --git a/apps/frontend/src/util/hooks/customHooks.ts b/apps/frontend/src/util/hooks/customHooks.ts index d61381ded..daf5c5c9f 100644 --- a/apps/frontend/src/util/hooks/customHooks.ts +++ b/apps/frontend/src/util/hooks/customHooks.ts @@ -13,7 +13,9 @@ export function useDebouncedState( useEffect(() => { const handler = setTimeout(() => { setDebouncedValue(value) - passThrough && passThrough(value) + if (passThrough) { + passThrough(value) + } }, delay) return () => { clearTimeout(handler) @@ -41,10 +43,14 @@ export function useAwait(promise: Promise, setLoading?: Dispatch { ;(async () => { - setLoading && setLoading(true) + if (setLoading) { + setLoading(true) + } await promise update() - setLoading && setLoading(false) + if (setLoading) { + setLoading(false) + } })() }, []) } diff --git a/apps/frontend/src/util/network.tsx b/apps/frontend/src/util/network.tsx index eb4973e1a..8225661f1 100644 --- a/apps/frontend/src/util/network.tsx +++ b/apps/frontend/src/util/network.tsx @@ -22,7 +22,9 @@ const init = (onErr: (e: any) => void) => { export const useNetworkStatus = () => { const [error, setError] = useState() - !done && init(setError) + if (!done) { + init(setError) + } const clear = () => { setError(undefined)