next.js icon indicating copy to clipboard operation
next.js copied to clipboard

fix: support pageExtensions in no-html-link-for-pages ESLint rule

Open harikapadia999 opened this issue 2 weeks ago • 1 comments

Description

Fixes #53473

The @next/next/no-html-link-for-pages ESLint rule now respects the pageExtensions configuration from next.config.js.

Problem

Previously, the rule only detected pages with hardcoded extensions (.js, .jsx, .ts, .tsx). When users configured custom pageExtensions in their next.config.js, the ESLint rule would fail to detect those pages, leading to false negatives.

Solution

  • Modified parseUrlForPages and parseUrlForAppDir functions to accept a pageExtensions parameter
  • Added buildExtensionRegex helper to dynamically build regex patterns based on configured extensions
  • Updated the ESLint rule to read pageExtensions from context.settings.next.pageExtensions
  • Pass the extensions to URL parsing functions

Usage

Users can now configure the rule in their .eslintrc.json:

{
  "settings": {
    "next": {
      "pageExtensions": ["page.tsx", "page.ts", "tsx", "ts"]
    }
  },
  "rules": {
    "@next/next/no-html-link-for-pages": ["error"]
  }
}

Changes

packages/eslint-plugin-next/src/utils/url.ts:

  • Added buildExtensionRegex() helper function
  • Updated parseUrlForPages() to accept and use pageExtensions parameter
  • Updated parseUrlForAppDir() to accept and use pageExtensions parameter
  • Updated getUrlFromPagesDirectories() and getUrlFromAppDirectory() to pass extensions

packages/eslint-plugin-next/src/rules/no-html-link-for-pages.ts:

  • Read pageExtensions from context.settings.next.pageExtensions
  • Pass extensions to URL parsing functions

Testing

  • Maintains backward compatibility (defaults to ['tsx', 'ts', 'jsx', 'js'])
  • Works with custom extensions like ['page.tsx', 'page.ts']
  • Correctly detects pages in both /pages and /app directories

Breaking Changes

None - fully backward compatible

harikapadia999 avatar Dec 08 '25 14:12 harikapadia999

Allow CI Workflow Run

  • [ ] approve CI run for commit: e33ea8bcf0d32dd3b659867c2418a40de7dac557

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

nextjs-bot avatar Dec 08 '25 14:12 nextjs-bot