From c9001ab98a5786769e63e8c794239ff13790acca Mon Sep 17 00:00:00 2001 From: HiDeoo <494699+HiDeoo@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:25:31 +0100 Subject: [PATCH] fix: fixes validation issue with the Astro `trailingSlash` option for root pages --- packages/starlight-links-validator/libs/validation.ts | 5 +++-- .../tests/fixtures/trailing-always/src/content/docs/index.md | 5 +++++ .../tests/fixtures/trailing-always/src/content/docs/test.md | 2 ++ .../tests/fixtures/trailing-never/src/content/docs/index.md | 5 +++++ .../tests/fixtures/trailing-never/src/content/docs/test.md | 2 ++ 5 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 packages/starlight-links-validator/tests/fixtures/trailing-always/src/content/docs/index.md create mode 100644 packages/starlight-links-validator/tests/fixtures/trailing-never/src/content/docs/index.md diff --git a/packages/starlight-links-validator/libs/validation.ts b/packages/starlight-links-validator/libs/validation.ts index 875876f..97e6ec8 100644 --- a/packages/starlight-links-validator/libs/validation.ts +++ b/packages/starlight-links-validator/libs/validation.ts @@ -151,8 +151,9 @@ function validateLink(context: ValidationContext) { } if ( - (astroConfig.trailingSlash === 'always' && !path.endsWith('/')) || - (astroConfig.trailingSlash === 'never' && path.endsWith('/')) + path.length > 0 && + ((astroConfig.trailingSlash === 'always' && !path.endsWith('/')) || + (astroConfig.trailingSlash === 'never' && path.endsWith('/'))) ) { addError(errors, filePath, link, ValidationErrorType.TrailingSlash) return diff --git a/packages/starlight-links-validator/tests/fixtures/trailing-always/src/content/docs/index.md b/packages/starlight-links-validator/tests/fixtures/trailing-always/src/content/docs/index.md new file mode 100644 index 0000000..e9dde0f --- /dev/null +++ b/packages/starlight-links-validator/tests/fixtures/trailing-always/src/content/docs/index.md @@ -0,0 +1,5 @@ +--- +title: Home +--- + +This is the home page. diff --git a/packages/starlight-links-validator/tests/fixtures/trailing-always/src/content/docs/test.md b/packages/starlight-links-validator/tests/fixtures/trailing-always/src/content/docs/test.md index e3a9cf4..ca2615b 100644 --- a/packages/starlight-links-validator/tests/fixtures/trailing-always/src/content/docs/test.md +++ b/packages/starlight-links-validator/tests/fixtures/trailing-always/src/content/docs/test.md @@ -6,6 +6,8 @@ title: Test - [External link](https://starlight.astro.build/) +- [Honme page](/) + - [Example page](/guides/example) - [Example page](/guides/example/) diff --git a/packages/starlight-links-validator/tests/fixtures/trailing-never/src/content/docs/index.md b/packages/starlight-links-validator/tests/fixtures/trailing-never/src/content/docs/index.md new file mode 100644 index 0000000..e9dde0f --- /dev/null +++ b/packages/starlight-links-validator/tests/fixtures/trailing-never/src/content/docs/index.md @@ -0,0 +1,5 @@ +--- +title: Home +--- + +This is the home page. diff --git a/packages/starlight-links-validator/tests/fixtures/trailing-never/src/content/docs/test.md b/packages/starlight-links-validator/tests/fixtures/trailing-never/src/content/docs/test.md index e3a9cf4..ca2615b 100644 --- a/packages/starlight-links-validator/tests/fixtures/trailing-never/src/content/docs/test.md +++ b/packages/starlight-links-validator/tests/fixtures/trailing-never/src/content/docs/test.md @@ -6,6 +6,8 @@ title: Test - [External link](https://starlight.astro.build/) +- [Honme page](/) + - [Example page](/guides/example) - [Example page](/guides/example/)