Skip to content

Commit

Permalink
fix: correct some of type errors reported by eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Mar 10, 2021
1 parent b7a6665 commit 5beb7b8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type RedirectFileMetadata = {
fileContent: string;
};

export function createToUrl(baseUrl: string, to: string) {
export function createToUrl(baseUrl: string, to: string): string {
return normalizeUrl([baseUrl, to]);
}

Expand Down
24 changes: 18 additions & 6 deletions packages/docusaurus-plugin-content-docs/src/theme/hooks/useDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import {
getActiveVersion,
getActiveDocContext,
getDocVersionSuggestions,
GetActivePluginOptions,
ActivePlugin,
ActiveDocContext,
DocVersionSuggestions,
GetActivePluginOptions,
} from '../../client/docsClientUtils';

export const useAllDocsData = (): Record<string, GlobalPluginData> =>
Expand All @@ -28,7 +30,9 @@ export const useAllDocsData = (): Record<string, GlobalPluginData> =>
export const useDocsData = (pluginId: string | undefined) =>
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;

export const useActivePlugin = (options: GetActivePluginOptions = {}) => {
export const useActivePlugin = (
options: GetActivePluginOptions = {},
): ActivePlugin | undefined => {
const data = useAllDocsData();
const {pathname} = useLocation();
return getActivePlugin(data, pathname, options);
Expand Down Expand Up @@ -57,27 +61,35 @@ export const useVersions = (pluginId: string | undefined): GlobalVersion[] => {
return data.versions;
};

export const useLatestVersion = (pluginId: string | undefined) => {
export const useLatestVersion = (
pluginId: string | undefined,
): GlobalVersion => {
const data = useDocsData(pluginId);
return getLatestVersion(data);
};

// Note: return undefined on doc-unrelated pages,
// because there's no version currently considered as active
export const useActiveVersion = (pluginId: string | undefined) => {
export const useActiveVersion = (
pluginId: string | undefined,
): GlobalVersion | undefined => {
const data = useDocsData(pluginId);
const {pathname} = useLocation();
return getActiveVersion(data, pathname);
};

export const useActiveDocContext = (pluginId: string | undefined) => {
export const useActiveDocContext = (
pluginId: string | undefined,
): ActiveDocContext => {
const data = useDocsData(pluginId);
const {pathname} = useLocation();
return getActiveDocContext(data, pathname);
};

// Useful to say "hey, you are not on the latest docs version, please switch"
export const useDocVersionSuggestions = (pluginId: string | undefined) => {
export const useDocVersionSuggestions = (
pluginId: string | undefined,
): DocVersionSuggestions => {
const data = useDocsData(pluginId);
const {pathname} = useLocation();
return getDocVersionSuggestions(data, pathname);
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-utils-validation/src/validationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const logValidationBugReportHint = (): void => {
export function normalizePluginOptions<T extends {id?: string}>(
schema: Joi.ObjectSchema<T>,
options: unknown,
) {
): T {
// All plugins can be provided an "id" option (multi-instance support)
// we add schema validation automatically
const finalSchema = schema.append({
Expand All @@ -51,7 +51,7 @@ export function normalizePluginOptions<T extends {id?: string}>(
logValidationBugReportHint();
if (isValidationDisabledEscapeHatch) {
console.error(error);
return options;
return options as T;
} else {
throw error;
}
Expand All @@ -62,7 +62,7 @@ export function normalizePluginOptions<T extends {id?: string}>(
export function normalizeThemeConfig<T>(
schema: Joi.ObjectSchema<T>,
themeConfig: unknown,
) {
): T {
// A theme should only validate his "slice" of the full themeConfig,
// not the whole object, so we allow unknown attributes
// otherwise one theme would fail validating the data of another theme
Expand All @@ -76,7 +76,7 @@ export function normalizeThemeConfig<T>(
logValidationBugReportHint();
if (isValidationDisabledEscapeHatch) {
console.error(error);
return themeConfig;
return themeConfig as T;
} else {
throw error;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus/src/client/exports/useGlobalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {DocusaurusContext} from '@docusaurus/types';
import useDocusaurusContext from './useDocusaurusContext';

// TODO annoying constant duplication
Expand All @@ -13,7 +14,7 @@ import useDocusaurusContext from './useDocusaurusContext';
// import {DEFAULT_PLUGIN_ID} from '../../constants';
const DEFAULT_PLUGIN_ID = 'default';

export default function useGlobalData() {
export default function useGlobalData(): DocusaurusContext['globalData'] {
const {globalData} = useDocusaurusContext();
if (!globalData) {
throw new Error('Docusaurus global data not found');
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/client/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Too dynamic
// eslint-disable-next-line @typescript-eslint/no-explicit-any
/* eslint-disable @typescript-eslint/no-explicit-any */
function flat(target: unknown): Record<string, any> {
const delimiter = '.';
const output: Record<string, any> = {};
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus/src/commands/writeHeadingIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import initPlugins from '../server/plugins/init';
import {flatten} from 'lodash';
import {parseMarkdownHeadingId} from '@docusaurus/utils';

export function unwrapMarkdownLinks(line) {
export function unwrapMarkdownLinks(line: string): string {
return line.replace(/\[([^\]]+)\]\([^)]+\)/g, (match, p1) => p1);
}

function addHeadingId(line, slugger) {
function addHeadingId(line: string, slugger: GithubSlugger): string {
let headingLevel = 0;
while (line.charAt(headingLevel) === '#') {
headingLevel += 1;
Expand All @@ -35,7 +35,7 @@ function addHeadingId(line, slugger) {
export function transformMarkdownHeadingLine(
line: string,
slugger: GithubSlugger,
) {
): string {
if (!line.startsWith('#')) {
throw new Error(`Line is not a markdown heading: ${line}`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/webpack/plugins/WaitPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class WaitPlugin {
this.filepath = options.filepath;
}

apply(compiler: Compiler) {
apply(compiler: Compiler): void {
// Before finishing the compilation step
compiler.hooks.make.tapAsync('WaitPlugin', (compilation, callback) => {
// To prevent 'waitFile' error on waiting non-existing directory
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"rootDir": "src",
"outDir": "lib",
"noImplicitAny": false,
"jsx": "react",
"jsx": "react"
},
"exclude": ["node_modules", "**/__tests__/**/*", "**/lib/**/*", "src/client"]
}

0 comments on commit 5beb7b8

Please sign in to comment.