Skip to content

feat(eslint): add fred/no-external-link-whitespace rule - #1886

Closed
caugner wants to merge 2 commits into
mainfrom
lint-external-link-whitespace
Closed

caugner wants to merge 2 commits into
mainfrom
lint-external-link-whitespace

Conversation

@caugner

@caugner caugner commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a custom ESLint rule fred/no-external-link-whitespace that flags <a> elements with the external class inside html templates whose content starts or ends with whitespace, with an autofix that strips it.

  • Rule + RuleTester unit tests in build/eslint-fred.js and test/unit/build/eslint-fred.test.js.
  • Enable the rule in eslint.config.js as warn, so it can land before the 14 existing violations are fixed.

Motivation

Ensure the external-link icon stays attached to the last word of the link. Whitespace before </a> renders as a space, so when the link text wraps, the icon drops onto its own line. Prettier introduces this whitespace whenever it wraps the link text onto its own line, so a lint rule is needed to keep it out.

Additional details

Prettier does not reintroduce the whitespace once removed: it formats a whitespace-free anchor as >${text}</a\n>, so the rule and the formatter are stable together.

Rari does not add whitespace to external links, and a scan of a fresh en-US content build found only one external link out of about 30k with trailing whitespace, so the templates in this repo are the main source.

Related issues and pull requests

@github-actions

Copy link
Copy Markdown
Contributor

56cdf09 was deployed to: https://fred-pr1886.review.mdn.allizom.net/

@caugner
caugner force-pushed the lint-external-link-whitespace branch from 725d701 to 797a75c Compare September 10, 2026 12:19
@caugner
caugner added this pull request to stack #1887 September 10, 2026 12:20
@caugner caugner changed the title feat(eslint): add fred/no-external-link-whitespace rule + strip whitespace in external links feat(eslint): add fred/no-external-link-whitespace rule Sep 10, 2026
Flag `<a>` elements with the `external` class inside `html` templates
whose content starts or ends with whitespace, and offer an autofix that
strips it. Whitespace before `</a>` renders as a space, which pushes the
external-link icon onto its own line when the text wraps.

Prettier does not reintroduce the whitespace once removed (it emits the
`>${text}</a\n>` form), so the rule and formatter are stable together.
Start at `warn` so the rule can land before the existing violations are
fixed; a follow-up elevates it to `error`.
@caugner
caugner force-pushed the lint-external-link-whitespace branch from 797a75c to ea168f4 Compare September 10, 2026 12:49
@caugner
caugner removed this pull request from stack #1887 September 14, 2026 15:09
@caugner

caugner commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of one-time fixes.

@caugner caugner closed this Sep 16, 2026
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.

2 participants