Skip to content

fix(metadata): preserve -- prefix in anchor IDs for CLI flags#758

Open
sujalgoel wants to merge 1 commit intonodejs:mainfrom
sujalgoel:fix/anchor-double-hyphen-prefix
Open

fix(metadata): preserve -- prefix in anchor IDs for CLI flags#758
sujalgoel wants to merge 1 commit intonodejs:mainfrom
sujalgoel:fix/anchor-double-hyphen-prefix

Conversation

@sujalgoel
Copy link
Copy Markdown
Contributor

Fixes #757.

In v25, CLI flag headings like --permission produce anchor #permission
instead of #--permission, breaking links that worked in v24.

Two regexes in DOC_API_SLUGS_REPLACEMENTS caused this. The leading
hyphen rule (^-+(?!-*$)) stripped all leading hyphens unconditionally.
The consecutive hyphen rule (^(?!-+$).*?(--+)) also fired on anything
starting with --.

Changes in constants.mjs:

  • Leading hyphen: ^-+(?!-*$) -> ^-(?=[^-]). Strips only a single
    - not followed by another, so --permission passes through.
  • Consecutive hyphens: added [^-] after the start anchor so the rule
    skips ---prefixed slugs.

Changes in slugger.test.mjs:

  • Updated --foo expectation from 'foo' to '--foo'
  • Added tests for --permission and --allow-fs-read

Test plan

  • node --run test
  • node --run lint
  • node --run format

Two regexes in DOC_API_SLUGS_REPLACEMENTS were stripping -- from the
start of slugs, turning --permission into permission and breaking
existing links.

Fixes nodejs#757
@sujalgoel sujalgoel requested a review from a team as a code owner April 9, 2026 05:54
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Apr 9, 2026 5:55am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 9, 2026

PR Summary

Medium Risk
Changes slug/anchor generation regexes for API docs; low code complexity but can affect many generated anchor IDs and inbound links if edge cases are missed.

Overview
Fixes Node.js API doc anchor generation so headings that are CLI flags keep their -- prefix (e.g., --permission now slugs to --permission instead of dropping hyphens).

Updates the DOC_API_SLUGS_REPLACEMENTS regexes to only strip a single leading hyphen and to avoid the consecutive-hyphen normalization rule firing on ---prefixed strings, and adjusts/adds tests to cover these CLI-flag cases.

Reviewed by Cursor Bugbot for commit 079de38. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.44%. Comparing base (2765300) to head (079de38).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #758      +/-   ##
==========================================
+ Coverage   78.42%   78.44%   +0.01%     
==========================================
  Files         157      157              
  Lines       13959    13969      +10     
  Branches     1152     1155       +3     
==========================================
+ Hits        10948    10958      +10     
  Misses       3006     3006              
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

[v25] Anchors without -- prefix

1 participant