Skip to content

fix(lint-mdx): detect multi-line opening tags in component attribute check - #1796

Open
teyrebaz33 wants to merge 2 commits into
base:masterfrom
teyrebaz33:fix/lint-mdx-multiline-tag-attribute-check
Open

fix(lint-mdx): detect multi-line opening tags in component attribute check#1796
teyrebaz33 wants to merge 2 commits into
base:masterfrom
teyrebaz33:fix/lint-mdx-multiline-tag-attribute-check

Conversation

@teyrebaz33

Copy link
Copy Markdown

Fixes #1795

Problem

The opening-tag check in scripts/lint-mdx.js only matched tags against a regex applied to a single line. When a tag's name was on its own line with attributes spread across following lines, the regex never matched and the tag was silently skipped - no required-attribute check, no CardGroup cols check, no parent/child stack tracking.

Fix

The check now accumulates lines starting at a lone opening-tag line until a closing > is found, then matches the existing regex against the accumulated text. isSelfClosing was also updated to check the accumulated text instead of only the first line.

Scope

Found and fixed for 5 real multi-line tag instances across 2 files:

  • docs/base-account/quickstart/ai-tools-available-for-devs.mdx (3 Card tags)
  • docs/apps/resources/templates.mdx (2 Card tags)

Verification

  • node scripts/lint-mdx.js all: totals unchanged at 1246 errors / 70 warnings (all 5 tags already had valid required attributes, so this closes a detection gap without surfacing new findings)
  • Verified against a synthetic multi-line Card missing title=: now correctly flagged (previously silently skipped)

The alt-attribute check in checkMintlifyComponents only looked at the
single line containing '<img', so when an <img> tag's attributes were
spread across multiple lines (a common JSX formatting style used
throughout docs/), a present alt= attribute on a later line was never
seen and the linter reported a false-positive missing-alt warning.

This affected 5 warnings across 3 files that already had a valid
alt attribute:
- docs/base-account/improve-ux/sponsor-gas/paymasters.mdx (2)
- docs/base-account/reference/ui-elements/brand-guidelines.mdx (2)
- docs/snippets/BasePayButton.mdx (1)

The check now accumulates lines starting at the <img> tag until the
tag closes (or end of file), matching the multi-line lookback pattern
already used by the adjacent <Frame>-wrapping check in the same file.

Verified with node scripts/lint-mdx.js all: warnings drop from 75 to
70 (exactly the 5 false positives), errors unchanged at 1246. Also
verified against a synthetic missing-alt case and a synthetic
multi-line-with-alt case to confirm the check still catches real
violations and doesn't over-suppress.
…check

The opening-tag check in checkMintlifyComponents matched tags against
a regex applied only to the current line. When a tag's name was on
its own line with attributes spread across the following lines (e.g.
<Card on one line, title=... on the next), the regex never matched,
so the tag was silently skipped entirely - no required-attribute
check, no CardGroup cols check, no parent/child stack tracking.

Found 5 such multi-line tags across 2 files, all with valid required
attributes that were never actually being checked before this fix:
- docs/base-account/quickstart/ai-tools-available-for-devs.mdx (3 <Card> tags, lines 10, 47, 67)
- docs/apps/resources/templates.mdx (2 <Card> tags, lines 22, 28)

The check now accumulates lines starting at a lone opening-tag line
until a '>' is found, then matches the existing regex against the
accumulated text. isSelfClosing was also updated to check the
accumulated text instead of only the first line, since a multi-line
tag's closing '/>' would otherwise never be seen.

Verified with node scripts/lint-mdx.js all: totals unchanged at
1246 errors / 70 warnings (all 5 tags already had valid required
attributes, so this closes a detection gap without surfacing new
findings). Also verified against a synthetic multi-line <Card>
missing title=, which is now correctly flagged (previously would
have been silently skipped).
@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

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.

lint-mdx.js: multi-line opening tags (Card, CardGroup, etc.) silently skipped by attribute check

2 participants