feat(eslint): Add pageExtensions support to no-html-link-for-pages rule #86915
+99
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This PR adds support for custom
pageExtensionsconfiguration to the@next/next/no-html-link-for-pagesESLint rule.Why?
Currently, the ESLint rule only recognizes default Next.js page extensions (
.js,.jsx,.ts,.tsx) and ignores custom extensions configured viapageExtensionsinnext.config.js. This causes the linting rule to fail when projects use custom file extensions.Fixes #53473
How?
Changes Made:
packages/eslint-plugin-next/src/utils/url.ts:buildPageExtensionRegex()helper to generate dynamic regex from extensions arrayparseUrlForPages()to acceptpageExtensionsparameter with default fallbackparseUrlForAppDir()to acceptpageExtensionsparameter with default fallbackgetUrlFromPagesDirectories()andgetUrlFromAppDirectory()signatures to support custom extensionspackages/eslint-plugin-next/src/rules/no-html-link-for-pages.ts:getPageExtensions()function to readpageExtensionsfromnext.config.js.js,.mjs, and.tsconfig filesFeatures:
pageExtensionsfromnext.config.js,next.config.mjs, ornext.config.tsTesting
The implementation:
.page.tsx,.mdx, etc.Note: This is my first contribution to Next.js. I'd appreciate any feedback on the implementation approach!