Skip to content

fix(eslint-plugin-next): respect pageExtensions in no-html-link-for-pages#93853

Open
Eswar809 wants to merge 1 commit into
vercel:canaryfrom
Eswar809:fix/53473-pageExtensions-in-no-html-link-for-pages
Open

fix(eslint-plugin-next): respect pageExtensions in no-html-link-for-pages#93853
Eswar809 wants to merge 1 commit into
vercel:canaryfrom
Eswar809:fix/53473-pageExtensions-in-no-html-link-for-pages

Conversation

@Eswar809
Copy link
Copy Markdown

What?

Fixes #53473.

The no-html-link-for-pages ESLint rule had a hardcoded /(\.(j|t)sx?)$/ regex when scanning the pages and app directories, so projects that configure custom pageExtensions (e.g. ['page.tsx', 'page.ts']) got false negatives — none of their actual page files were detected as routes, and the rule silently skipped them.

Why?

This matches the existing settings.next.rootDir convention already supported by this plugin. The hardcoded regex was a known limitation flagged by TODO comments in packages/eslint-plugin-next/src/utils/url.ts:

// TODO: this should account for all page extensions
// not just js(x) and ts(x)

How?

  • Adds a new settings.next.pageExtensions shared setting, read by no-html-link-for-pages and threaded through parseUrlForPages, parseUrlForAppDir, getUrlFromPagesDirectories, and getUrlFromAppDirectory.
  • The extension regex is built dynamically from the configured list (special regex characters are escaped) and falls back to the previous default ['tsx', 'ts', 'jsx', 'js'] when the setting is absent, so existing rule configurations behave identically.
  • Adds a test fixture (test/unit/eslint-plugin-next/with-page-extensions/) and a test case verifying that <a href="/about"> is correctly flagged when the corresponding file is pages/about.page.tsx and pageExtensions is configured.

Test plan

  • New unit test covers the bug.
  • All existing tests for this rule still pass with the default behavior preserved (default pageExtensions matches the previous regex exactly).

Closes #53473

…ages

Fixes vercel#53473.

The no-html-link-for-pages rule used a hardcoded `/(\.(j|t)sx?)$/` regex
when scanning the pages and app directories for routes, so projects that
configure custom `pageExtensions` (for example `['page.tsx', 'page.ts']`)
got false negatives — none of their actual page files were detected as
routes.

This adds a `settings.next.pageExtensions` shared setting (matching the
existing `settings.next.rootDir` convention) and threads it through
`parseUrlForPages`, `parseUrlForAppDir`, `getUrlFromPagesDirectories`
and `getUrlFromAppDirectory`. The extension regex is built dynamically
from the configured list, with regex special characters escaped, and
falls back to the previous default of [tsx, ts, jsx, js] when the
setting is absent — so existing rule configurations behave identically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@next/next/no-html-link-for-pages rule does not work with pageExtensions

1 participant