Skip to content

chore(lint): flag doc links that aren't relative file paths - #4863

Merged
thetaPC merged 2 commits into
mainfrom
doc-link-lint
Nov 19, 2026
Merged

thetaPC merged 2 commits into
mainfrom
doc-link-lint

Conversation

@thetaPC

@thetaPC thetaPC commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Issue URL: N/A

What is the current behavior?

What is the new behavior?

  • npm run lint fails on:
    • A Markdown link without an extension, or one starting with /.
    • A JSX href or to that's relative or has an .mdx extension.
    • On an older version's page, an absolute JSX link without the version prefix, such as /components instead of /v8/components, since it leads to the current docs.
  • The check is a remark plugin in .remarkrc.mjs, run by eslint-plugin-mdx's mdx/remark rule. The rule goes from the preset's warn to error, since a warning doesn't fail the lint.
  • CONTRIBUTING says the lint enforces the link rule.

Does this introduce a breaking change?

  • Yes
  • No

Other information

The ESLint extension in VS Code shows these errors on the link as you type.

How to test

  1. In docs/api/grid.mdx, change ./row.mdx to ./row, then to /api/row.mdx. npm run lint fails on each, naming the line.
  2. In docs/index.mdx, change the Installation Guide card's href="/intro/cli" to href="./intro/cli", then to href="/intro/cli.mdx". npm run lint fails on each.
  3. In versioned_docs/version-v8/index.mdx, change the Installation Guide card's href="/v8/intro/cli" to href="/intro/cli". npm run lint fails and asks for the /v8/ prefix.
  4. With the ESLint extension in VS Code, the same edits are underlined as you type.

⚠️ Merge after #4879. The version prefix check fails on the 28 v8 cards that PR fixes.

@thetaPC
thetaPC added this pull request to stack #4861 November 18, 2026 01:04
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-docs Ready Ready Preview Nov 19, 2026 11:01pm UTC

Request Review

@brandyscarney brandyscarney left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Left a couple suggestions.

Comment thread .remarkrc.mjs Outdated
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
if (attribute.name !== 'href' || typeof attribute.value !== 'string') continue;
if (!['href', 'to'].includes(attribute.name) || typeof attribute.value !== 'string') continue;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 189ecf3. to is checked the same way as href, and nothing in the docs trips it today.

Comment thread .remarkrc.mjs
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('/')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here in 189ecf3. On a versioned_docs/version-vN/ page, an absolute JSX link now has to start with /vN/. It flags only the 28 cards that #4879 fixes, so this PR merges after #4879.

@thetaPC
thetaPC merged commit a2d1e63 into main Nov 19, 2026
7 checks passed
@thetaPC
thetaPC deleted the doc-link-lint branch November 19, 2026 23:06

This branch was successfully deployed

1 active deployment
Preview — b8e26a08 Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants