Skip to content

Commit cbeaa0f

Browse files
authored
feat: ignore query strings with exclude option (#104)
1 parent 8957a8c commit cbeaa0f

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

.changeset/tricky-apes-invite.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'starlight-links-validator': minor
3+
---
4+
5+
Ignores query strings when checking for [excluded links](https://starlight-links-validator.vercel.app/configuration#exclude).
6+
7+
Previously, to exclude links with query strings, you may have needed to rely on fairly loose glob patterns, e.g. `/playground/**` to exclude `/playground/`, `/playground/?id=foo` and `/playground/?id=bar`. With this change, excluding `/playground/` will ignore all query strings, so `/playground/`, `/playground/?id=foo` and `/playground/?id=bar` will all be excluded.

packages/starlight-links-validator/libs/validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function isValidAsset(path: string, context: ValidationContext) {
249249
* Check if a link is excluded from validation by the user.
250250
*/
251251
function isExcludedLink(link: Link, context: ValidationContext) {
252-
return picomatch(context.options.exclude)(link.raw)
252+
return picomatch(context.options.exclude)(stripQueryString(link.raw))
253253
}
254254

255255
function stripQueryString(path: string): string {

packages/starlight-links-validator/tests/exclude.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ test('ignores links that are excluded from validation', async () => {
99

1010
expect(status).toBe('error')
1111

12-
expectValidationErrorCount(output, 6, 1)
12+
expectValidationErrorCount(output, 7, 1)
1313

1414
expectValidationErrors(output, '/', [
1515
['/excluded/', ValidationErrorType.InvalidLink],
16+
['/excluded/?something', ValidationErrorType.InvalidLink],
1617
['/excluded#test', ValidationErrorType.InvalidLink],
1718
['/test/excluded', ValidationErrorType.InvalidLink],
1819
['/test/excluded/test', ValidationErrorType.InvalidLink],

packages/starlight-links-validator/tests/fixtures/exclude/src/content/docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ title: Index
1313
# Exclude
1414

1515
- [Excluded link](/excluded)
16+
- [Excluded link with query string](/excluded?something)
1617

1718
- [Non-excluded link](/excluded/)
19+
- [Non-excluded link with query string](/excluded/?something)
1820
- [More non-excluded link](/excluded#test)
1921
- [Another non-excluded link](/test/excluded)
2022
- [And another non-excluded link](/test/excluded/test)

0 commit comments

Comments
 (0)