From ddbf2192a2490a479673852dc96c1e3edd571231 Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Tue, 10 Oct 2023 08:55:34 -0400 Subject: [PATCH 1/5] Update eslint to allow unused args starting with _ --- app/client/.eslintrc.cjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/client/.eslintrc.cjs b/app/client/.eslintrc.cjs index 0949c679..96cb20cd 100644 --- a/app/client/.eslintrc.cjs +++ b/app/client/.eslintrc.cjs @@ -15,7 +15,11 @@ module.exports = { rules: { "react-refresh/only-export-components": [ "warn", - { allowConstantExport: true }, + { allowConstantExport: true }, // allow export const foo = 4 + ], + "@typescript-eslint/no-unused-vars": [ + "warn", + { argsIgnorePattern: "^_" }, // ignore unused args starting with _ ], }, }; From 447a9b3bad7cda0c7f52d5b2835965cc68c74339 Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Tue, 10 Oct 2023 08:56:40 -0400 Subject: [PATCH 2/5] Resolve eslint no-prototype-builtins error with using hasOwnProperty() directly on an object --- app/client/src/routes/frf2022.tsx | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/app/client/src/routes/frf2022.tsx b/app/client/src/routes/frf2022.tsx index 9053a539..c628b028 100644 --- a/app/client/src/routes/frf2022.tsx +++ b/app/client/src/routes/frf2022.tsx @@ -69,10 +69,16 @@ function useFormioSubmissionQueryAndMutation(mongoId: string | undefined) { return s3(s3Formio); }; - // remove `ncesDataSource` and `ncesDataLookup` fields const data = { ...res.submission?.data }; - if (data.hasOwnProperty("ncesDataSource")) delete data.ncesDataSource; - if (data.hasOwnProperty("ncesDataLookup")) delete data.ncesDataLookup; + + // remove `ncesDataSource` and `ncesDataLookup` fields + // (https://eslint.org/docs/latest/rules/no-prototype-builtins) + if (Object.prototype.hasOwnProperty.call(data, "ncesDataSource")) { + delete data.ncesDataSource; + } + if (Object.prototype.hasOwnProperty.call(data, "ncesDataLookup")) { + delete data.ncesDataLookup; + } return Promise.resolve({ ...res, @@ -423,8 +429,13 @@ function FundingRequestForm(props: { email: string }) { const data = { ...onSubmitSubmission.data }; // remove `ncesDataSource` and `ncesDataLookup` fields - if (data.hasOwnProperty("ncesDataSource")) delete data.ncesDataSource; // prettier-ignore - if (data.hasOwnProperty("ncesDataLookup")) delete data.ncesDataLookup; // prettier-ignore + // (https://eslint.org/docs/latest/rules/no-prototype-builtins) + if (Object.prototype.hasOwnProperty.call(data, "ncesDataSource")) { + delete data.ncesDataSource; + } + if (Object.prototype.hasOwnProperty.call(data, "ncesDataLookup")) { + delete data.ncesDataLookup; + } const updatedSubmission = { ...onSubmitSubmission, @@ -502,8 +513,13 @@ function FundingRequestForm(props: { email: string }) { const data = { ...onNextPageParam.submission.data }; // remove `ncesDataSource` and `ncesDataLookup` fields - if (data.hasOwnProperty("ncesDataSource")) delete data.ncesDataSource; // prettier-ignore - if (data.hasOwnProperty("ncesDataLookup")) delete data.ncesDataLookup; // prettier-ignore + // (https://eslint.org/docs/latest/rules/no-prototype-builtins) + if (Object.prototype.hasOwnProperty.call(data, "ncesDataSource")) { + delete data.ncesDataSource; + } + if (Object.prototype.hasOwnProperty.call(data, "ncesDataLookup")) { + delete data.ncesDataLookup; + } // "dirty check" – don't post an update if no changes have been made // to the form (ignoring current user fields) From fbca4b1ab7a06a1679fef505f5158a16d02117e3 Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Tue, 10 Oct 2023 11:33:52 -0400 Subject: [PATCH 3/5] Resolve eslint react-refresh/only-export-components warning --- app/client/src/contexts/dialog.tsx | 2 ++ app/client/src/contexts/notifications.tsx | 2 ++ app/client/src/contexts/rebateYear.tsx | 2 ++ app/client/src/index.tsx | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/client/src/contexts/dialog.tsx b/app/client/src/contexts/dialog.tsx index 20a59ad6..5cd25cb0 100644 --- a/app/client/src/contexts/dialog.tsx +++ b/app/client/src/contexts/dialog.tsx @@ -1,3 +1,5 @@ +/* eslint-disable react-refresh/only-export-components */ + import type { Dispatch, ReactNode } from "react"; import { createContext, useContext, useReducer } from "react"; diff --git a/app/client/src/contexts/notifications.tsx b/app/client/src/contexts/notifications.tsx index e1853627..6fc70863 100644 --- a/app/client/src/contexts/notifications.tsx +++ b/app/client/src/contexts/notifications.tsx @@ -1,3 +1,5 @@ +/* eslint-disable react-refresh/only-export-components */ + import type { Dispatch, ReactNode } from "react"; import { createContext, useContext, useReducer } from "react"; diff --git a/app/client/src/contexts/rebateYear.tsx b/app/client/src/contexts/rebateYear.tsx index d006e014..13f01636 100644 --- a/app/client/src/contexts/rebateYear.tsx +++ b/app/client/src/contexts/rebateYear.tsx @@ -1,3 +1,5 @@ +/* eslint-disable react-refresh/only-export-components */ + import type { Dispatch, ReactNode } from "react"; import { createContext, useContext, useReducer } from "react"; diff --git a/app/client/src/index.tsx b/app/client/src/index.tsx index f6636159..1e982891 100644 --- a/app/client/src/index.tsx +++ b/app/client/src/index.tsx @@ -18,7 +18,7 @@ import "@/styles.css"; const container = document.getElementById("root") as HTMLElement; -function Index() { +export default function Index() { return ( From 09771750231383103dd37865382bfdea474e018b Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Tue, 10 Oct 2023 13:19:18 -0400 Subject: [PATCH 4/5] Configure eslint to ignore no-extra-boolean-cast rule --- app/client/.eslintrc.cjs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/client/.eslintrc.cjs b/app/client/.eslintrc.cjs index 96cb20cd..40f0b070 100644 --- a/app/client/.eslintrc.cjs +++ b/app/client/.eslintrc.cjs @@ -13,6 +13,7 @@ module.exports = { parser: "@typescript-eslint/parser", plugins: ["react-refresh"], rules: { + "no-extra-boolean-cast": "off", "react-refresh/only-export-components": [ "warn", { allowConstantExport: true }, // allow export const foo = 4 From 3448630c6a300020814635ea5bf5efe041f7fc14 Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Tue, 10 Oct 2023 14:52:43 -0400 Subject: [PATCH 5/5] Update code to remove all use of any for types (resolves @typescript-eslint/no-explicit-any warnings) --- app/client/src/components/providers.tsx | 11 ++++++----- app/client/src/routes/crf2022.tsx | 5 ++++- app/client/src/routes/frf2022.tsx | 5 ++++- app/client/src/routes/frf2023.tsx | 5 ++++- app/client/src/routes/prf2022.tsx | 5 ++++- app/client/src/utilities.ts | 6 +++--- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/client/src/components/providers.tsx b/app/client/src/components/providers.tsx index 495e4cc6..02d078ca 100644 --- a/app/client/src/components/providers.tsx +++ b/app/client/src/components/providers.tsx @@ -8,7 +8,7 @@ import { RebateYearProvider } from "@/contexts/rebateYear"; declare global { interface Window { - csb: any; + csb?: { toggleReactQueryDevtools: () => void }; } } @@ -22,11 +22,12 @@ export function Providers(props: { children: ReactNode }) { const { children } = props; const [queryClient] = useState(() => new QueryClient()); - const [devtoolsDisplayed, setDevtoolsDisplayed] = useState(false); + const [reactQueryDevtoolsShown, setReactQueryDevtoolsShown] = useState(false); useEffect(() => { - window.csb ??= {}; - window.csb.toggleDevtools = () => setDevtoolsDisplayed((value) => !value); + window.csb ??= { + toggleReactQueryDevtools: () => setReactQueryDevtoolsShown((val) => !val), + }; }); return ( @@ -37,7 +38,7 @@ export function Providers(props: { children: ReactNode }) { - {devtoolsDisplayed && ( + {reactQueryDevtoolsShown && ( diff --git a/app/client/src/routes/crf2022.tsx b/app/client/src/routes/crf2022.tsx index 63da1ca5..86597dfe 100644 --- a/app/client/src/routes/crf2022.tsx +++ b/app/client/src/routes/crf2022.tsx @@ -63,7 +63,10 @@ function useFormioSubmissionQueryAndMutation(rebateId: string | undefined) { * https://github.com/formio/formio.js/blob/master/src/providers/storage/s3.js#L5 * https://github.com/formio/formio.js/blob/master/src/providers/storage/xhr.js#L90 */ - Formio.Providers.providers.storage.s3 = function (formio: any) { + Formio.Providers.providers.storage.s3 = function (formio: { + formUrl: string; + [field: string]: unknown; + }) { const s3Formio = cloneDeep(formio); s3Formio.formUrl = `${serverUrl}/api/formio/2022/s3/crf/${mongoId}/${comboKey}`; return s3(s3Formio); diff --git a/app/client/src/routes/frf2022.tsx b/app/client/src/routes/frf2022.tsx index c628b028..1c72d84d 100644 --- a/app/client/src/routes/frf2022.tsx +++ b/app/client/src/routes/frf2022.tsx @@ -63,7 +63,10 @@ function useFormioSubmissionQueryAndMutation(mongoId: string | undefined) { * https://github.com/formio/formio.js/blob/master/src/providers/storage/s3.js#L5 * https://github.com/formio/formio.js/blob/master/src/providers/storage/xhr.js#L90 */ - Formio.Providers.providers.storage.s3 = function (formio: any) { + Formio.Providers.providers.storage.s3 = function (formio: { + formUrl: string; + [field: string]: unknown; + }) { const s3Formio = cloneDeep(formio); s3Formio.formUrl = `${serverUrl}/api/formio/2022/s3/frf/${mongoId}/${comboKey}`; return s3(s3Formio); diff --git a/app/client/src/routes/frf2023.tsx b/app/client/src/routes/frf2023.tsx index fa13aca5..5226cbb8 100644 --- a/app/client/src/routes/frf2023.tsx +++ b/app/client/src/routes/frf2023.tsx @@ -62,7 +62,10 @@ function useFormioSubmissionQueryAndMutation(mongoId: string | undefined) { * https://github.com/formio/formio.js/blob/master/src/providers/storage/s3.js#L5 * https://github.com/formio/formio.js/blob/master/src/providers/storage/xhr.js#L90 */ - Formio.Providers.providers.storage.s3 = function (formio: any) { + Formio.Providers.providers.storage.s3 = function (formio: { + formUrl: string; + [field: string]: unknown; + }) { const s3Formio = cloneDeep(formio); s3Formio.formUrl = `${serverUrl}/api/formio/2023/s3/frf/${mongoId}/${comboKey}`; return s3(s3Formio); diff --git a/app/client/src/routes/prf2022.tsx b/app/client/src/routes/prf2022.tsx index c597142b..a7502314 100644 --- a/app/client/src/routes/prf2022.tsx +++ b/app/client/src/routes/prf2022.tsx @@ -63,7 +63,10 @@ function useFormioSubmissionQueryAndMutation(rebateId: string | undefined) { * https://github.com/formio/formio.js/blob/master/src/providers/storage/s3.js#L5 * https://github.com/formio/formio.js/blob/master/src/providers/storage/xhr.js#L90 */ - Formio.Providers.providers.storage.s3 = function (formio: any) { + Formio.Providers.providers.storage.s3 = function (formio: { + formUrl: string; + [field: string]: unknown; + }) { const s3Formio = cloneDeep(formio); s3Formio.formUrl = `${serverUrl}/api/formio/2022/s3/prf/${mongoId}/${comboKey}`; return s3(s3Formio); diff --git a/app/client/src/utilities.ts b/app/client/src/utilities.ts index c90058d9..6c7fa015 100644 --- a/app/client/src/utilities.ts +++ b/app/client/src/utilities.ts @@ -236,7 +236,7 @@ export type Rebate = }; }; -async function fetchData(url: string, options: RequestInit) { +async function fetchData(url: string, options: RequestInit) { try { const response = await fetch(url, options); const contentType = response.headers.get("content-type"); @@ -253,7 +253,7 @@ async function fetchData(url: string, options: RequestInit) { * Fetches data and returns a promise containing JSON fetched from a provided * web service URL or handles any other OK response returned from the server */ -export function getData(url: string) { +export function getData(url: string) { return fetchData(url, { method: "GET", credentials: "include" as const, @@ -264,7 +264,7 @@ export function getData(url: string) { * Posts JSON data and returns a promise containing JSON fetched from a provided * web service URL or handles any other OK response returned from the server */ -export function postData(url: string, data: object) { +export function postData(url: string, data: object) { return fetchData(url, { method: "POST", credentials: "include" as const,