Skip to content

Validate codeblock URLs during build and streamline CI lints#3020

Merged
manovotny merged 11 commits intomainfrom
manovotny/codeblock-link-checker
Mar 23, 2026
Merged

Validate codeblock URLs during build and streamline CI lints#3020
manovotny merged 11 commits intomainfrom
manovotny/codeblock-link-checker

Conversation

@manovotny
Copy link
Copy Markdown
Contributor

@manovotny manovotny commented Jan 29, 2026

Warning

These upstream changes will need to be merged before the build will pass (because they contain broken or out-of-date URLs):

Summary

  • Adds build-time validation for clerk.com/docs URLs found in code block comments
  • Streamlines CI lint workflow to only run lints that don't require a build
  • Fixes outdated documentation URLs

What changed?

Build-time codeblock URL validation

Updated scripts/lib/plugins/validateLinks.ts to validate clerk.com/docs URLs found in code block comments during the build process:

  • Scans code blocks for URLs matching https://clerk.com/docs/*
  • Validates URLs exist in the built docs directory
  • Reports warnings during build if URLs are invalid
  • Auto-generated API error docs (backend-api.mdx, frontend-api.mdx) are excluded from link-doc-not-found warnings since their URLs come from upstream

CI workflow changes

Updated .github/workflows/lint.yml to run all lints that don't require a build:

  • lint:formatting - Prettier check
  • lint:check-frontmatter - Frontmatter validation
  • lint:check-duplicate-redirects - Duplicate redirect check
  • lint:check-svgs - SVG optimization check
  • lint:check-images - Image reference check
  • lint:check-description-backticks - Description backtick check
  • lint:check-prompt-deeplink-length - Prompt deeplink length check

Lints requiring a build (lint:check-redirects) are now validated as part of the build process itself.

Fixed URLs

Fixed outdated clerk.com/docs URLs found in code blocks:

  • /docs/quickstarts/nextjs/docs/nextjs/getting-started/quickstart
  • /docs/custom-flows/error-handling/docs/guides/development/custom-flows/error-handling
  • /docs/reference/tanstack-react-start/custom-sign-in-or-up-page/docs/guides/development/custom-sign-in-or-up-page
  • /docs/references/backend/types/auth-object/docs/reference/backend/types/auth-object
  • /docs/authentication/enterprise-connections/authentication-flows/docs/guides/configure/auth-strategies/enterprise-connections/authentication-flows
  • /docs/guides/development/custom-flows/overview#session-tasks/docs/guides/development/custom-flows/authentication/session-tasks

Unit tests

Added integration tests for codeblock URL validation in scripts/build-docs.test.ts:

  • Warns on non-existent codeblock URLs
  • No warning for valid codeblock URLs
  • Warns on invalid hash fragments in codeblock URLs
  • Validates multiple URLs in a single code block
  • Accepts valid hash fragments

Test plan

  • Build passes locally with pnpm run build
  • Lint passes locally with pnpm run lint:formatting
  • Tests pass locally with pnpm run test (excluding pre-existing move-doc.test.ts failures on main)
  • Verified codeblock URL validation catches outdated URLs
  • API error docs are excluded from codeblock link-not-found warnings

🤖 Generated with Claude Code

@manovotny manovotny requested a review from a team as a code owner January 29, 2026 23:13
@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 29, 2026

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

Project Deployment Actions Updated (UTC)
clerk-docs Ready Ready Preview Mar 19, 2026 8:11pm

Request Review

@NWylynko
Copy link
Copy Markdown
Contributor

In scripts/lib/plugins/validateLinks.ts we already validate standard links and then have a map of all available guides to check against if they exist. Could we just update that to also check in code blocks?

@manovotny manovotny force-pushed the manovotny/codeblock-link-checker branch from a11c901 to e794dc6 Compare February 4, 2026 17:35
@manovotny manovotny force-pushed the manovotny/codeblock-link-checker branch from 7bf9d01 to ae58e94 Compare February 4, 2026 20:15
@manovotny manovotny changed the title Add codeblock link checker and enable all lints on PR Validate codeblock URLs during build and streamline CI lints Feb 4, 2026
@manovotny
Copy link
Copy Markdown
Contributor Author

In scripts/lib/plugins/validateLinks.ts we already validate standard links and then have a map of all available guides to check against if they exist. Could we just update that to also check in code blocks?

Done!

Comment thread scripts/build-docs.ts Outdated
Comment thread scripts/lib/plugins/validateLinks.ts Outdated
Comment thread scripts/lib/error-messages.ts Outdated
manovotny and others added 5 commits February 6, 2026 11:30
- Add scripts/check-codeblock-links.ts to validate clerk.com/docs URLs
  in code block comments against built docs
- Fix 4 outdated URLs found by the new checker
- Update .github/workflows/lint.yml to run all lint checks after build
- Add lint:check-codeblock-links script to package.json

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move codeblock URL validation from standalone script into the existing
validateLinks remark plugin. This validates clerk.com/docs URLs in code
block comments during the build process.

Changes:
- Add codeblock URL validation to validateLinks.ts
- Detect URLs that redirect and suggest the correct path
- Preserve hash fragments in redirect suggestions
- Add 'link-redirects' error message
- Pass redirects to validateLinks for redirect chain resolution
- Remove standalone check-codeblock-links.ts script

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove build step from lint workflow and run only lints that don't
require built artifacts: formatting, frontmatter, duplicate redirects,
SVGs, and images. Build-dependent validations (like codeblock URL
checking) run as part of the build process itself.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Derive redirectsForValidation from existing variables instead of
storing a separate copy of the raw redirect arrays.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
manovotny and others added 2 commits March 9, 2026 20:56
…ink-checker

# Conflicts:
#	.github/workflows/lint.yml
- Remove redirect chain logic (followRedirectChain, link-redirects error,
  redirect params) per reviewer feedback — just use link-doc-not-found
- Add unit tests for codeblock URL validation
- Ignore link-doc-not-found for auto-generated API error docs
- Fix outdated session-tasks URLs in code block comments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@manovotny manovotny merged commit d526202 into main Mar 23, 2026
8 checks passed
@manovotny manovotny deleted the manovotny/codeblock-link-checker branch March 23, 2026 20:42
manovotny added a commit that referenced this pull request Mar 26, 2026
PR #3227 replaced hardcoded SDK cards with a dynamic `SDKCards`
component, removing the `community-sdks.mdx` partial that referenced
these images. The image files themselves were not deleted, leaving
them orphaned and failing `lint:check-images`.

The lint didn't catch this on PR #3227 because of a timing issue:
`lint:check-images` was added to the CI lint workflow in PR #3020
(merged 2026-03-23), but the CI run for PR #3227 executed on
2026-03-18 — five days before the check existed. The PR was then
merged on 2026-03-26 using that stale passing CI result.

Deleted files:
- public/images/logos/sdks/angular.svg
- public/images/logos/sdks/elysia.svg
- public/images/logos/sdks/hono.svg
- public/images/logos/sdks/koa-dark.svg
- public/images/logos/sdks/koa.svg
- public/images/logos/sdks/rust.svg
- public/images/logos/sdks/solidjs.svg
- public/images/logos/sdks/svelte.svg

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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