From 0b723cb6cf750e02d9b4869ede1dd5c890888a0b Mon Sep 17 00:00:00 2001 From: Paul Gottschling Date: Tue, 19 Nov 2024 11:16:24 -0500 Subject: [PATCH] Make it possible to disable the absolute link rule (#505) 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 */} ``` --- server/lint-teleport-docs-links.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/lint-teleport-docs-links.ts b/server/lint-teleport-docs-links.ts index ed30320d97..1cd02e7305 100644 --- a/server/lint-teleport-docs-links.ts +++ b/server/lint-teleport-docs-links.ts @@ -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 { @@ -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`, @@ -52,5 +53,5 @@ export function remarkLintTeleportDocsLinks(): Transformer { } } }); - }; -} + } +);