style(v2): reduce number of ESLint warnings (#4993)

* Initial work

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

* More fixes

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

* Update packages/docusaurus-theme-classic/src/theme/ThemedImage/index.tsx

Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>

* Update packages/docusaurus-theme-bootstrap/src/theme/ThemedImage/index.tsx

Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>

* Fix

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

* Replace versionPathPart with function

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

* Prefer non-null assertions

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

* Substitute for-of with forEach

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

* Fill `catch` block with placeholder comment

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

* Ignore local require

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

* Revert global require change

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

* Tighten eslint disable range

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

* Make eslint ignore examples and more tolerating to templates

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

* Use reduce to handle doc items sequentially

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

* Revert "Use reduce to handle doc items sequentially"

This reverts commit c7525d463b.

* Address change requests

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

Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
This commit is contained in:
Joshua Chen 2021-06-25 00:12:48 +08:00 committed by GitHub
parent 364051f232
commit 462b1cf2bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 75 additions and 35 deletions

View file

@ -130,6 +130,7 @@ function doProcessDocMetadata({
// Strip number prefixes by default (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc) by default,
// but allow to disable this behavior with frontmatterr
// eslint-disable-next-line camelcase
parse_number_prefixes = true,
} = frontMatter;
@ -144,6 +145,7 @@ function doProcessDocMetadata({
// ex: myDoc -> .
const sourceDirName = path.dirname(source);
// eslint-disable-next-line camelcase
const {filename: unprefixedFileName, numberPrefix} = parse_number_prefixes
? options.numberPrefixParser(sourceFileNameWithoutExtension)
: {filename: sourceFileNameWithoutExtension, numberPrefix: undefined};
@ -172,6 +174,7 @@ function doProcessDocMetadata({
return undefined;
}
// Eventually remove the number prefixes from intermediate directories
// eslint-disable-next-line camelcase
return parse_number_prefixes
? stripPathNumberPrefixes(sourceDirName, options.numberPrefixParser)
: sourceDirName;

View file

@ -127,7 +127,10 @@ function assertIsCategory(
);
}
// "collapsed" is an optional property
if (item.hasOwnProperty('collapsed') && typeof item.collapsed !== 'boolean') {
if (
typeof item.collapsed !== 'undefined' &&
typeof item.collapsed !== 'boolean'
) {
throw new Error(
`Error loading ${JSON.stringify(item)}: "collapsed" must be a boolean.`,
);
@ -438,7 +441,20 @@ export function collectSidebarsDocIds(
});
}
export function createSidebarsUtils(sidebars: Sidebars) {
export function createSidebarsUtils(
sidebars: Sidebars,
): {
getFirstDocIdOfFirstSidebar: () => string | undefined;
getSidebarNameByDocId: (docId: string) => string | undefined;
getDocNavigation: (
docId: string,
) => {
sidebarName: string | undefined;
previousId: string | undefined;
nextId: string | undefined;
};
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
} {
const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
function getFirstDocIdOfFirstSidebar(): string | undefined {

View file

@ -187,6 +187,8 @@ export type LastUpdateData = {
};
export type DocFrontMatter = {
// Front matter uses snake case
/* eslint-disable camelcase */
id?: string;
title?: string;
hide_title?: boolean;
@ -200,6 +202,7 @@ export type DocFrontMatter = {
pagination_label?: string;
custom_edit_url?: string | null;
parse_number_prefixes?: boolean;
/* eslint-enable camelcase */
};
export type DocMetadataBase = LastUpdateData & {
@ -213,7 +216,6 @@ export type DocMetadataBase = LastUpdateData & {
sourceDirName: string; // relative to the docs folder (can be ".")
slug: string;
permalink: string;
// eslint-disable-next-line camelcase
sidebarPosition?: number;
editUrl?: string | null;
frontMatter: DocFrontMatter & Record<string, unknown>;

View file

@ -341,11 +341,13 @@ function createVersionMetadata({
// retro-compatible values
const defaultVersionLabel =
versionName === CURRENT_VERSION_NAME ? 'Next' : versionName;
const defaultVersionPathPart = isLast
? ''
: versionName === CURRENT_VERSION_NAME
? 'next'
: versionName;
function getDefaultVersionPathPart() {
if (isLast) {
return '';
}
return versionName === CURRENT_VERSION_NAME ? 'next' : versionName;
}
const defaultVersionPathPart = getDefaultVersionPathPart();
const versionOptions: VersionOptions = options.versions[versionName] ?? {};