mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-19 17:49:19 +02:00
refactor: fix all eslint warnings (#6502)
This commit is contained in:
parent
c1e3801ee7
commit
4f2b09fe32
3 changed files with 24 additions and 10 deletions
|
@ -14,6 +14,7 @@ import remarkStringify from 'remark-stringify';
|
|||
import htmlTags from 'html-tags';
|
||||
import toText from 'hast-util-to-string';
|
||||
import type {Code, InlineCode} from 'mdast';
|
||||
import type {Element, Text} from 'hast';
|
||||
|
||||
const tags = htmlTags.reduce((acc: {[key: string]: boolean}, tag) => {
|
||||
acc[tag] = true;
|
||||
|
@ -34,12 +35,14 @@ export default function sanitizeMD(code: string): string {
|
|||
.stringify(markdownTree);
|
||||
|
||||
const htmlTree = unified().use(parse).parse(markdownString);
|
||||
visit(htmlTree, 'element', (node: any) => {
|
||||
|
||||
visit(htmlTree, 'element', (node: Element) => {
|
||||
if (!tags[node.tagName as string]) {
|
||||
node.type = 'text';
|
||||
node.value = node.tagName + toText(node);
|
||||
delete node.children;
|
||||
delete node.tagName;
|
||||
(node as Element | Text).type = 'text';
|
||||
(node as Element & Partial<Omit<Text, 'type'>>).value =
|
||||
node.tagName + toText(node);
|
||||
delete (node as Partial<Element>).children;
|
||||
delete (node as Partial<Element>).tagName;
|
||||
}
|
||||
});
|
||||
return toJsx(htmlTree)
|
||||
|
|
|
@ -12,6 +12,9 @@ import jscodeshift, {
|
|||
type Collection,
|
||||
type TemplateElement,
|
||||
VariableDeclarator,
|
||||
type CallExpression,
|
||||
type MemberExpression,
|
||||
type Identifier,
|
||||
} from 'jscodeshift';
|
||||
|
||||
const empty = () =>
|
||||
|
@ -29,9 +32,12 @@ const property = (key: string, value: ArrowFunctionExpression) =>
|
|||
jscodeshift.objectProperty(jscodeshift.identifier(key), value);
|
||||
|
||||
const processCallExpression = (node: ASTPath<VariableDeclarator>) => {
|
||||
const args = (node?.value?.init as any)?.arguments[0];
|
||||
const args = (node?.value?.init as CallExpression)?.arguments[0];
|
||||
if (args.type === 'Literal') {
|
||||
if (args.value.includes('../../core/CompLibrary')) {
|
||||
if (
|
||||
typeof args.value === 'string' &&
|
||||
args.value.includes('../../core/CompLibrary')
|
||||
) {
|
||||
const newDeclarator = jscodeshift.variableDeclarator(
|
||||
node.value.id,
|
||||
jscodeshift.objectExpression([
|
||||
|
@ -60,7 +66,11 @@ const processCallExpression = (node: ASTPath<VariableDeclarator>) => {
|
|||
};
|
||||
|
||||
const processMemberExpression = (node: ASTPath<VariableDeclarator>) => {
|
||||
const args = (node?.value?.init as any)?.object?.arguments[0];
|
||||
const object = (node?.value?.init as MemberExpression)?.object;
|
||||
if (!(object.type === 'CallExpression')) {
|
||||
return;
|
||||
}
|
||||
const args = object.arguments[0];
|
||||
if (args.type === 'Literal') {
|
||||
if (args.value === '../../core/CompLibrary.js') {
|
||||
const newDeclarator = jscodeshift.variableDeclarator(
|
||||
|
@ -72,7 +82,7 @@ const processMemberExpression = (node: ASTPath<VariableDeclarator>) => {
|
|||
]),
|
||||
);
|
||||
jscodeshift(node).replaceWith(newDeclarator);
|
||||
} else if (args.value.match(/server/)) {
|
||||
} else if (typeof args.value === 'string' && args.value.match(/server/)) {
|
||||
const newDeclarator = jscodeshift.variableDeclarator(
|
||||
node.value.id,
|
||||
empty(),
|
||||
|
@ -146,7 +156,7 @@ export default function transformer(file: string): string {
|
|||
[
|
||||
jscodeshift.jsxElement(
|
||||
jscodeshift.jsxOpeningElement(
|
||||
jscodeshift.jsxIdentifier((p.value.right as any).name),
|
||||
jscodeshift.jsxIdentifier((p.value.right as Identifier).name),
|
||||
[
|
||||
jscodeshift.jsxSpreadAttribute(
|
||||
jscodeshift.identifier('props'),
|
||||
|
|
|
@ -46,6 +46,7 @@ function Details({summary, children, ...props}: DetailsProps): JSX.Element {
|
|||
const [open, setOpen] = useState(props.open);
|
||||
|
||||
return (
|
||||
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
|
||||
<details
|
||||
{...props}
|
||||
ref={detailsRef}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue