Validate codeblock URLs during build and streamline CI lints#3020
Validate codeblock URLs during build and streamline CI lints#3020
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
In |
a11c901 to
e794dc6
Compare
7bf9d01 to
ae58e94
Compare
Done! |
| /** | ||
| * Follow redirect chain to get final destination | ||
| */ | ||
| function followRedirectChain( | ||
| url: string, | ||
| staticRedirects: Map<string, string>, | ||
| dynamicRedirects: Redirect[], | ||
| maxRedirects = 10, | ||
| ): string | null { | ||
| let currentUrl = url | ||
| let redirectCount = 0 | ||
|
|
||
| while (redirectCount < maxRedirects) { | ||
| // Check static redirects first | ||
| const staticDest = staticRedirects.get(currentUrl) | ||
| if (staticDest) { | ||
| currentUrl = staticDest | ||
| redirectCount++ | ||
| continue | ||
| } | ||
|
|
||
| // Check dynamic redirects (simple prefix matching for common patterns) | ||
| let foundDynamic = false | ||
| for (const redirect of dynamicRedirects) { | ||
| // Handle simple wildcard patterns like /docs/old/:path* -> /docs/new/:path* | ||
| const sourceBase = redirect.source.replace(/:\w+\*?$/, '') | ||
| if (currentUrl.startsWith(sourceBase)) { | ||
| const remainder = currentUrl.slice(sourceBase.length) | ||
| const destBase = redirect.destination.replace(/:\w+\*?$/, '') | ||
| currentUrl = destBase + remainder | ||
| foundDynamic = true | ||
| redirectCount++ | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if (!foundDynamic) { | ||
| // No more redirects | ||
| return currentUrl !== url ? currentUrl : null | ||
| } | ||
| } | ||
|
|
||
| return currentUrl !== url ? currentUrl : null | ||
| } | ||
|
|
There was a problem hiding this comment.
If using the staticRedirects objects set in the build() function, it has already done the redirect chain following (see optimizeRedirects() on line 271) so this wouldn't need to do that. Additionally this logic is wrong as clerk/clerk redirect checks start with dynamic redirects, then static second (see https://github.com/clerk/clerk/blob/main/src/app/(website)/docs/clerk-docs-redirects.ts#L51)
| 'link-redirects': (url: string, destination: string): string => | ||
| `Link "${url}" redirects to "${destination}". Update the URL to use the new path.`, |
There was a problem hiding this comment.
As much as this is nice to report, we don't really need to (to fulfill the purpose of this pr), we can just use link-doc-not-found and leave it at that, let the author figure out what the link should be.
Some reasons to not bother:
- This gives a false sense of like its fine, don't worry a redirect is in place, when really your saying like no this needs to be updated.
- It would cut down on the complexity of this pr a lot by not reporting that a redirect does or does not exist.
If we do want to go down the route of checking links against the redirects, a couple other options come to mind
- Update the link in place based off the redirect, so the outputted files already include the latest link
- Add a
--fixflag to the cli that updates the link in the docs folder
- 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>
4b37177 to
c93a3b1
Compare
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>
Warning
These upstream changes will need to be merged before the build will pass (because they contain broken or out-od-date urls):
chore: Update API ErrorsPR (like this one) should automatically show up when a new release happensSummary
clerk.com/docsURLs found in code block commentsWhat changed?
Build-time codeblock URL validation
Updated
scripts/lib/plugins/validateLinks.tsto validateclerk.com/docsURLs found in code block comments during the build process:https://clerk.com/docs/*CI workflow changes
Updated
.github/workflows/lint.ymlto run all lints that don't require a build:lint:formatting- Prettier checklint:check-frontmatter- Frontmatter validationlint:check-duplicate-redirects- Duplicate redirect checklint:check-svgs- SVG optimization checklint:check-images- Image reference checkLints requiring a build (
lint:check-redirects) are now validated as part of the build process itself.Fixed URLs
Fixed outdated
clerk.com/docsURLs 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-flowsTest plan
pnpm run buildpnpm run lint🤖 Generated with Claude Code