Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Make it possible to disable the absolute link rule #505

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions server/lint-teleport-docs-links.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Transformer } from "unified";
import { lintRule } from "unified-lint-rule";
import { visit } from "unist-util-visit";
import type { Link as MdastLink } from "mdast";
import type { EsmNode, MdxAnyElement, MdxastNode } from "./types-unist";

import { visit } from "unist-util-visit";
import { isExternalLink, isHash, isPage } from "../utils/url";

interface ObjectHref {
Expand All @@ -28,9 +28,10 @@ const isAnAbsoluteDocsLink = (href: string): boolean => {
);
};

export function remarkLintTeleportDocsLinks(): Transformer {
return (root, vfile) => {
visit(root, (node: MdxastNode) => {
export const remarkLintTeleportDocsLinks = lintRule(
"remark-lint:absolute-docs-links",
(root, vfile) => {
visit(root, undefined, (node: MdxastNode) => {
if (node.type == "link" && isAnAbsoluteDocsLink(node.url)) {
vfile.message(
`Link reference ${node.url} must be a relative link to an *.mdx page`,
Expand All @@ -52,5 +53,5 @@ export function remarkLintTeleportDocsLinks(): Transformer {
}
}
});
};
}
}
);
Loading