Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clear a few ESLint warnings #5808

Merged
merged 2 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

declare module '@generated/client-modules' {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const clientModules: readonly any[];
export default clientModules;
}
Expand All @@ -26,6 +27,7 @@ declare module '@generated/site-metadata' {

declare module '@generated/registry' {
const registry: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly [key: string]: [() => Promise<any>, string, string];
};
export default registry;
Expand All @@ -50,7 +52,8 @@ declare module '@generated/routesChunkNames' {
}

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;
}

Expand Down Expand Up @@ -89,7 +92,7 @@ declare module '@theme/Loading' {
}

declare module '@theme/NotFound' {
export default function NotFound(props: any): JSX.Element;
export default function NotFound(): JSX.Element;
}

declare module '@theme/Root' {
Expand Down Expand Up @@ -292,6 +295,7 @@ declare module '@docusaurus/useGlobalData' {
pluginId?: string,
): T;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function useGlobalData(): Record<string, any>;
export default useGlobalData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ function validateCollectedRedirects(
redirects: RedirectMetadata[],
pluginContext: PluginContext,
) {
const redirectValidationErrors: string[] = redirects
const redirectValidationErrors = redirects
.map((redirect) => {
try {
validateRedirect(redirect);
return undefined;
} catch (e: any) {
return e.message;
} catch (e) {
return (e as Error).message;
}
})
.filter(Boolean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function DocPage(props: Props): JSX.Element {
matchPath(location.pathname, docRoute),
);
if (!currentDocRoute) {
return <NotFound {...props} />;
return <NotFound />;
}
return (
<>
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-theme-common/src/utils/storageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function getBrowserStorage(
} else {
try {
return window[storageType];
} catch (e: any) {
logOnceBrowserStorageNotAvailableWarning(e);
} catch (e) {
logOnceBrowserStorageNotAvailableWarning(e as Error);
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-utils/src/markdownParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ export async function parseMarkdownFile(
const markdownString = await fs.readFile(source, 'utf-8');
try {
return parseMarkdownString(markdownString, options);
} catch (e: any) {
} catch (e) {
throw new Error(
`Error while parsing Markdown file ${source}: "${e.message}".`,
`Error while parsing Markdown file ${source}: "${(e as Error).message}".`,
);
}
}
7 changes: 4 additions & 3 deletions packages/docusaurus/src/server/translations/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export async function readTranslationFileContent(
const content = JSON.parse(await fs.readFile(filePath, 'utf8'));
ensureTranslationFileContent(content);
return content;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
throw new Error(`Invalid translation file at ${filePath}.\n${e.message}`);
} catch (e) {
throw new Error(
`Invalid translation file at ${filePath}.\n${(e as Error).message}`,
);
}
}
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,15 @@ export async function extractSourceCodeFileTranslations(
filename: sourceCodeFilePath,
}) as Node;

return await extractSourceCodeAstTranslations(ast, sourceCodeFilePath);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
e.message = `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}\n${e.message}`;
const translations = await extractSourceCodeAstTranslations(
ast,
sourceCodeFilePath,
);
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,10 @@ class CleanWebpackPlugin {
console.warn(`clean-webpack-plugin: removed ${filename}`);
});
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
} catch (error) {
const needsForce =
/Cannot delete files\/folders outside the current working directory\./.test(
error.message,
(error as Error).message,
);

if (needsForce) {
Expand Down
12 changes: 6 additions & 6 deletions packages/docusaurus/src/webpack/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,21 +459,21 @@ function validateKeyAndCerts({
try {
// publicEncrypt will throw an error with an invalid cert
encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
} catch (err) {
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 {
// privateDecrypt will throw an error with an invalid key
crypto.privateDecrypt(key, encrypted);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
} catch (err) {
throw new Error(
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
err.message
(err as Error).message
}`,
);
}
Expand Down