Skip to content

Commit

Permalink
Make it possible to disable the absolute link rule (#505)
Browse files Browse the repository at this point in the history
Export `remarkLintTeleportDocsLinks` using `lintRule`, naming the rule
`remark-lint:absolute-docs-links`. This means that a docs author can
disable the linter within a page by adding the following:

```
{/* lint disable absolute-docs-links */}
```
  • Loading branch information
ptgott authored Nov 19, 2024
1 parent 4b5cb28 commit 0b723cb
Showing 1 changed file with 8 additions and 7 deletions.
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 {
}
}
});
};
}
}
);

0 comments on commit 0b723cb

Please sign in to comment.