Skip to content

Validate line highlight ranges in markdown code blocks - #8780

Open
PrashantSingh2618 wants to merge 1 commit into
reactjs:mainfrom
PrashantSingh2618:lint-line-highlight-ranges
Open

PrashantSingh2618 wants to merge 1 commit into
reactjs:mainfrom
PrashantSingh2618:lint-line-highlight-ranges

Conversation

@PrashantSingh2618

@PrashantSingh2618 PrashantSingh2618 commented Nov 30, 2026 •

Copy link
Copy Markdown

Code fence highlight metadata like ```js {3,7} can reference lines that don't exist in the code block. getHighlightLines() in CodeBlock.tsx silently ignores those lines, so the line the author meant to highlight is never highlighted. Nothing catches this today. #8645 added validation for inline [[step, line, "text"]] highlights, but not for line ranges.

This PR extends lint-markdown-code-blocks to report highlighted lines outside the code block. It uses the same pattern as getHighlightLines(). It also fixes the three existing cases, which have been wrong since the blocks were added:

Page Before After
cacheSignal {3,7} on a 4-line block {3}
Components and Hooks must be pure (2 blocks) {4} on 3-line blocks, so nothing is highlighted {2}, which highlights the "🔴 never mutate" and "✅ make a copy" lines

Test plan

  • New fixture out-of-bounds-line-highlight.md covers a single line and the end of a range past the code block. Valid ranges, including one ending on the last line, are added to valid-highlight.md.
  • The new test fails without the rule change and passes with it.
  • Before the content fixes, the rule flagged exactly these three blocks across src/content and nothing else.
  • yarn ci-check passes.

The pre-commit hook ran Prettier on lint-markdown-code-blocks.test.js, which also reformatted a few existing lines in that file.

Code fence metadata like `{3,7}` can reference lines past the end of the
code block. The site silently ignores those lines, so the line the author
meant to highlight is never highlighted.

Extend lint-markdown-code-blocks to report highlighted lines outside the
code block, using the same pattern as getHighlightLines() in
CodeBlock.tsx, and fix the three existing cases in the cacheSignal
reference and the "Components and Hooks must be pure" page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

This branch was successfully deployed

1 active deployment
Preview — 5727cc88 Deployed Nov 30, 2026 by vercel[bot]
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.

1 participant