refactor: clean up TODO comments (#6399)

This commit is contained in:
Joshua Chen 2022-01-19 12:10:50 +08:00 committed by GitHub
parent 1d7827d572
commit 6c0da3ee4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 21 additions and 27 deletions

View file

@ -62,9 +62,7 @@ export function shouldQuotifyFrontMatter([key, value]: [
if (String(value).match(/^("|').+("|')$/)) { if (String(value).match(/^("|').+("|')$/)) {
return false; return false;
} }
// TODO weird graymatter case // title: !something needs quotes because otherwise it's a YAML tag.
// title: !something need quotes
// but not title: something!
if (!String(value).trim().match(/^\w.*/)) { if (!String(value).trim().match(/^\w.*/)) {
return true; return true;
} }

View file

@ -162,10 +162,10 @@ declare module '@docusaurus/Link' {
declare module '@docusaurus/Interpolate' { declare module '@docusaurus/Interpolate' {
import type {ReactNode} from 'react'; import type {ReactNode} from 'react';
// TODO use TS template literal feature to make values typesafe! export type ExtractInterpolatePlaceholders<Str extends string> =
// (requires upgrading TS first) Str extends `${string}{${infer Key}}${infer Rest}`
// eslint-disable-next-line @typescript-eslint/no-unused-vars ? Key | ExtractInterpolatePlaceholders<Rest>
export type ExtractInterpolatePlaceholders<Str extends string> = string; : never;
export type InterpolateValues< export type InterpolateValues<
Str extends string, Str extends string,

View file

@ -5,11 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type { import type {LoadContext, Plugin, PostCssOptions} from '@docusaurus/types';
DocusaurusContext,
Plugin,
PostCssOptions,
} from '@docusaurus/types';
import type {ThemeConfig} from '@docusaurus/theme-common'; import type {ThemeConfig} from '@docusaurus/theme-common';
import {getTranslationFiles, translateThemeConfig} from './translations'; import {getTranslationFiles, translateThemeConfig} from './translations';
import path from 'path'; import path from 'path';
@ -95,7 +91,7 @@ function getInfimaCSSFile(direction: string) {
} }
export default function docusaurusThemeClassic( export default function docusaurusThemeClassic(
context: DocusaurusContext, // TODO: LoadContext is missing some of properties context: LoadContext,
options: Options, options: Options,
): Plugin<void> { ): Plugin<void> {
const { const {

View file

@ -44,9 +44,9 @@ export default function CodeBlock({
setMounted(true); setMounted(true);
}, []); }, []);
// TODO: the title is provided by MDX as props automatically // We still parse the metastring in case we want to support more syntax in the
// so we probably don't need to parse the metastring // future. Note that MDX doesn't strip quotes when parsing metastring:
// (note: title="xyz" => title prop still has the quotes) // "title=\"xyz\"" => title: "\"xyz\""
const codeBlockTitle = parseCodeBlockTitle(metastring) || title; const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
const prismTheme = usePrismTheme(); const prismTheme = usePrismTheme();

View file

@ -16,7 +16,7 @@ import type {Types, Props} from '@theme/NavbarItem';
const NavbarItemComponents: Record< const NavbarItemComponents: Record<
Exclude<Types, undefined>, Exclude<Types, undefined>,
// TODO: properly type this // Not really worth typing, as we pass all props down immediately
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
() => (props: any) => JSX.Element () => (props: any) => JSX.Element
> = { > = {

View file

@ -31,8 +31,10 @@ import {mapAsyncSequential} from '@docusaurus/utils';
export default async function build( export default async function build(
siteDir: string, siteDir: string,
cliOptions: Partial<BuildCLIOptions> = {}, cliOptions: Partial<BuildCLIOptions> = {},
// When running build, we force terminate the process to prevent async
// TODO what's the purpose of this arg ? // operations from never returning. However, if run as part of docusaurus
// deploy, we have to let deploy finish.
// See https://github.com/facebook/docusaurus/pull/2496
forceTerminate: boolean = true, forceTerminate: boolean = true,
): Promise<string> { ): Promise<string> {
['SIGINT', 'SIGTERM'].forEach((sig) => { ['SIGINT', 'SIGTERM'].forEach((sig) => {

View file

@ -147,7 +147,7 @@ describe('normalizeConfig', () => {
'should accept [function, object] for plugin', 'should accept [function, object] for plugin',
[[function (_context, _options) {}, {it: 'should work'}]], [[function (_context, _options) {}, {it: 'should work'}]],
], ],
])(`subdue= for the input of: path=`, (_message, plugins) => { ])(`%s for the input of: %p`, (_message, plugins) => {
expect(() => { expect(() => {
normalizeConfig({ normalizeConfig({
plugins, plugins,

View file

@ -65,9 +65,7 @@ const PluginSchema = Joi.alternatives()
.length(2), .length(2),
Joi.bool().equal(false), // In case of conditional adding of plugins. Joi.bool().equal(false), // In case of conditional adding of plugins.
) )
// TODO isn't there a simpler way to customize the default Joi error message??? // @ts-expect-error: bad lib def, doesn't recognize an array of reports
// Not sure why Joi makes it complicated to add a custom error message...
// See https://stackoverflow.com/a/54657686/82609
.error((errors) => { .error((errors) => {
errors.forEach((error) => { errors.forEach((error) => {
error.message = ` => Bad Docusaurus plugin value as path [${error.path}]. error.message = ` => Bad Docusaurus plugin value as path [${error.path}].
@ -83,7 +81,7 @@ Example valid plugin config:
}; };
`; `;
}); });
return errors as any; return errors;
}); });
const ThemeSchema = Joi.alternatives().try( const ThemeSchema = Joi.alternatives().try(

View file

@ -230,7 +230,7 @@ export function applyConfigurePostCss(
options: {postcssOptions: PostCssOptions}; options: {postcssOptions: PostCssOptions};
}; };
// TODO not ideal heuristic but good enough for our usecase? // not ideal heuristic but good enough for our usecase?
function isPostCssLoader(loader: unknown): loader is LocalPostCSSLoader { function isPostCssLoader(loader: unknown): loader is LocalPostCSSLoader {
return !!(loader as LocalPostCSSLoader)?.options?.postcssOptions; return !!(loader as LocalPostCSSLoader)?.options?.postcssOptions;
} }

View file

@ -38,8 +38,6 @@ Code blocks are text blocks wrapped around by strings of 3 backticks. You may ch
console.log('Every repo must come with a mascot.'); console.log('Every repo must come with a mascot.');
``` ```
<!-- TODO: We need to allow users to pick syntax highlighting themes (maybe other than swizzling) -->
Use the matching language meta string for your code block, and Docusaurus will pick up syntax highlighting automatically, powered by [Prism React Renderer](https://github.com/FormidableLabs/prism-react-renderer). Use the matching language meta string for your code block, and Docusaurus will pick up syntax highlighting automatically, powered by [Prism React Renderer](https://github.com/FormidableLabs/prism-react-renderer).
<BrowserWindow> <BrowserWindow>
@ -67,6 +65,8 @@ module.exports = {
}; };
``` ```
Because a Prism theme is just a JS object, you can also write your own theme if you are not satisfied with the default. Docusaurus enhances the `github` and `vsDark` themes to provide richer highlight, and you can check our implementations for the [light](https://github.com/facebook/docusaurus/blob/main/website/src/utils/prismLight.mjs) and [dark](https://github.com/facebook/docusaurus/blob/main/website/src/utils/prismDark.mjs) code block themes.
### Supported Languages {#supported-languages} ### Supported Languages {#supported-languages}
By default, Docusaurus comes with a subset of [commonly used languages](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js). By default, Docusaurus comes with a subset of [commonly used languages](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js).