From f72ea25b3b702d85f12679f0e70ccea06602fad5 Mon Sep 17 00:00:00 2001 From: Leonel Rivas Date: Wed, 17 Jun 2026 11:21:45 -0700 Subject: [PATCH] fix(lint): match @font-face when a comment inside the block holds a brace (#1538) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit font_family_without_font_face (and system_font_will_alias) collect @font-face blocks with `@font-face\s*\{[^}]*\}`, which stops at the first `}`. A CSS comment inside the block that contains a brace — `@font-face { /* 400 } regular */ font-family: 'X'; ... }` — truncates the match before the font-family, so the family is never recorded as declared and a later `font-family: 'X'` usage is wrongly flagged as used without an @font-face. Strip CSS comments before scanning so a brace inside one cannot split a block. Refs #1534 --- packages/core/src/lint/rules/fonts.test.ts | 11 +++++++++++ packages/core/src/lint/rules/fonts.ts | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/core/src/lint/rules/fonts.test.ts b/packages/core/src/lint/rules/fonts.test.ts index 395bdafcf..6e28c881a 100644 --- a/packages/core/src/lint/rules/fonts.test.ts +++ b/packages/core/src/lint/rules/fonts.test.ts @@ -215,5 +215,16 @@ describe("font rules", () => { const findings = await findByCode(html, "font_family_without_font_face"); expect(findings).toHaveLength(0); }); + + it("matches @font-face even when a CSS comment inside the block contains a brace (#1534)", async () => { + const html = `
+ +
`; + const findings = await findByCode(html, "font_family_without_font_face"); + expect(findings).toHaveLength(0); + }); }); }); diff --git a/packages/core/src/lint/rules/fonts.ts b/packages/core/src/lint/rules/fonts.ts index 9f84a3401..0f61d9ce3 100644 --- a/packages/core/src/lint/rules/fonts.ts +++ b/packages/core/src/lint/rules/fonts.ts @@ -22,13 +22,25 @@ const GENERIC_FAMILIES = new Set([ "revert", ]); +// A CSS comment can contain a `}` (e.g. `@font-face { /* 400 } regular */ +// font-family: 'X'; ... }`), which truncates the naive `@font-face\s*\{[^}]*\}` +// block match at the comment's brace — so the rule never sees the real +// `font-family` and reports a false-positive font_family_without_font_face. +// Large/"framework" stylesheets hit this far more often than minimal ones, +// which is why a simple