Skip to content

fix(lint): match @font-face when a comment inside the block holds a brace#1538

Merged
miguel-heygen merged 1 commit into
heygen-com:mainfrom
leorivastech:fix/font-face-lint
Jun 17, 2026
Merged

fix(lint): match @font-face when a comment inside the block holds a brace#1538
miguel-heygen merged 1 commit into
heygen-com:mainfrom
leorivastech:fix/font-face-lint

Conversation

@leorivastech

Copy link
Copy Markdown
Contributor

What

font_family_without_font_face (and system_font_will_alias) collect declared
@font-face families with @font-face\s*\{[^}]*\}. [^}]* stops at the first
}, so a CSS comment inside the block that contains a brace truncates the match
before font-family: is reached:

@font-face { /* weight 400 } regular */ font-family: 'Noto Sans SC'; src: url('...'); }

The family is never recorded as declared, and a later literal
font-family: 'Noto Sans SC' is then reported as used without an @font-face
a blocking error since 0.6.109, where #1495 promoted this rule from warning to error.

Fix: strip CSS comments before scanning. In valid CSS the only source of a }
inside an @font-face block is a comment, so this closes the gap. It's the same
technique #1495 already applied to scene_layer_missing_visibility_kill ("strip
JS comments before pattern matching") and caption_transcript_parse_error
("balanced-bracket scanner replaces non-greedy regex") — just never applied to the
font rules.

Honest note on #1534

I believe this is the cause of #1534, but I want to be upfront: I could not
reproduce it with a clean @font-face, no matter how large/complex the
surrounding CSS was (tested 139-line blocks, 15 @keyframes, Fontsource-style
multi-line faces, comments that mention @font-face, two <style> blocks). The
only thing that reproduces the exact error is a brace inside the @font-face
block — realistically a comment. The reporter says the @font-face is byte-identical
between the passing and failing cases; if so, the failing file most likely has an
inline comment in the block that was dropped when minimizing the repro.

@Johnson-Jia — could you share the exact failing @font-face block (or the minimal
HTML) verbatim? If it carries a comment with a } inside, this fixes it; if not,
I'd like to track down the remaining mechanism. Marked Refs #1534 rather than
Fixes until that's confirmed.

Verification

  • Added a regression test (comment-with-brace inside @font-face); confirmed it
    goes red on main and green with this change.
  • packages/core: full lint suite 191/191, tsc --noEmit clean, and the
    pre-commit gate (oxlint + oxfmt + fallow audit) clean.

…race

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 heygen-com#1534
@miguel-heygen miguel-heygen merged commit f72ea25 into heygen-com:main Jun 17, 2026
44 of 46 checks passed
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