Skip to content

fix(eslint-plugin): support pageExtensions in no-html-link-for-pages rule#94092

Open
AliMahmoudDev wants to merge 3 commits into
vercel:canaryfrom
AliMahmoudDev:fix/eslint-no-html-link-page-extensions
Open

fix(eslint-plugin): support pageExtensions in no-html-link-for-pages rule#94092
AliMahmoudDev wants to merge 3 commits into
vercel:canaryfrom
AliMahmoudDev:fix/eslint-no-html-link-page-extensions

Conversation

@AliMahmoudDev
Copy link
Copy Markdown

Fixes #53473

The @next/next/no-html-link-for-pages ESLint rule was hardcoded to only recognize .js, .jsx, .ts, .tsx file extensions. When users configure custom pageExtensions in next.config.js, the rule produces false positives and false negatives.

Changes:

  • Modified parseUrlForPages and parseUrlForAppDir to accept custom extension regex
  • Added support for settings.next.pageExtensions
  • Removed TODO comments about page extensions

…rule

Fixes vercel#53473

The no-html-link-for-pages rule was hardcoded to only match .js, .jsx,
.ts, .tsx file extensions. When users configure custom pageExtensions
in next.config.js (e.g. ['page.tsx', 'page.ts']), the rule would
produce false positives/negatives.

Changes:
- Added pageExtensions support via eslint settings.next.pageExtensions
- Modified parseUrlForPages and parseUrlForAppDir to accept custom
  extension regex patterns
- Updated getUrlFromPagesDirectories and getUrlFromAppDirectory
  signatures to pass through extension regexes
- Removed hardcoded TODO comments about page extensions support

Usage in .eslintrc:
  settings: {
    next: {
      pageExtensions: ['page.tsx', 'page.ts']
    }
  }
Comment thread packages/eslint-plugin-next/src/rules/no-html-link-for-pages.ts Outdated
Comment thread packages/eslint-plugin-next/src/rules/no-html-link-for-pages.ts Outdated
…y safety

- Pass extPattern string instead of RegExp objects to memoized functions,
  fixing cache key collision (JSON.stringify(regex) returns '{}' for all)
- Properly escape regex special characters in extension patterns to prevent
  false-positive file matches
Comment thread packages/eslint-plugin-next/src/utils/url.ts
…ttern

- Split extPattern by '|' and escape each extension individually before
  rejoining, so that regex special characters in extensions (e.g. dots
  in 'custom.ext') are properly escaped as literals
- Previously, escapeRegExp was applied to the entire pipe-joined pattern,
  which also escaped the '|' alternation operators, causing the regex to
  never match any file extensions
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