Skip to content

Automatically fix broken links #1459

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

Merged
merged 1 commit into from
Mar 5, 2025
Merged

Automatically fix broken links #1459

merged 1 commit into from
Mar 5, 2025

Conversation

krofax
Copy link
Collaborator

@krofax krofax commented Mar 5, 2025

Description

Implement Broken Links Auto-Fixer

This PR adds an automatic broken link fixer that extends our existing link checker to not only detect broken internal links but also repair them using intelligent path matching.

Features

  • Automatic Link Repair: Fixes broken internal links without manual intervention

  • Smart Path Detection: Uses multiple strategies to find the correct path:

    • Case-insensitive matching
    • Alternative file extension detection
    • Fuzzy matching with Levenshtein distance algorithm
  • Comprehensive Reporting: Shows detailed statistics about fixed vs unfixable links

  • Non-destructive Operation: Carefully modifies files without side effects

Tests

Additional context

Metadata

@krofax krofax requested a review from a team as a code owner March 5, 2025 18:50
Copy link

netlify bot commented Mar 5, 2025

Deploy Preview for docs-optimism ready!

Name Link
🔨 Latest commit 25806c8
🔍 Latest deploy log https://app.netlify.com/sites/docs-optimism/deploys/67c89d0f2e7d6c0008b36bb9
😎 Deploy Preview https://deploy-preview-1459--docs-optimism.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

📝 Walkthrough

Walkthrough

The changes update the project’s maintenance scripts and add functionality to handle broken links. In the package.json file, the existing "fix" script is extended by appending a new command (pnpm fix-links), and a new "fix-links" script is added to run a Node.js utility. The new utility in utils/fix-broken-links.ts scans documentation files, extracts links, identifies broken links, and attempts auto-fixes based on various criteria, ultimately generating a report. Additionally, a new entry (ethpandaops) has been appended to words.txt without altering its overall structure. These modifications streamline the process for maintaining link integrity across documentation while allowing further customization via configuration options.

Sequence Diagram(s)

sequenceDiagram
    participant U as User/Developer
    participant PM as Package Manager ("pnpm fix")
    participant FS as File System (Documentation Files)
    participant UT as fix-broken-links Utility
    participant RG as Report Generator

    U->>PM: Run "pnpm fix"
    PM->>UT: Execute "pnpm fix-links" script
    UT->>FS: Scan documentation files for links
    FS-->>UT: Return list of files
    UT->>UT: Extract links & identify broken links
    UT->>UT: Attempt auto-fix for each broken link
    UT->>RG: Generate audit report
    RG-->>UT: Return report summary
    UT->>PM: Return fixed link status and report
    PM->>U: Display aggregated fix report
Loading

Possibly related PRs

Suggested reviewers

  • cpengilly
  • bradleycamacho
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
utils/fix-broken-links.ts (5)

58-78: Consider adding a toggle for backups or integrating revision history.
Even though backupFiles is disabled by default, overwriting original files may risk accidental data loss during fixes. You may want to allow a simple rollback mechanism or track changes so users can revert if needed.


80-106: Potential concurrency optimization for large repositories.
The runLinkFixer function processes files sequentially, which may become slow if the codebase is large. Introducing concurrency or a pool-based approach to reading and writing files could improve performance. Ensure to handle potential race conditions carefully.


130-184: Enhance error reporting for broken links.
Currently, the script reports broken links but does not categorize the type of issue (e.g., file not found, link not recognized). Including more specific error messages — for instance, “File not found within docs directory” — could help users quickly diagnose problems.


186-279: Validate cross-file references or external imports conditionally.
The extractLinks function might encounter references to local or external resources. If intended to skip verifying external resources, ensure to highlight them differently or store them for a separate check. This can improve the clarity of the link-auditing process.


339-507: Consider user feedback loop and test coverage.
The fixBrokenLinks function automatically fixes broken links, which is great. However:
• It would be beneficial to gather user feedback in real-world scenarios to ensure the logic matches user expectations.
• Adding test coverage (unit tests or integration tests) would ensure the reliability of these fixes and help detect regressions quickly.

Would you like me to create an initial test suite for this function or open a new GitHub issue tracking the coverage improvements?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a31ca2 and 25806c8.

📒 Files selected for processing (3)
  • package.json (2 hunks)
  • utils/fix-broken-links.ts (1 hunks)
  • words.txt (1 hunks)
🧰 Additional context used
🪛 LanguageTool
words.txt

[duplication] ~118-~118: Možný preklep: zopakovali ste slovo
Context: ...therbase Ethernity Ethernow ethpandaops ETHSTATS ethstats EVMTIMEOUT evmtimeout executability exf...

(WORD_REPEAT_RULE)

🔇 Additional comments (3)
words.txt (1)

118-118: No issues found regarding the newly added word.

This looks like a legitimate addition to the known word list. The static analysis hint likely flagged a false positive “word repetition.” There is no apparent duplication in this context.

🧰 Tools
🪛 LanguageTool

[duplication] ~118-~118: Možný preklep: zopakovali ste slovo
Context: ...therbase Ethernity Ethernow ethpandaops ETHSTATS ethstats EVMTIMEOUT evmtimeout executability exf...

(WORD_REPEAT_RULE)

utils/fix-broken-links.ts (1)

631-633: Exit code usage is correct but verify CI integration.
The script uses process.exit(1) when broken links remain. Ensure this behavior aligns with your CI/CD pipeline requirements (e.g., failing a build if any broken links are found).

package.json (1)

8-9: Script addition appears valid and well-integrated.
Appending pnpm fix-links to the existing "fix" script, alongside the new "fix-links" script definition, properly incorporates the link-fixing utility into your workflow without disrupting other tasks.

Also applies to: 17-17

@krofax krofax merged commit 9b2a44b into main Mar 5, 2025
8 checks passed
@krofax krofax deleted the fix-links branch March 5, 2025 20:26
This was referenced Mar 6, 2025
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.

2 participants