refactor: clear a few ESLint warnings (#5808)

* refactor: clear a few ESLint warnings

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

* Fix
This commit is contained in:
Joshua Chen 2021-10-28 12:47:40 +08:00 committed by GitHub
parent 68c970175a
commit 4b2152a964
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 26 deletions

View file

@ -6,6 +6,7 @@
*/ */
declare module '@generated/client-modules' { declare module '@generated/client-modules' {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const clientModules: readonly any[]; const clientModules: readonly any[];
export default clientModules; export default clientModules;
} }
@ -26,6 +27,7 @@ declare module '@generated/site-metadata' {
declare module '@generated/registry' { declare module '@generated/registry' {
const registry: { const registry: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly [key: string]: [() => Promise<any>, string, string]; readonly [key: string]: [() => Promise<any>, string, string];
}; };
export default registry; export default registry;
@ -50,7 +52,8 @@ declare module '@generated/routesChunkNames' {
} }
declare module '@generated/globalData' { declare module '@generated/globalData' {
const globalData: Record<string, unknown>; // eslint-disable-next-line @typescript-eslint/no-explicit-any
const globalData: Record<string, any>;
export default globalData; export default globalData;
} }
@ -89,7 +92,7 @@ declare module '@theme/Loading' {
} }
declare module '@theme/NotFound' { declare module '@theme/NotFound' {
export default function NotFound(props: any): JSX.Element; export default function NotFound(): JSX.Element;
} }
declare module '@theme/Root' { declare module '@theme/Root' {
@ -292,6 +295,7 @@ declare module '@docusaurus/useGlobalData' {
pluginId?: string, pluginId?: string,
): T; ): T;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function useGlobalData(): Record<string, any>; function useGlobalData(): Record<string, any>;
export default useGlobalData; export default useGlobalData;
} }

View file

@ -59,13 +59,13 @@ function validateCollectedRedirects(
redirects: RedirectMetadata[], redirects: RedirectMetadata[],
pluginContext: PluginContext, pluginContext: PluginContext,
) { ) {
const redirectValidationErrors: string[] = redirects const redirectValidationErrors = redirects
.map((redirect) => { .map((redirect) => {
try { try {
validateRedirect(redirect); validateRedirect(redirect);
return undefined; return undefined;
} catch (e: any) { } catch (e) {
return e.message; return (e as Error).message;
} }
}) })
.filter(Boolean); .filter(Boolean);

View file

@ -148,7 +148,7 @@ function DocPage(props: Props): JSX.Element {
matchPath(location.pathname, docRoute), matchPath(location.pathname, docRoute),
); );
if (!currentDocRoute) { if (!currentDocRoute) {
return <NotFound {...props} />; return <NotFound />;
} }
return ( return (
<> <>

View file

@ -26,8 +26,8 @@ function getBrowserStorage(
} else { } else {
try { try {
return window[storageType]; return window[storageType];
} catch (e: any) { } catch (e) {
logOnceBrowserStorageNotAvailableWarning(e); logOnceBrowserStorageNotAvailableWarning(e as Error);
return null; return null;
} }
} }

View file

@ -181,9 +181,9 @@ export async function parseMarkdownFile(
const markdownString = await fs.readFile(source, 'utf-8'); const markdownString = await fs.readFile(source, 'utf-8');
try { try {
return parseMarkdownString(markdownString, options); return parseMarkdownString(markdownString, options);
} catch (e: any) { } catch (e) {
throw new Error( throw new Error(
`Error while parsing Markdown file ${source}: "${e.message}".`, `Error while parsing Markdown file ${source}: "${(e as Error).message}".`,
); );
} }
} }

View file

@ -55,9 +55,10 @@ export async function readTranslationFileContent(
const content = JSON.parse(await fs.readFile(filePath, 'utf8')); const content = JSON.parse(await fs.readFile(filePath, 'utf8'));
ensureTranslationFileContent(content); ensureTranslationFileContent(content);
return content; return content;
// eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e) {
} catch (e: any) { throw new Error(
throw new Error(`Invalid translation file at ${filePath}.\n${e.message}`); `Invalid translation file at ${filePath}.\n${(e as Error).message}`,
);
} }
} }
return undefined; return undefined;

View file

@ -157,10 +157,15 @@ export async function extractSourceCodeFileTranslations(
filename: sourceCodeFilePath, filename: sourceCodeFilePath,
}) as Node; }) as Node;
return await extractSourceCodeAstTranslations(ast, sourceCodeFilePath); const translations = await extractSourceCodeAstTranslations(
// eslint-disable-next-line @typescript-eslint/no-explicit-any ast,
} catch (e: any) { sourceCodeFilePath,
e.message = `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}\n${e.message}`; );
return translations;
} catch (e) {
if (e instanceof Error) {
e.message = `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}\n${e.message}`;
}
throw e; throw e;
} }
} }

View file

@ -234,11 +234,10 @@ class CleanWebpackPlugin {
console.warn(`clean-webpack-plugin: removed ${filename}`); console.warn(`clean-webpack-plugin: removed ${filename}`);
}); });
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error) {
} catch (error: any) {
const needsForce = const needsForce =
/Cannot delete files\/folders outside the current working directory\./.test( /Cannot delete files\/folders outside the current working directory\./.test(
error.message, (error as Error).message,
); );
if (needsForce) { if (needsForce) {

View file

@ -457,21 +457,21 @@ function validateKeyAndCerts({
try { try {
// publicEncrypt will throw an error with an invalid cert // publicEncrypt will throw an error with an invalid cert
encrypted = crypto.publicEncrypt(cert, Buffer.from('test')); encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
// eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err) {
} catch (err: any) {
throw new Error( throw new Error(
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`, `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${
(err as Error).message
}`,
); );
} }
try { try {
// privateDecrypt will throw an error with an invalid key // privateDecrypt will throw an error with an invalid key
crypto.privateDecrypt(key, encrypted); crypto.privateDecrypt(key, encrypted);
// eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err) {
} catch (err: any) {
throw new Error( throw new Error(
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${ `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
err.message (err as Error).message
}`, }`,
); );
} }