Skip to content

fix(lint-mdx): stop flagging closing code fences as missing a language - #1805

Open
bayrakdarerdem wants to merge 1 commit into
base:masterfrom
bayrakdarerdem:fix/lint-mdx-closing-fence-false-positive
Open

fix(lint-mdx): stop flagging closing code fences as missing a language#1805
bayrakdarerdem wants to merge 1 commit into
base:masterfrom
bayrakdarerdem:fix/lint-mdx-closing-fence-false-positive

Conversation

@bayrakdarerdem

Copy link
Copy Markdown

Summary

checkCodeBlocks() in scripts/lint-mdx.js matched every line starting with ``` the same way, opening and closing fences alike. Closing fences never carry a language, so every single fenced code block in the docs —
thousands of them was reported as "Code block missing language specifier" on its closing line.

Before / after

Running node scripts/lint-mdx.js all:

  • Before: 349 files checked, 1246 errors, 75 warnings
  • After: 349 files checked, 100 errors, 74 warnings

Fix

The function now tracks the length of the currently-open fence and only treats a ``` line as a new opening fence when not already inside a block.

This also fixes a related edge case surfaced while writing the fix: two files (agents/plugins/custom-plugins.mdx and
base-account/guides/authenticate-users.mdx) use a 4-backtick fence to show a literal 3-backtick code sample as content. A plain boolean would have treated that inner 3-backtick line as a real closing fence and gotten out of sync for the rest of the file, so the fix tracks fence length and only closes a block on a fence at least as long as the one that opened it
(matching CommonMark's nested-fence rule).

The <CodeGroup> label check is unchanged in behavior; it's simplified now that the surrounding opening/closing logic no longer needs it to compensate.

Verification

Spot-checked several of the ~100 remaining reported issues directly in the source files to confirm they're real (genuine language-less code blocks, missing frontmatter, multiple H1s, etc.) no false positives
left in the sample I checked.

checkCodeBlocks() matched every line starting with ``` the same way,
opening and closing fences alike. Closing fences never carry a
language, so every single fenced code block in the docs -- thousands
of them -- was reported as "Code block missing language specifier" on
its closing line.

Running `node scripts/lint-mdx.js all` before this change:
  349 files checked, 1246 errors, 75 warnings

After:
  349 files checked, 100 errors, 74 warnings

The function now tracks the length of the currently-open fence and
only treats a ``` line as a new opening fence when not already inside
a block. This also fixes a related edge case surfaced while writing
the fix: two files (agents/plugins/custom-plugins.mdx and
base-account/guides/authenticate-users.mdx) use a 4-backtick fence to
show a literal 3-backtick code sample as content. A plain boolean
would have treated that inner 3-backtick line as a real closing fence
and gotten out of sync for the rest of the file, so the fix tracks
fence length and only closes a block on a fence at least as long as
the one that opened it (matching CommonMark's nested-fence rule).

The CodeGroup label check is unchanged in behavior; it's simplified
now that the surrounding opening/closing logic no longer needs it to
compensate.

Verified the ~100 remaining reported issues are real (genuine
language-less code blocks, missing frontmatter, multiple H1s, etc.)
by spot-checking several files directly.

Assisted by Claude (Anthropic).
@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.

2 participants