Skip to content

Commit

Permalink
<ContentRef> 유실된 링크 lint 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
CirnoV authored and XiNiHa committed May 21, 2024
1 parent 81d3f3c commit a292800
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion packages/lint-local-links-valid/src/remark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "node:path";

import { lintRule } from "unified-lint-rule";
import { lintRule, type Node } from "unified-lint-rule";
import { visit } from "unist-util-visit";
import * as YAML from "yaml";

Expand Down Expand Up @@ -83,6 +83,37 @@ export const remarkLintLocalLinksValid = lintRule(
});
tasks.push(task);
}
if (
node.type === "mdxJsxFlowElement" &&
"name" in node &&
node.name === "ContentRef" &&
"attributes" in node &&
Array.isArray(node.attributes)
) {
for (const _attr of node.attributes) {
const attr = _attr as unknown;
if (
typeof attr === "object" &&
attr !== null &&
"type" in attr &&
attr.type === "mdxJsxAttribute" &&
"name" in attr &&
attr.name === "slug" &&
"value" in attr &&
typeof attr.value === "string" &&
"position" in attr
) {
const link = attr.value;
const task = checkLink(
path.isAbsolute(link) ? path.join("/docs", link) : link,
(reason) => {
file.message(reason, attr as Node);
},
);
tasks.push(task);
}
}
}
});
await Promise.all(tasks);
},
Expand Down

0 comments on commit a292800

Please sign in to comment.