chore(v2): Fix linter warnings (#4442)

* chore(v2): Fix linter warnings

223 warnings to 145 warnings

* Remove explicit type annotations

* Do not prefetch when targetLink == null
This commit is contained in:
Sam Zhou 2021-03-17 12:28:42 -04:00 committed by GitHub
parent f041a37622
commit 5e73c72f26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 146 additions and 71 deletions

View file

@ -120,7 +120,10 @@ export function processDocMetadata({
const docsFileDirName = path.dirname(source);
const {frontMatter = {}, excerpt} = parseMarkdownString(content);
const {sidebar_label, custom_edit_url} = frontMatter;
const {
sidebar_label: sidebarLabel,
custom_edit_url: customEditURL,
} = frontMatter;
const baseID: string =
frontMatter.id || path.basename(source, path.extname(source));
@ -206,7 +209,7 @@ export function processDocMetadata({
source: aliasedSitePath(filePath, siteDir),
slug: docSlug,
permalink,
editUrl: custom_edit_url !== undefined ? custom_edit_url : getDocEditUrl(),
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
version: versionMetadata.versionName,
lastUpdatedBy: lastUpdate.lastUpdatedBy,
lastUpdatedAt: lastUpdate.lastUpdatedAt,
@ -215,6 +218,6 @@ export function processDocMetadata({
lastUpdate.lastUpdatedAt * 1000,
)
: undefined,
sidebar_label,
sidebar_label: sidebarLabel,
};
}

View file

@ -22,7 +22,7 @@ declare module '@docusaurus/plugin-content-docs-types' {
};
type PropsSidebarItemBase = {
customProps?: object;
customProps?: Record<string, unknown>;
};
export type PropSidebarItemLink = PropsSidebarItemBase & {

View file

@ -33,11 +33,11 @@ Available document ids=
);
}
const {title, permalink, sidebar_label} = docMetadata;
const {title, permalink, sidebar_label: sidebarLabel} = docMetadata;
return {
type: 'link',
label: sidebar_label || title,
label: sidebarLabel || title,
href: permalink,
customProps: item.customProps,
};

View file

@ -76,7 +76,7 @@ function normalizeCategoryShorthand(
* Check that item contains only allowed keys.
*/
function assertItem<K extends string>(
item: any,
item: Record<string, unknown>,
keys: K[],
): asserts item is Record<K, any> {
const unknownKeys = Object.keys(item).filter(
@ -94,7 +94,7 @@ function assertItem<K extends string>(
}
function assertIsCategory(
item: unknown,
item: Record<string, unknown>,
): asserts item is SidebarItemCategoryJSON {
assertItem(item, ['items', 'label', 'collapsed', 'customProps']);
if (typeof item.label !== 'string') {
@ -115,7 +115,9 @@ function assertIsCategory(
}
}
function assertIsDoc(item: unknown): asserts item is SidebarItemDoc {
function assertIsDoc(
item: Record<string, unknown>,
): asserts item is SidebarItemDoc {
assertItem(item, ['id', 'customProps']);
if (typeof item.id !== 'string') {
throw new Error(
@ -124,7 +126,9 @@ function assertIsDoc(item: unknown): asserts item is SidebarItemDoc {
}
}
function assertIsLink(item: unknown): asserts item is SidebarItemLink {
function assertIsLink(
item: Record<string, unknown>,
): asserts item is SidebarItemLink {
assertItem(item, ['href', 'label', 'customProps']);
if (typeof item.href !== 'string') {
throw new Error(

View file

@ -27,7 +27,7 @@ import {
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
useAllPluginInstancesData('docusaurus-plugin-content-docs');
export const useDocsData = (pluginId: string | undefined) =>
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
export const useActivePlugin = (

View file

@ -94,7 +94,7 @@ export type PluginOptions = MetadataOptions &
};
export type SidebarItemBase = {
customProps?: object;
customProps?: Record<string, unknown>;
};
export type SidebarItemDoc = SidebarItemBase & {
@ -147,6 +147,7 @@ export type DocMetadataBase = LastUpdateData & {
source: string;
slug: string;
permalink: string;
// eslint-disable-next-line camelcase
sidebar_label?: string;
editUrl?: string | null;
};

View file

@ -427,7 +427,7 @@ function filterVersions(
) {
if (options.onlyIncludeVersions) {
return versionNamesUnfiltered.filter((name) =>
options.onlyIncludeVersions!.includes(name),
(options.onlyIncludeVersions || []).includes(name),
);
} else {
return versionNamesUnfiltered;