Skip to content

fix(rust-docs): use [lib].name override + prefix bare-filename links#64

Merged
WomB0ComB0 merged 1 commit into
mainfrom
fix/rust-libname-and-bare-links
May 10, 2026
Merged

fix(rust-docs): use [lib].name override + prefix bare-filename links#64
WomB0ComB0 merged 1 commit into
mainfrom
fix/rust-libname-and-bare-links

Conversation

@WomB0ComB0
Copy link
Copy Markdown
Member

Two issues caught from the first cargo-doc-md run (resq-software/docs#63):

1. resq-bin fell through to README stub

`resq-bin` has `lib.rs` but its `Cargo.toml` sets `[lib].name = "bin_explorer"`, overriding the default snake_case-of-package-name. `cargo-doc-md` uses the lib name for output dirs, so `target/doc-md/bin_explorer/` exists but my snake-case lookup checked `target/doc-md/resq_bin/` and missed it.

Parse `[lib].name` from each crate's `Cargo.toml` and use that for the rustdoc output lookup. Falls back to snake_case of the package name when not set.

2. cargo-doc-md emits bare-filename links

28 broken-link errors across 4 files: `config.md`, `commands/audit.md`, etc. Mintlify only resolves `./`, `../`, or absolute paths. Add the same Python-based prefix step the TypeScript template uses to add `./` to bare relative `.md` link targets.

Two issues from the first multi-package rustdoc run:

1. resq-bin fell through to the README stub even though it has a
   lib.rs. Cargo allows a custom [lib].name (resq-bin sets it to
   bin_explorer), which overrides the default snake_case of the
   package name. cargo-doc-md uses the lib name for output dirs.
   Parse [lib].name from each crate's Cargo.toml and use that for
   the rustdoc output lookup.

2. cargo-doc-md emits cross-references as bare relative paths
   (config.md, commands/audit.md) which Mintlify rejects as broken
   (28 links across 4 files). Add the same prefix-with-./ step the
   TypeScript template uses.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 10, 2026

Warning

Rate limit exceeded

@WomB0ComB0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 16 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd2bcb75-af2b-417a-8304-69ad57414b0f

📥 Commits

Reviewing files that changed from the base of the PR and between cc78942 and dad0789.

📒 Files selected for processing (1)
  • automation/source-repo-templates/api-docs.rust.yml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rust-libname-and-bare-links

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the area:content MDX/MD documentation content label May 10, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Rust API documentation template to correctly handle custom library names defined in Cargo.toml and introduces a new step to prefix bare relative Markdown links with ./ for Mintlify compatibility. Feedback identifies several issues in the link prefixing Python script, including a greedy regex that fails on multiple links per line, a potential IndexError for empty link targets, and lack of support for links containing titles or trailing whitespace. Additionally, it is recommended to use explicit project lists instead of automated file discovery via rglob.

Comment on lines +314 to +335
link_re = re.compile(r'(?<!\!)\[([^\]]*)\]\(([^)]+)\)')

def is_qualified(target: str) -> bool:
t = target.strip().split(None, 1)[0]
if t.startswith(("./", "../", "/", "#")):
return True
if ":" in t.split("/", 1)[0]:
return True
return False

for f in pathlib.Path(".").rglob("*.md"):
text = f.read_text(encoding="utf-8")
def fix(m: re.Match) -> str:
label, target = m.group(1), m.group(2)
if is_qualified(target):
return m.group(0)
if not target.endswith(".md") and ".md#" not in target:
return m.group(0)
return f"[{label}](./{target})"
new = link_re.sub(fix, text)
if new != text:
f.write_text(new, encoding="utf-8")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The link prefixing logic has a few issues that could lead to incorrect documentation or script failures:

  1. Greedy Regex: The regex ([^)]+) for the link target is greedy. On lines with multiple links (e.g., [a](b.md) and [c](d.md)), it will match from the first [ to the last ), causing the rewriter to fail or produce corrupted output. Using a non-greedy quantifier +? is necessary.
  2. Potential IndexError: In is_qualified, target.strip().split(None, 1)[0] will raise an IndexError if the link target is empty or contains only whitespace (e.g., []()). While rare in generated docs, the script should handle this gracefully.
  3. Extension Check Robustness: The fix function checks target.endswith(".md"). If a link includes a title (e.g., [label](file.md "title")) or trailing whitespace, this check will fail, and the link won't be prefixed with ./, leaving it broken in Mintlify.
  4. Automated Discovery: The script uses rglob("*.md") to discover files. Per repository guidelines, prefer explicit project lists over automated discovery in CI workflows if the repository structure contains duplicate project configurations (such as shadow copies) or if manual oversight of the public API surface is necessary to distinguish between public and internal components.

Note that these same patterns appear to be present in the TypeScript template as well.

          link_re = re.compile(r'(?<!\!)\[([^\]]*)\]\(([^)]+?)\)')

          def is_qualified(target: str) -> bool:
              parts = target.strip().split(None, 1)
              if not parts:
                  return True
              t = parts[0]
              if t.startswith(("./", "../", "/", "#")):
                  return True
              if ":" in t.split("/", 1)[0]:
                  return True
              return False

          for f in pathlib.Path(".").rglob("*.md"):
              text = f.read_text(encoding="utf-8")
              def fix(m: re.Match) -> str:
                  label, target = m.group(1), m.group(2)
                  if is_qualified(target):
                      return m.group(0)
                  url_part = target.strip().split(None, 1)[0]
                  if not url_part.endswith(".md") and ".md#" not in url_part:
                      return m.group(0)
                  return f"[{label}](./{target})"
              new = link_re.sub(fix, text)
              if new != text:
                  f.write_text(new, encoding="utf-8")
References
  1. Prefer explicit project lists over automated discovery (e.g., via grep) in CI workflows if the repository structure contains duplicate project configurations (such as shadow copies) or if manual oversight of the public API surface is necessary to distinguish between public and internal components.

@WomB0ComB0 WomB0ComB0 merged commit 5c9baba into main May 10, 2026
13 checks passed
@WomB0ComB0 WomB0ComB0 deleted the fix/rust-libname-and-bare-links branch May 10, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:content MDX/MD documentation content

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants