-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow JavaScript code as the value of the `href` attribute. This allows us to import assets as MDX modules so we can refer to the asset paths in HTML tags. Otherwise, the linter encounters a runtime exception and fails even if there is a comment that ignores messages from the linter. An example of the linter failing is gravitational/teleport#51193, which imports a bot avatar logo as a module so users can download it.
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { remarkLintTeleportDocsLinks } from "./lint-teleport-docs-links"; | ||
import { VFile } from "vfile"; | ||
import { remark } from "remark"; | ||
import mdx from "remark-mdx"; | ||
|
||
const getReasons = (value: string) => { | ||
return remark() | ||
.use(mdx as any) | ||
.use(remarkLintTeleportDocsLinks as any) | ||
.processSync(new VFile({ value, path: "mypath.mdx" }) as any) | ||
.messages.map((m) => m.reason); | ||
}; | ||
|
||
describe("server/lint-absolute-docs-links", () => { | ||
interface testCase { | ||
description: string; | ||
input: string; | ||
expected: Array<string>; | ||
} | ||
|
||
const testCases: Array<testCase> = [ | ||
{ | ||
description: "absolute docs path in a Markdown link href", | ||
input: "This is a [link](https://goteleport.com/docs/installation)", | ||
expected: [ | ||
"Link reference https://goteleport.com/docs/installation must be a relative link to an *.mdx page", | ||
], | ||
}, | ||
{ | ||
description: "absolute docs path in an a tag", | ||
input: "<a href='https://goteleport.com/docs/installation'>here</a>", | ||
expected: [ | ||
"Component href https://goteleport.com/docs/installation must be a relative link to an *.mdx page", | ||
], | ||
}, | ||
{ | ||
description: "JavaScript identifier as href value", | ||
input: | ||
"You can <a href={BotLogo} download>download</a> our avatar to set as your Bot Icon.", | ||
expected: [], | ||
}, | ||
]; | ||
|
||
test.each(testCases)("$description", (tc) => { | ||
expect(getReasons(tc.input)).toEqual(tc.expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters