Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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