|
24 | 24 | * Path to Git root folder (default: local Git folder); |
25 | 25 | * if both `root` and `repository` are nullish, the Git root is detected; |
26 | 26 | * if `root` is not given but `repository` is, `file.cwd` is used. |
| 27 | + * @property {ReadonlyArray<RegExp | string> | null | undefined} [skipPathPatterns] |
| 28 | + * List of patterns for *paths* that should be skipped; |
| 29 | + * each absolute local path + hash will be tested against each pattern and |
| 30 | + * will be ignored if `new RegExp(pattern).test(value) === true`; |
| 31 | + * example value are then `/Users/tilde/path/to/repo/readme.md#some-heading`. |
27 | 32 | * @property {Readonly<UrlConfig> | null | undefined} [urlConfig] |
28 | 33 | * Config on how hosted Git works (default: detected from repo); |
29 | 34 | * `github.com`, `gitlab.com`, or `bitbucket.org` work automatically; |
|
79 | 84 | * Path to file. |
80 | 85 | * @property {string | null | undefined} root |
81 | 86 | * Path to Git folder. |
| 87 | + * @property {ReadonlyArray<RegExp>} skipPathPatterns |
| 88 | + * List of patterns for paths that should be skipped. |
82 | 89 | * @property {Readonly<UrlConfig>} urlConfig |
83 | 90 | * Configuration. |
84 | 91 | */ |
@@ -195,6 +202,11 @@ const readmeBasename = /^readme$/i |
195 | 202 | */ |
196 | 203 | export default function remarkValidateLinks(options, fileSet) { |
197 | 204 | const settings = options || {} |
| 205 | + const skipPathPatterns = settings.skipPathPatterns |
| 206 | + ? settings.skipPathPatterns.map(function (d) { |
| 207 | + return typeof d === 'string' ? new RegExp(d) : d |
| 208 | + }) |
| 209 | + : [] |
198 | 210 |
|
199 | 211 | // Attach a `completer`. |
200 | 212 | if (fileSet) { |
@@ -270,6 +282,7 @@ export default function remarkValidateLinks(options, fileSet) { |
270 | 282 | base: absolute ? path.dirname(absolute) : file.cwd, |
271 | 283 | path: absolute, |
272 | 284 | root, |
| 285 | + skipPathPatterns, |
273 | 286 | urlConfig |
274 | 287 | } |
275 | 288 | /** @type {Set<string>} */ |
@@ -310,6 +323,15 @@ export default function remarkValidateLinks(options, fileSet) { |
310 | 323 | if (info) { |
311 | 324 | const fp = info.filePath |
312 | 325 | const hash = info.hash |
| 326 | + const together = fp + (hash ? '#' + hash : '') |
| 327 | + |
| 328 | + if ( |
| 329 | + state.skipPathPatterns.some(function (skipPattern) { |
| 330 | + return skipPattern.test(together) |
| 331 | + }) |
| 332 | + ) { |
| 333 | + return |
| 334 | + } |
313 | 335 |
|
314 | 336 | addReference(fp, '', node) |
315 | 337 |
|
@@ -556,12 +578,14 @@ async function checkAll(files) { |
556 | 578 | * Landmarks. |
557 | 579 | * @param {ReferenceInfo} reference |
558 | 580 | * Reference. |
| 581 | + * @returns {undefined} |
| 582 | + * Nothing. |
559 | 583 | */ |
560 | 584 | function warn(landmarks, reference) { |
561 | 585 | const absolute = reference.file.path |
562 | 586 | ? path.resolve(reference.file.cwd, reference.file.path) |
563 | 587 | : '' |
564 | | - const base = absolute ? path.dirname(absolute) : null |
| 588 | + const base = absolute ? path.dirname(absolute) : undefined |
565 | 589 | const filePath = base |
566 | 590 | ? path.relative(base, reference.reference.filePath) |
567 | 591 | : reference.reference.filePath |
|
0 commit comments