Repository navigation
chore(lint): flag doc links that aren't relative file paths - #4863
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
a30b018 to
52205fa
Compare
brandyscarney
left a comment
There was a problem hiding this comment.
Looks good! Left a couple suggestions.
| if (reason) report(reason, node); | ||
| } else if (node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') { | ||
| for (const attribute of node.attributes) { | ||
| if (attribute.name !== 'href' || typeof attribute.value !== 'string') continue; |
There was a problem hiding this comment.
This only checks href, but CONTRIBUTING tells authors to use <Link> from @docusaurus/Link, whose usual prop is to. I tried it: <Link to="./foo.mdx"> passes the lint. Nothing in docs uses to= yet, so this is cheap to close now:
| if (attribute.name !== 'href' || typeof attribute.value !== 'string') continue; | |
| if (!['href', 'to'].includes(attribute.name) || typeof attribute.value !== 'string') continue; |
There was a problem hiding this comment.
Done in 189ecf3. to is checked the same way as href, and nothing in the docs trips it today.
| if (/\.mdx?$/.test(path)) { | ||
| return `A JSX \`href\` is a URL, not a file. Drop the extension from \`${url}\`, such as \`/api/accordion\`.`; | ||
| } | ||
| if (!path.startsWith('/')) { |
There was a problem hiding this comment.
Suggestion, here or in a follow-up: on a file under versioned_docs/version-vN/, this could also require an absolute href to start with /vN/. That would catch the ~26 v8 DocsCards still pointing at current docs (see my comment on #4862), and match the rule CONTRIBUTING now states.
52205fa to
2c9f714
Compare
2c9f714 to
2f71833
Compare
2f71833 to
f6f74ae
Compare
189ecf3 to
b8e26a0
Compare
Issue URL: N/A
What is the current behavior?
/.What is the new behavior?
npm run lintfails on:/.hrefortothat's relative or has an.mdxextension./componentsinstead of/v8/components, since it leads to the current docs..remarkrc.mjs, run byeslint-plugin-mdx'smdx/remarkrule. The rule goes from the preset'swarntoerror, since a warning doesn't fail the lint.Does this introduce a breaking change?
Other information
The ESLint extension in VS Code shows these errors on the link as you type.
How to test
docs/api/grid.mdx, change./row.mdxto./row, then to/api/row.mdx.npm run lintfails on each, naming the line.docs/index.mdx, change the Installation Guide card'shref="/intro/cli"tohref="./intro/cli", then tohref="/intro/cli.mdx".npm run lintfails on each.versioned_docs/version-v8/index.mdx, change the Installation Guide card'shref="/v8/intro/cli"tohref="/intro/cli".npm run lintfails and asks for the/v8/prefix.