fix(eslint-plugin): respect pageExtensions in no-html-link-for-pages rule#91602
Open
wabalabudabdab wants to merge 1 commit intovercel:canaryfrom
Open
fix(eslint-plugin): respect pageExtensions in no-html-link-for-pages rule#91602wabalabudabdab wants to merge 1 commit intovercel:canaryfrom
wabalabudabdab wants to merge 1 commit intovercel:canaryfrom
Conversation
The no-html-link-for-pages rule was matching page files using a hardcoded regex for .js, .jsx, .ts, .tsx extensions, ignoring any custom pageExtensions configured in next.config.js. This fix: - Adds a pageExtensions parameter to parseUrlForPages, parseUrlForAppDir, getUrlFromPagesDirectories, and getUrlFromAppDirectory in url.ts (resolves the TODO comments) - Adds getPageExtensions() in no-html-link-for-pages.ts that reads pageExtensions with the following priority: 1. ESLint settings (settings.next.pageExtensions) — explicit override 2. next.config.js / next.config.ts in the project root 3. Next.js defaults: ['js', 'jsx', 'ts', 'tsx'] Fixes vercel#53473
Collaborator
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
The
no-html-link-for-pagesESLint rule was ignoringpageExtensionsconfigured innext.config.js, causing false negatives for projects using custom page file extensions.Fixes #53473
Why?
In
url.ts,parseUrlForPagesandparseUrlForAppDirhad a hardcoded regex/(\.( j|t)sx?)$/with aTODOcomment acknowledging the limitation. This fix resolves those TODOs.How?
packages/eslint-plugin-next/src/utils/url.tspageExtensionsparameter (default:['js', 'jsx', 'ts', 'tsx']) toparseUrlForPages,parseUrlForAppDir,getUrlFromPagesDirectories, andgetUrlFromAppDirectorypackages/eslint-plugin-next/src/rules/no-html-link-for-pages.tsgetPageExtensions()helper that resolvespageExtensionswith the following priority:settings.next.pageExtensions) — explicit user override, consistent with howrootDiris configurednext.config.js/next.config.ts— auto-detected from the project root['js', 'jsx', 'ts', 'tsx']Testing
To test, create a Next.js project with:
Before this fix, the rule would not detect
<a>links to.page.tsxpages.After this fix, it correctly identifies them.