mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-26 13:08:58 +02:00
chore(v2): Fix more eslint errors (#2976)
This commit is contained in:
parent
3611c96f90
commit
6e43c9bd34
81 changed files with 375 additions and 237 deletions
|
@ -45,8 +45,12 @@ function normalizeCategoryShorthand(
|
|||
/**
|
||||
* Check that item contains only allowed keys.
|
||||
*/
|
||||
function assertItem(item: Object, keys: string[]): void {
|
||||
function assertItem<K extends string>(
|
||||
item: any,
|
||||
keys: K[],
|
||||
): asserts item is Record<K, any> {
|
||||
const unknownKeys = Object.keys(item).filter(
|
||||
// @ts-expect-error: key is always string
|
||||
(key) => !keys.includes(key) && key !== 'type',
|
||||
);
|
||||
|
||||
|
@ -59,7 +63,9 @@ function assertItem(item: Object, keys: string[]): void {
|
|||
}
|
||||
}
|
||||
|
||||
function assertIsCategory(item: any): asserts item is SidebarItemCategoryRaw {
|
||||
function assertIsCategory(
|
||||
item: unknown,
|
||||
): asserts item is SidebarItemCategoryRaw {
|
||||
assertItem(item, ['items', 'label', 'collapsed']);
|
||||
if (typeof item.label !== 'string') {
|
||||
throw new Error(
|
||||
|
@ -79,7 +85,7 @@ function assertIsCategory(item: any): asserts item is SidebarItemCategoryRaw {
|
|||
}
|
||||
}
|
||||
|
||||
function assertIsDoc(item: any): asserts item is SidebarItemDoc {
|
||||
function assertIsDoc(item: unknown): asserts item is SidebarItemDoc {
|
||||
assertItem(item, ['id']);
|
||||
if (typeof item.id !== 'string') {
|
||||
throw new Error(
|
||||
|
@ -88,7 +94,7 @@ function assertIsDoc(item: any): asserts item is SidebarItemDoc {
|
|||
}
|
||||
}
|
||||
|
||||
function assertIsLink(item: any): asserts item is SidebarItemLink {
|
||||
function assertIsLink(item: unknown): asserts item is SidebarItemLink {
|
||||
assertItem(item, ['href', 'label']);
|
||||
if (typeof item.href !== 'string') {
|
||||
throw new Error(
|
||||
|
@ -175,7 +181,7 @@ export default function loadSidebars(sidebarPaths?: string[]): Sidebar {
|
|||
return {} as Sidebar;
|
||||
}
|
||||
|
||||
sidebarPaths.map((sidebarPath) => {
|
||||
sidebarPaths.forEach((sidebarPath) => {
|
||||
if (sidebarPath && fs.existsSync(sidebarPath)) {
|
||||
const sidebar = importFresh(sidebarPath) as SidebarRaw;
|
||||
Object.assign(allSidebars, sidebar);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue