Skip to content

Commit

Permalink
chore(v2): Fix linter warnings (#4442)
Browse files Browse the repository at this point in the history
* chore(v2): Fix linter warnings

223 warnings to 145 warnings

* Remove explicit type annotations

* Do not prefetch when targetLink == null
  • Loading branch information
SamChou19815 authored Mar 17, 2021
1 parent f041a37 commit 5e73c72
Show file tree
Hide file tree
Showing 39 changed files with 146 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module.exports = {
],
'no-unused-vars': OFF,
'no-nested-ternary': WARNING,
'@typescript-eslint/no-empty-function': OFF,
'@typescript-eslint/no-unused-vars': [ERROR, {argsIgnorePattern: '^_'}],
'@typescript-eslint/ban-ts-comment': [
ERROR,
Expand All @@ -108,7 +109,6 @@ module.exports = {
camelcase: WARNING,
'no-restricted-syntax': WARNING,
'no-unused-expressions': WARNING,
'@typescript-eslint/no-empty-function': WARNING,
'global-require': WARNING,
'prefer-destructuring': WARNING,
yoda: WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('create config', () => {
test('simple test', () => {
const v1Config: VersionOneConfig = importFresh(
`${__dirname}/__fixtures__/sourceSiteConfig.js`,
) as any;
);
const siteDir = 'website';
const newDir = 'websiteMigrated';

Expand Down
12 changes: 6 additions & 6 deletions packages/docusaurus-migrate/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export type Data = {
};

export type ClassicPresetEntries = {
docs: {[key: string]: any};
blog: {[key: string]: any};
theme: {[key: string]: any};
docs: {[key: string]: unknown};
blog: {[key: string]: unknown};
theme: {[key: string]: unknown};
};

export type SidebarEntries = {
Expand All @@ -39,7 +39,7 @@ export interface VersionTwoConfig {
githubHost?: string;
onBrokenLinks: string;
onBrokenMarkdownLinks: string;
plugins: Array<[string, {[key: string]: any}]>;
plugins: Array<[string, {[key: string]: unknown}]>;
themes?: [];
presets: [[string, ClassicPresetEntries]];
themeConfig: {
Expand Down Expand Up @@ -114,8 +114,8 @@ export type VersionOneConfig = {
gaTrackingId?: string;
highlight?: Record<string, unknown>;
markdownPlugins?: Array<() => void>;
scripts?: Array<{src: string; [key: string]: any} | string>;
stylesheets?: Array<{href: string; [key: string]: any} | string>;
scripts?: Array<{src: string; [key: string]: unknown} | string>;
stylesheets?: Array<{href: string; [key: string]: unknown} | string>;
facebookAppId?: string;
facebookComments?: true;
facebookPixelId?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare module '@generated/routesChunkNames' {
}

declare module '@generated/globalData' {
const globalData: any;
const globalData: Record<string, unknown>;
export default globalData;
}

Expand Down
9 changes: 6 additions & 3 deletions packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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,
Expand All @@ -215,6 +218,6 @@ export function processDocMetadata({
lastUpdate.lastUpdatedAt * 1000,
)
: undefined,
sidebar_label,
sidebar_label: sidebarLabel,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare module '@docusaurus/plugin-content-docs-types' {
};

type PropsSidebarItemBase = {
customProps?: object;
customProps?: Record<string, unknown>;
};

export type PropSidebarItemLink = PropsSidebarItemBase & {
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
12 changes: 8 additions & 4 deletions packages/docusaurus-plugin-content-docs/src/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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') {
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type PluginOptions = MetadataOptions &
};

export type SidebarItemBase = {
customProps?: object;
customProps?: Record<string, unknown>;
};

export type SidebarItemDoc = SidebarItemBase & {
Expand Down Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ function filterVersions(
) {
if (options.onlyIncludeVersions) {
return versionNamesUnfiltered.filter((name) =>
options.onlyIncludeVersions!.includes(name),
(options.onlyIncludeVersions || []).includes(name),
);
} else {
return versionNamesUnfiltered;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('docusaurus-plugin-content-pages', () => {
path: pluginPath,
}),
);
const pagesMetadatas = (await plugin.loadContent?.())!;
const pagesMetadatas = await plugin.loadContent?.();

expect(pagesMetadatas).toEqual([
{
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('docusaurus-plugin-content-pages', () => {
path: pluginPath,
}),
);
const pagesMetadatas = (await plugin.loadContent?.())!;
const pagesMetadatas = await plugin.loadContent?.();

const frTranslationsPath = path.posix.join(
'@site',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ declare module '@theme/MDXPage' {
readonly title: string;
readonly description: string;
readonly wrapperClassName?: string;
// eslint-disable-next-line camelcase
readonly hide_table_of_contents?: string;
};
readonly metadata: {readonly permalink: string};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const BrowserOnlyReactJson = (props) => {
return (
<BrowserOnly>
{() => {
// eslint-disable-next-line global-require
const ReactJson = require('react-json-view').default;
return <ReactJson {...props} />;
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
*/

import React from 'react';
import Highlight, {defaultProps} from 'prism-react-renderer';
import Highlight, {defaultProps, Language} from 'prism-react-renderer';
import theme from 'prism-react-renderer/themes/nightOwl';
import type {Props} from '@theme/CodeBlock';

export default ({children, className}): JSX.Element => {
export default ({children, className}: Props): JSX.Element => {
const language = className && className.replace(/language-/, '');

return (
<Highlight
{...defaultProps}
theme={theme}
code={children}
language={language}>
language={language as Language}>
{({style, tokens, getLineProps, getTokenProps}) => (
<pre className={className} style={{...style, padding: '20px'}}>
{tokens.map((line, i) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function FooterLink({to, href, label, ...props}) {
);
}

function Footer() {
function Footer(): JSX.Element {
const context = useDocusaurusContext();
const {siteConfig = {}} = context;
const {themeConfig = {}} = siteConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React, {ReactNode} from 'react';
import CodeBlock from '@theme/CodeBlock';
import CodeBlock, {Props} from '@theme/CodeBlock';
import {Table} from 'reactstrap';

const Heading = (tag: string): ReactNode => {
Expand All @@ -22,16 +22,18 @@ export default {
h4: Heading('h4'),
h5: Heading('h5'),
h6: Heading('h6'),
code: (props) => {
code: (props: Props): JSX.Element => {
const {children} = props;
if (typeof children === 'string') {
return <CodeBlock {...props} />;
}
return children;
},
table: Table,
blockquote: (props) => (
blockquote: (props: {children: ReactNode}): JSX.Element => (
<blockquote className="blockquote-footer">{props.children}</blockquote>
),
p: (props) => <div className="font-weight-light">{props.children}</div>,
p: (props: {children: ReactNode}): JSX.Element => (
<div className="font-weight-light">{props.children}</div>
),
};
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function NavItem({
);
}

function Navbar() {
function Navbar(): JSX.Element {
const {
siteConfig: {
themeConfig: {navbar: {title = '', items: links = []} = {}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';

function TOCInline(_props: any): JSX.Element {
function TOCInline(_props: Record<string, unknown>): JSX.Element {
return <div>TODO bootstrap toc</div>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {merge} from 'lodash';
const {ThemeConfigSchema, DEFAULT_CONFIG} = require('../validateThemeConfig');

const {normalizeThemeConfig} = require('@docusaurus/utils-validation');
const theme = require('prism-react-renderer/themes/github');
const darkTheme = require('prism-react-renderer/themes/dracula');

function testValidateThemeConfig(partialThemeConfig) {
return normalizeThemeConfig(ThemeConfigSchema, {
Expand All @@ -31,8 +33,8 @@ describe('themeConfig', () => {
test('should accept valid theme config', () => {
const userConfig = {
prism: {
theme: require('prism-react-renderer/themes/github'),
darkTheme: require('prism-react-renderer/themes/dracula'),
theme,
darkTheme,
defaultLanguage: 'javascript',
additionalLanguages: ['kotlin', 'java'],
},
Expand Down
10 changes: 8 additions & 2 deletions packages/docusaurus-theme-classic/src/theme/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ import React from 'react';
import clsx from 'clsx';

import Link from '@docusaurus/Link';
import {useThemeConfig} from '@docusaurus/theme-common';
import {FooterLinkItem, useThemeConfig} from '@docusaurus/theme-common';
import useBaseUrl from '@docusaurus/useBaseUrl';
import styles from './styles.module.css';
import ThemedImage, {Props as ThemedImageProps} from '@theme/ThemedImage';

function FooterLink({to, href, label, prependBaseUrlToHref, ...props}: any) {
function FooterLink({
to,
href,
label,
prependBaseUrlToHref,
...props
}: FooterLinkItem) {
const toUrl = useBaseUrl(to);
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MDXComponents: MDXComponentsObject = {
return children;
},
a: (props) => <Link {...props} />,
pre: (props: any) => {
pre: (props) => {
const {children} = props;
return (
<CodeBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const NavbarItemComponents = {
// Need to lazy load these items as we don't know for sure the docs plugin is loaded
// See https://github.com/facebook/docusaurus/issues/3360
docsVersion: () =>
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
require('@theme/NavbarItem/DocsVersionNavbarItem').default,
docsVersionDropdown: () =>
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
doc: () =>
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
require('@theme/NavbarItem/DocNavbarItem').default,
} as const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// see https://github.com/webpack/webpack/issues/7713#issuecomment-467888437
// note: warning can be filtered: https://github.com/facebook/docusaurus/pull/3382#issuecomment-684966924
try {
// eslint-disable-next-line global-require
module.exports = require('@theme-init/hooks/useDocs');
} catch (e) {
// In case the docs plugin is not available, might be useful to stub some methods here
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-theme-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@docusaurus/module-type-aliases": "2.0.0-alpha.72"
},
"peerDependencies": {
"prism-react-renderer": "^1.1.1",
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
},
Expand Down
Loading

0 comments on commit 5e73c72

Please sign in to comment.