-
-
Notifications
You must be signed in to change notification settings - Fork 13
fix: disambiguate duplicate TOC anchors and persist empty TOC #466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Track anchor occurrences using a Map and append numeric suffixes (-1, -2, etc.) for duplicate headers like GitHub does - Remove early return when no headers found; now properly clears stale TOC by updating section with empty content - Add comprehensive test suite for update-contents (14 tests) https://claude.ai/code/session_01Jc7bzM5ZUmsgkWG6Vjq1Nx
Move eslint disable from inline comments to eslint config for test files, as vi.mocked() often triggers false positives. https://claude.ai/code/session_01Jc7bzM5ZUmsgkWG6Vjq1Nx
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
|
🎉 This PR is included in version 1.9.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Improves TOC generation to better match GitHub anchor behavior for duplicate headings and ensures stale TOC sections are cleared when no headers are found.
Changes:
- Disambiguate duplicate TOC anchors by tracking occurrences and appending numeric suffixes.
- Remove early return when no headers are found so the TOC section can be cleared to empty.
- Add a dedicated
updateContentstest suite and adjust ESLint config to avoid per-file rule disables in tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/sections/update-contents.ts | Adds duplicate-anchor suffixing and ensures empty TOC updates clear the section. |
| eslint.config.mjs | Disables @typescript-eslint/unbound-method for __tests__/** to avoid repeated inline disables. |
| tests/update-contents.test.ts | Adds comprehensive coverage for TOC generation, including duplicates and code-block handling. |
| tests/readme-generator.test.ts | Removes now-unnecessary file-level unbound-method disable. |
| tests/action.test.ts | Removes now-unnecessary file-level unbound-method disable. |
| // Find minimum header level for proper indentation | ||
| const minLevel = Math.min(...tocHeaders.map((h) => h.level)); | ||
|
|
||
| // Track anchor occurrences to disambiguate duplicates like GitHub does | ||
| const anchorCounts = new Map<string, number>(); |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplicate-anchor disambiguation only counts occurrences within tocHeaders (H2–H6 excluding “contents”). GitHub’s generated heading IDs count all headings in document order (including H1 and any excluded headings), so cases like # Features followed by ## Features will render the H2 as #features-1 on GitHub but this TOC will link to #features (wrong target). Consider computing unique anchors by iterating over the full extracted headers list in order (building a per-heading anchor field using a shared anchorCounts map), then filtering to TOC entries and reusing those precomputed anchors; add a regression test for the H1/H2 duplicate case.
(-1, -2, etc.) for duplicate headers like GitHub does
stale TOC by updating section with empty content
https://claude.ai/code/session_01Jc7bzM5ZUmsgkWG6Vjq1Nx