Skip to content

Commit aad07fa

Browse files
committed
fix(doc-tools): Fix type and linter errors in @doc/mdx-gen-cli
1 parent 972bed1 commit aad07fa

File tree

7 files changed

+105
-101
lines changed

7 files changed

+105
-101
lines changed

doc-tools/doc-mdx-gen-cli/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"doc-mdx-gen-cli": "bin/bundle.js"
77
},
88
"scripts": {
9+
"test": "yarn test:ts && yarn test:lint",
10+
"test:ts": "tsc --noEmit",
11+
"test:lint": "eslint --ext ts,tsx src/",
912
"build": "node ./build.js",
1013
"prepack": "yarn build"
1114
},

doc-tools/doc-mdx-gen-cli/src/MdxToolkitProvider.tsx

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -22,103 +22,103 @@ function normalizeUrl(url: string, fragment?: string) {
2222
return WEBSITE_BASE + url + normalizedFragment;
2323
}
2424

25+
const config: UIToolkitConfig = {
26+
Chapter,
27+
Section: ({ children, title }) => (
28+
<Fragment>
29+
<h3>{title}</h3>
30+
{children}
31+
</Fragment>
32+
),
33+
Header,
34+
List: ({ children, type = 'decimal' }) => (
35+
<ol style={{ listStyleType: type }}>{children}</ol>
36+
),
37+
ListItem: ({ children }) => <li>{children}</li>,
38+
Paragraph: ({ children }) => <p>{children}</p>,
39+
Bold: ({ children }) => <strong>{children}</strong>,
40+
RenderHtmlCard: ({
41+
caption,
42+
snippet,
43+
expoSource,
44+
title,
45+
props,
46+
preferHtmlSrc,
47+
extraneousDeps,
48+
snapshot
49+
}) => {
50+
const html = (props.source as HTMLSourceInline).html;
51+
return (
52+
<renderhtmlcard
53+
preferHtmlSrc={preferHtmlSrc}
54+
html={html}
55+
title={title}
56+
caption={caption}
57+
snippet={snippet}
58+
expoSource={expoSource}
59+
extraneousDeps={extraneousDeps}
60+
snapshot={snapshot}
61+
/>
62+
);
63+
},
64+
SourceDisplay: (props) => <codeblockds {...props} />,
65+
TNodeTransformDisplay: ({ snaphost, ...props }) => {
66+
return <tnodetransformdisplay snapshot={snaphost} {...props} />;
67+
},
68+
Admonition: ({ children, type, title }) => (
69+
<admonition type={type} title={title}>
70+
{children}
71+
</admonition>
72+
),
73+
RefBuilder: ({ name, url, type }) => {
74+
return <reference full={false} name={name} url={url} type={type} />;
75+
},
76+
RefDoc: ({ target, children, fragment }) => {
77+
const linkFragments =
78+
target.group === 'root'
79+
? ['/docs', target.id]
80+
: ['/docs', target.group, target.id];
81+
return (
82+
<reference
83+
library="react-native-render-html"
84+
name={(children as string) || target.title}
85+
url={normalizeUrl(linkFragments.join('/'), fragment)}
86+
type={'doc'}
87+
full={false}
88+
/>
89+
);
90+
},
91+
Acronym: ({ fullName, name, definition }) => (
92+
<abbr about={definition} children={name} title={fullName} />
93+
),
94+
SvgFigure: ({ asset, description, title }) => (
95+
<svgfigure asset={asset} title={title} description={description} />
96+
),
97+
InlineCode: ({ children }) => <code>{children}</code>,
98+
Hyperlink: ({ children, url }) => <a href={url}>{children}</a>,
99+
RefAPI: ({ library, name, url, member, full, plural }) => {
100+
const isRNProp = url.match(/^\/api\/renderhtmlprops/);
101+
return (
102+
<reference
103+
library={library}
104+
name={name}
105+
url={normalizeUrl(url, member?.toLowerCase())}
106+
member={member}
107+
full={full || false}
108+
type={isRNProp ? 'rnrh-prop' : 'api-def'}
109+
plural={plural}
110+
/>
111+
);
112+
},
113+
DList: ({ children }) => <dl>{children}</dl>,
114+
DListTitle: ({ children }) => <dt>{children}</dt>,
115+
DListItem: ({ children }) => <dd>{children}</dd>,
116+
Conditional: ({ platform, children }) =>
117+
platform === 'web' ? <Fragment>{children}</Fragment> : null
118+
};
119+
25120
export default function MdxToolkitProvider({
26121
children: toolkitChildren
27122
}: PropsWithChildren<{}>) {
28-
const config: UIToolkitConfig = {
29-
Chapter,
30-
Section: ({ children, title }) => (
31-
<Fragment>
32-
<h3>{title}</h3>
33-
{children}
34-
</Fragment>
35-
),
36-
Header,
37-
List: ({ children, type = 'decimal' }) => (
38-
<ol style={{ listStyleType: type }}>{children}</ol>
39-
),
40-
ListItem: ({ children }) => <li>{children}</li>,
41-
Paragraph: ({ children }) => <p>{children}</p>,
42-
Bold: ({ children }) => <strong>{children}</strong>,
43-
RenderHtmlCard: ({
44-
caption,
45-
snippet,
46-
expoSource,
47-
title,
48-
props,
49-
preferHtmlSrc,
50-
extraneousDeps,
51-
snapshot
52-
}) => {
53-
const html = (props.source as HTMLSourceInline).html;
54-
return (
55-
<renderhtmlcard
56-
preferHtmlSrc={preferHtmlSrc}
57-
html={html}
58-
title={title}
59-
caption={caption}
60-
snippet={snippet}
61-
expoSource={expoSource}
62-
extraneousDeps={extraneousDeps}
63-
snapshot={snapshot}
64-
/>
65-
);
66-
},
67-
SourceDisplay: (props) => <codeblockds {...props} />,
68-
TNodeTransformDisplay: ({ snaphost, ...props }) => {
69-
return <tnodetransformdisplay snapshot={snaphost} {...props} />;
70-
},
71-
Admonition: ({ children, type, title }) => (
72-
<admonition type={type} title={title}>
73-
{children}
74-
</admonition>
75-
),
76-
RefBuilder: ({ name, url, type }) => {
77-
return <reference full={false} name={name} url={url} type={type} />;
78-
},
79-
RefDoc: ({ target, children, fragment }) => {
80-
const linkFragments =
81-
target.group === 'root'
82-
? ['/docs', target.id]
83-
: ['/docs', target.group, target.id];
84-
return (
85-
<reference
86-
library="react-native-render-html"
87-
name={(children as string) || target.title}
88-
url={normalizeUrl(linkFragments.join('/'), fragment)}
89-
type={'doc'}
90-
full={false}
91-
/>
92-
);
93-
},
94-
Acronym: ({ fullName, name, definition }) => (
95-
<abbr about={definition} children={name} title={fullName} />
96-
),
97-
SvgFigure: ({ asset, description, title }) => (
98-
<svgfigure asset={asset} title={title} description={description} />
99-
),
100-
InlineCode: ({ children }) => <code>{children}</code>,
101-
Hyperlink: ({ children, url }) => <a href={url}>{children}</a>,
102-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
103-
RefAPI: ({ library, name, url, member, full, plural }) => {
104-
const isRNProp = url.match(/^\/api\/renderhtmlprops/);
105-
return (
106-
<reference
107-
library={library}
108-
name={name}
109-
url={normalizeUrl(url, member?.toLowerCase())}
110-
member={member}
111-
full={full || false}
112-
type={isRNProp ? 'rnrh-prop' : 'api-def'}
113-
plural={plural}
114-
/>
115-
);
116-
},
117-
DList: ({ children }) => <dl>{children}</dl>,
118-
DListTitle: ({ children }) => <dt>{children}</dt>,
119-
DListItem: ({ children }) => <dd>{children}</dd>,
120-
Conditional: ({ platform, children }) =>
121-
platform === 'web' ? <Fragment>{children}</Fragment> : null
122-
};
123123
return <ToolkitProvider config={config}>{toolkitChildren}</ToolkitProvider>;
124124
}

doc-tools/doc-mdx-gen-cli/src/genPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export default async function genPage(pageSpecs: PageSpecs, genFolder: string) {
1010
? [genFolder, `${pageSpecs.id}.mdx`]
1111
: [genFolder, pageSpecs.group, `${pageSpecs.id}.mdx`];
1212
return renderMdx(
13-
<MdxToolkitProvider
14-
docRelativeRoot={pageSpecs.group === 'root' ? '../..' : '../../..'}>
13+
<MdxToolkitProvider>
1514
{React.createElement(pageSpecs.component)}
1615
</MdxToolkitProvider>,
1716
pageSpecs,

doc-tools/doc-mdx-gen-cli/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function docMdxGen(outDir: string) {
99
try {
1010
const dir = await fs.opendir(dirPath);
1111
await dir.close();
12-
} catch (e) {
12+
} catch {
1313
console.warn(`${outDir} cannot be read or isn't a directory.`);
1414
process.exit(1);
1515
}

doc-tools/doc-mdx-gen-cli/src/render/MDXRenderer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ const MDXRenderer = Reconciler<
136136

137137
NotPendingTransition: undefined,
138138

139+
// @ts-ignore
139140
HostTransitionContext: undefined,
140141

141142
setCurrentUpdatePriority: function (
143+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
142144
newPriority: Reconciler.EventPriority
143145
): void {
144146
// noop

doc-tools/doc-mdx-gen-cli/src/render/createElement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import AdmonitionElement from './components/AdmonitionElement';
23
import CodeBlockElement from './components/CodeBlockElement';
34
import RenderHTMLCardElement from './components/RenderHTMLCardElement';
@@ -13,7 +14,7 @@ import H3Element from './components/H3Element';
1314
import TNodeTransformDisplayElement from './components/TNodeTransformDisplayElement';
1415
import ReferenceElement from './components/ReferenceElement';
1516

16-
export type NodeType = 'ROOT' | keyof JSX.IntrinsicElements;
17+
export type NodeType = 'ROOT' | keyof React.JSX.IntrinsicElements;
1718

1819
/**
1920
* Creates an element for a document

doc-tools/doc-mdx-gen-cli/src/render/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
21
import { AdmonitionProps } from './components/AdmonitionElement';
32
import { CodeBlockElementProps } from './components/CodeBlockElement';
43
import { ReferenceElementProps } from './components/ReferenceElement';
@@ -7,7 +6,7 @@ import { SvgFigureElementProps } from './components/SvgFigureElement';
76
import { TNodeTransformDisplayElementProps } from './components/TNodeTransformDisplayElement';
87
export { default as renderMdx } from './renderMdx';
98

10-
declare global {
9+
declare module 'react' {
1110
namespace JSX {
1211
interface IntrinsicElements {
1312
admonition: AdmonitionProps;

0 commit comments

Comments
 (0)