docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

fix(eslint-plugin): support template literals in no-html-links rule

Open Injora opened this issue 7 months ago • 1 comments

Pre-flight checklist

  • [x] I have read the Contributing Guidelines on pull requests.
  • [x] If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • [ ] If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

This pull request resolves a // TODO in the no-html-links ESLint rule regarding TemplateLiteral parsing. Previously, the rule could not statically determine the validity of a URL if a template literal contained interpolated JSX expressions (e.g., <a href={\https://example.com/docs/${id}`} />`), causing it to fail.

This change introduces a base URL prefix check. By evaluating the string segment before the first variable to ensure it contains a valid protocol (https://, mailto:, etc.), the parser can now correctly allow fully resolved external links written as template literals.

Test Plan

  • Updated packages/eslint-plugin/src/rules/no-html-links.ts to implement the prefix checking logic.
  • Moved the previously disabled test case for interpolated template literals to the valid assertions array in packages/eslint-plugin/src/rules/__tests__/no-html-links.test.ts.
  • Verified the fix by successfully running the unit tests: yarn test packages/eslint-plugin/src/rules/__tests__/no-html-links.test.ts.

Test links

Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/

Related issues/PRs

N/A

Injora avatar Apr 06 '26 06:04 Injora

[V2]

Built without sensitive environment variables

Name Link
Latest commit 9af66e65a8c0205eb644921d3fd681b5f0f0efee
Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69d3d12d7c6a3b0008fce9a8
Deploy Preview https://deploy-preview-11907--docusaurus-2.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify avatar Apr 06 '26 06:04 netlify