-
Notifications
You must be signed in to change notification settings - Fork 29k
fix(eslint-plugin): respect custom pageExtensions in no-html-link-for… #80035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: canary
Are you sure you want to change the base?
fix(eslint-plugin): respect custom pageExtensions in no-html-link-for… #80035
Conversation
|
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 |
fc0c19c
to
007ebe0
Compare
This doesn't work with |
Good catch! You're right this currently only supports next.config.js. To support next.config.ts, we’d need either ts-node or a custom loader at runtime, which isn’t ideal in a linting context. I can update the implementation to try both .js and .ts if ts-node is available, or add a fallback warning. Let me know your thoughts |
b9fb27b
to
d9e69bc
Compare
Hi @balazsorban44 @ijjk is there something missing to get a CI approval? |
1 similar comment
Hi @balazsorban44 @ijjk is there something missing to get a CI approval? |
if (page.test(dirent.name)) { | ||
res.push(`${urlprefix}${dirent.name.replace(page, '')}`) | ||
} else if (!layout.test(dirent.name)) { | ||
res.push(`${urlprefix}${dirent.name.replace(ext, '')}`) | ||
} | ||
} else { | ||
const dirPath = path.join(directory, dirent.name) | ||
if (dirent.isDirectory(dirPath) && !dirent.isSymbolicLink()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a small issue with the isDirectory()
method call on line 57 of the parseUrlForAppDir
function. The method doesn't accept any parameters, but it's being called with dirPath
as an argument. This should be corrected to:
if (dirent.isDirectory() && !dirent.isSymbolicLink()) {
The isDirectory()
method is a property of the Dirent object that returns a boolean indicating whether the entry is a directory, and it doesn't need any arguments to function correctly.
if (dirent.isDirectory(dirPath) && !dirent.isSymbolicLink()) { | |
if (dirent.isDirectory() && !dirent.isSymbolicLink()) { |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
Hi @balazsorban44 @ijjk, is there anything missing on my side to get CI approval or move this PR (#80035) forward? Thanks! |
Hi @viniciuspizettadesouza, I'm working on this issue as part of my open source contribution course assignment. I noticed the PR doesn't support next.config.ts as mentioned by @darthmaim. I've implemented this fix and created a PR to your branch. Would you be open to reviewing and merging it to help move your PR forward? |
What?
Fixes a bug in the ESLint rule
@next/next/no-html-link-for-pages
, where it did not recognize internal pages using custompageExtensions
defined innext.config.js
.Why?
When users configure custom extensions (e.g.,
page.tsx
,mdx
), the rule still relied on a hardcoded default list (['js', 'jsx', 'ts', 'tsx']
). This led to false positives by incorrectly flagging valid internal links as invalid.This PR aligns the rule behavior with how Next.js resolves routes — respecting the developer’s intended page structure.
How?
getPageExtensions()
utility ineslint-plugin-next
to dynamically load and normalizepageExtensions
fromnext.config.js
getPageExtensions()
as a self-contained closure to:parseUrlForPages
andparseUrlForAppDir
to call it without receiving external paramsnext.config.js
is missing → uses defaultgetRegexPatterns()
to receive page extensions fromgetPageExtensions()
, ensuring:ext
andindex
patterns are correctly built from actual user configBenefits of the Closure Design
By using
getPageExtensions()
as a lazy, memoized closure:getRegexPatterns()
now cleanly depends on a single canonical source for extensionsAdditional Context
This change complements the fix in #68770, which resolved structural matching issues for App Router, but did not handle
pageExtensions
inpages/
linting.It also supersedes partial or outdated approaches in:
Fixes
Fixes #53473