Skip to content

Commit

Permalink
[web] Upgrade eslint ruleset for accounts app (#2102)
Browse files Browse the repository at this point in the history
Only one workaround remains.
  • Loading branch information
mnvr authored Jun 11, 2024
2 parents 624a8bf + 309d332 commit 1a43c0f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 38 deletions.
11 changes: 0 additions & 11 deletions web/apps/accounts/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ module.exports = {
ignorePatterns: ["next.config.js", "next-env.d.ts"],
/* TODO: Temporary overrides */
rules: {
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"react-hooks/exhaustive-deps": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"react-refresh/only-export-components": "off",
},
};
15 changes: 15 additions & 0 deletions web/apps/accounts/src/components/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { BaseAppContextT } from "@/next/types/app";
import { ensure } from "@/utils/ensure";
import { createContext, useContext } from "react";

/** The accounts app has no extra properties on top of the base context. */
type AppContextT = BaseAppContextT;

/** The React {@link Context} available to all pages. */
export const AppContext = createContext<AppContextT | undefined>(undefined);

/**
* Utility hook to get the {@link AppContextT}, throwing an exception if it is
* not defined.
*/
export const useAppContext = (): AppContextT => ensure(useContext(AppContext));
29 changes: 11 additions & 18 deletions web/apps/accounts/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { CustomHead } from "@/next/components/Head";
import { setupI18n } from "@/next/i18n";
import { logUnhandledErrorsAndRejections } from "@/next/log-web";
import { appTitle, type AppName, type BaseAppContextT } from "@/next/types/app";
import { ensure } from "@/utils/ensure";
import { appTitle, type AppName } from "@/next/types/app";
import { PAGES } from "@ente/accounts/constants/pages";
import { accountLogout } from "@ente/accounts/services/logout";
import { Overlay } from "@ente/shared/components/Container";
Expand All @@ -16,22 +15,15 @@ import { getTheme } from "@ente/shared/themes";
import { THEME_COLOR } from "@ente/shared/themes/constants";
import { CssBaseline, useMediaQuery } from "@mui/material";
import { ThemeProvider } from "@mui/material/styles";
import { AppContext } from "components/context";
import { t } from "i18next";
import type { AppProps } from "next/app";
import { useRouter } from "next/router";
import { createContext, useContext, useEffect, useState } from "react";
import "styles/global.css";

/** The accounts app has no extra properties on top of the base context. */
type AppContextT = BaseAppContextT;

/** The React {@link Context} available to all pages. */
export const AppContext = createContext<AppContextT | undefined>(undefined);
import React, { useEffect, useState } from "react";

/** Utility hook to reduce amount of boilerplate in account related pages. */
export const useAppContext = () => ensure(useContext(AppContext));
import "styles/global.css";

export default function App({ Component, pageProps }: AppProps) {
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const appName: AppName = "accounts";

const [isI18nReady, setIsI18nReady] = useState<boolean>(false);
Expand All @@ -57,7 +49,7 @@ export default function App({ Component, pageProps }: AppProps) {
const [themeColor] = useLocalState(LS_KEYS.THEME, THEME_COLOR.DARK);

useEffect(() => {
setupI18n().finally(() => setIsI18nReady(true));
void setupI18n().finally(() => setIsI18nReady(true));
logUnhandledErrorsAndRejections(true);
return () => logUnhandledErrorsAndRejections(false);
}, []);
Expand Down Expand Up @@ -92,7 +84,7 @@ export default function App({ Component, pageProps }: AppProps) {
sx={{ zIndex: 1600 }}
open={dialogBoxV2View}
onClose={closeDialogBoxV2}
attributes={dialogBoxAttributeV2 as any}
attributes={dialogBoxAttributeV2}
/>

<AppContext.Provider value={appContext}>
Expand All @@ -103,8 +95,7 @@ export default function App({ Component, pageProps }: AppProps) {
justifyContent: "center",
alignItems: "center",
zIndex: 2000,
backgroundColor: (theme as any).colors
.background.base,
backgroundColor: theme.colors.background.base,
})}
>
<EnteSpinner />
Expand All @@ -116,4 +107,6 @@ export default function App({ Component, pageProps }: AppProps) {
</ThemeProvider>
</>
);
}
};

export default App;
2 changes: 1 addition & 1 deletion web/apps/accounts/src/pages/passkeys/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
import KeyIcon from "@mui/icons-material/Key";
import { Box, Button, Stack, Typography, useMediaQuery } from "@mui/material";
import { useAppContext } from "components/context";
import { t } from "i18next";
import { useAppContext } from "pages/_app";
import React, { useEffect, useState } from "react";
import {
deletePasskey,
Expand Down
4 changes: 2 additions & 2 deletions web/apps/accounts/src/pages/passkeys/verify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import EnteSpinner from "@ente/shared/components/EnteSpinner";
import InfoIcon from "@mui/icons-material/Info";
import { Paper, Typography, styled } from "@mui/material";
import { t } from "i18next";
import { useEffect, useState } from "react";
import React, { useEffect, useState } from "react";
import {
beginPasskeyAuthentication,
finishPasskeyAuthentication,
Expand Down Expand Up @@ -50,7 +50,7 @@ const Page = () => {
// Ensure that redirectURL is whitelisted, otherwise show an invalid
// "login" URL error to the user.
if (!redirectURL || !isWhitelistedRedirect(redirectURL)) {
log.error(`Redirect URL '${redirectURL}' is not whitelisted`);
log.error(`Redirect '${redirect}' is not whitelisted`);
setStatus("unknownRedirect");
return;
}
Expand Down
16 changes: 12 additions & 4 deletions web/apps/auth/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ import { ThemeProvider } from "@mui/material/styles";
import { t } from "i18next";
import type { AppProps } from "next/app";
import { useRouter } from "next/router";
import { createContext, useContext, useEffect, useRef, useState } from "react";
import React, {
createContext,
useContext,
useEffect,
useRef,
useState,
} from "react";
import LoadingBar, { type LoadingBarRef } from "react-top-loading-bar";
import "../../public/css/global.css";

Expand All @@ -52,7 +58,7 @@ export const AppContext = createContext<AppContextT | undefined>(undefined);
/** Utility hook to reduce amount of boilerplate in account related pages. */
export const useAppContext = () => ensure(useContext(AppContext));

export default function App({ Component, pageProps }: AppProps) {
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const appName: AppName = "auth";

const router = useRouter();
Expand All @@ -75,7 +81,7 @@ export default function App({ Component, pageProps }: AppProps) {
);

useEffect(() => {
setupI18n().finally(() => setIsI18nReady(true));
void setupI18n().finally(() => setIsI18nReady(true));
const userId = (getData(LS_KEYS.USER) as User)?.id;
logStartupBanner(appName, userId);
logUnhandledErrorsAndRejections(true);
Expand Down Expand Up @@ -198,4 +204,6 @@ export default function App({ Component, pageProps }: AppProps) {
</ThemeProvider>
</>
);
}
};

export default App;
2 changes: 1 addition & 1 deletion web/apps/photos/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default function App({ Component, pageProps }: AppProps) {
);

useEffect(() => {
setupI18n().finally(() => setIsI18nReady(true));
void setupI18n().finally(() => setIsI18nReady(true));
const userId = (getData(LS_KEYS.USER) as User)?.id;
logStartupBanner(appName, userId);
logUnhandledErrorsAndRejections(true);
Expand Down
15 changes: 15 additions & 0 deletions web/packages/build-config/eslintrc-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,20 @@ module.exports = {
ignoreArrowShorthand: true,
},
],
/*
Allow async functions to be passed as JSX attributes expected to be
functions that return void (typically onFoo event handlers).
This should be safe since we have registered global unhandled Promise
handlers.
*/
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: {
attributes: false,
},
},
],
},
};
2 changes: 1 addition & 1 deletion web/packages/shared/components/DialogBoxV2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface DialogBoxAttributesV2 {
title?: React.ReactNode;
staticBackdrop?: boolean;
nonClosable?: boolean;
content?: any;
content?: React.ReactNode;
close?: {
text?: string;
variant?: ButtonProps["color"];
Expand Down

0 comments on commit 1a43c0f

Please sign in to comment.