Skip to content

Conversation

@Jamie-BitFlight
Copy link
Contributor

  • 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

- 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
Copilot AI review requested due to automatic review settings January 28, 2026 01:24
@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

Warning

Rate limit exceeded

@Jamie-BitFlight has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 4 seconds before requesting another review.

⌛ 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.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-toc-duplicate-anchors-d12Hr

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
Copy link
Contributor

github-actions bot commented Jan 28, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 52.28% 446 / 853
🔵 Statements 52.94% 459 / 867
🔵 Functions 66.66% 76 / 114
🔵 Branches 50.94% 215 / 422
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/sections/update-contents.ts 100% 93.75% 100% 100%
Generated in workflow #401 for commit 937fce9 by the Vitest Coverage Report Action

@Jamie-BitFlight Jamie-BitFlight merged commit 6ddba6d into main Jan 28, 2026
10 checks passed
@Jamie-BitFlight Jamie-BitFlight deleted the claude/fix-toc-duplicate-anchors-d12Hr branch January 28, 2026 01:26
@Jamie-BitFlight
Copy link
Contributor Author

🎉 This PR is included in version 1.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Jamie-BitFlight Jamie-BitFlight added the released This issue/pull request has been released. label Jan 28, 2026
Copy link

Copilot AI left a 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 updateContents test 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.

Comment on lines +90 to +94
// 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>();
Copy link

Copilot AI Jan 28, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released This issue/pull request has been released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants