|
11 | 11 | * - Links whose case differs from the real path (work on macOS, 404 on Linux) |
12 | 12 | * - Missing anchor/heading references |
13 | 13 | * - Invalid file paths |
14 | | - * - Absolute links to this site (https://sourcegraph.com/docs/..., the legacy |
15 | | - * https://docs.sourcegraph.com/... host, http://, //, www.), which should be |
16 | | - * relative links; the finding proposes one, following src/data/redirects.ts |
| 14 | + * - With --check-self-links, absolute links to this site (https://sourcegraph.com/docs/..., |
| 15 | + * the legacy https://docs.sourcegraph.com/... host, http://, //, www.), which |
| 16 | + * should be relative links; the finding proposes one, following src/data/redirects.ts |
17 | 17 | * - With --check-external, external links on added lines that return 404 or 410 |
18 | | - * |
| 18 | + * |
| 19 | + * next.config.js runs this with no flags on every build, so only dead page links |
| 20 | + * can fail a deploy; the flags below are for the pull request workflow. |
| 21 | + * |
19 | 22 | * Usage: node dev/check-links.mjs [options] |
20 | 23 | * --check-anchors Also validate #anchors against headings |
| 24 | + * --check-self-links Also report absolute links to this site |
21 | 25 | * --root <dir> Repository to check (default: this repository) |
22 | 26 | * --format <name> Output as text (default), json, or markdown |
23 | 27 | * --baseline <file> Only report findings absent from this JSON file |
@@ -49,6 +53,7 @@ const __dirname = path.dirname(__filename); |
49 | 53 | // Parse CLI flags |
50 | 54 | const args = process.argv.slice(2); |
51 | 55 | const CHECK_ANCHORS = args.includes('--check-anchors'); |
| 56 | +const CHECK_SELF_LINKS = args.includes('--check-self-links'); |
52 | 57 | const ROOT_DIR = path.resolve(flagValue('--root') ?? path.dirname(__dirname)); |
53 | 58 | const FORMAT = flagValue('--format') ?? 'text'; |
54 | 59 | const BASELINE_FILE = flagValue('--baseline'); |
@@ -326,7 +331,7 @@ function validateLink(link, currentFile, maps) { |
326 | 331 | const { url } = link; |
327 | 332 |
|
328 | 333 | if (isSelfLink(url)) { |
329 | | - return validateSelfLink(url, currentFile, maps); |
| 334 | + return CHECK_SELF_LINKS ? validateSelfLink(url, currentFile, maps) : null; |
330 | 335 | } |
331 | 336 |
|
332 | 337 | // Skip external links, mailto, tel, javascript, etc. |
|
0 commit comments