Skip to content

Commit

Permalink
Merge pull request #374 from USEPA/feature/resolve-eslint-warnings
Browse files Browse the repository at this point in the history
Feature/resolve eslint warnings
  • Loading branch information
courtneymyers authored Oct 10, 2023
2 parents c32f4a6 + 3448630 commit 92c7901
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 21 deletions.
7 changes: 6 additions & 1 deletion app/client/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ module.exports = {
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
"no-extra-boolean-cast": "off",
"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 _
],
},
};
11 changes: 6 additions & 5 deletions app/client/src/components/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RebateYearProvider } from "@/contexts/rebateYear";

declare global {
interface Window {
csb: any;
csb?: { toggleReactQueryDevtools: () => void };
}
}

Expand All @@ -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 (
Expand All @@ -37,7 +38,7 @@ export function Providers(props: { children: ReactNode }) {
</NotificationsProvider>
</DialogProvider>

{devtoolsDisplayed && (
{reactQueryDevtoolsShown && (
<Suspense fallback={null}>
<ReactQueryDevtoolsProduction />
</Suspense>
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/contexts/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react-refresh/only-export-components */

import type { Dispatch, ReactNode } from "react";
import { createContext, useContext, useReducer } from "react";

Expand Down
2 changes: 2 additions & 0 deletions app/client/src/contexts/notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react-refresh/only-export-components */

import type { Dispatch, ReactNode } from "react";
import { createContext, useContext, useReducer } from "react";

Expand Down
2 changes: 2 additions & 0 deletions app/client/src/contexts/rebateYear.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react-refresh/only-export-components */

import type { Dispatch, ReactNode } from "react";
import { createContext, useContext, useReducer } from "react";

Expand Down
2 changes: 1 addition & 1 deletion app/client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "@/styles.css";

const container = document.getElementById("root") as HTMLElement;

function Index() {
export default function Index() {
return (
<StrictMode>
<ErrorBoundary>
Expand Down
5 changes: 4 additions & 1 deletion app/client/src/routes/crf2022.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 27 additions & 8 deletions app/client/src/routes/frf2022.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,25 @@ 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);
};

// 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,
Expand Down Expand Up @@ -423,8 +432,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,
Expand Down Expand Up @@ -502,8 +516,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)
Expand Down
5 changes: 4 additions & 1 deletion app/client/src/routes/frf2023.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion app/client/src/routes/prf2022.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions app/client/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export type Rebate =
};
};

async function fetchData<T = any>(url: string, options: RequestInit) {
async function fetchData<T = unknown>(url: string, options: RequestInit) {
try {
const response = await fetch(url, options);
const contentType = response.headers.get("content-type");
Expand All @@ -253,7 +253,7 @@ async function fetchData<T = any>(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<T = any>(url: string) {
export function getData<T = unknown>(url: string) {
return fetchData<T>(url, {
method: "GET",
credentials: "include" as const,
Expand All @@ -264,7 +264,7 @@ export function getData<T = any>(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<T = any>(url: string, data: object) {
export function postData<T = unknown>(url: string, data: object) {
return fetchData<T>(url, {
method: "POST",
credentials: "include" as const,
Expand Down

0 comments on commit 92c7901

Please sign in to comment.