Skip to content
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

Fix Anchor Generation Logic in Error Documentation #5975

Closed
wants to merge 1 commit into from

Conversation

voronor
Copy link

@voronor voronor commented Nov 23, 2024

  • Because this PR includes a bug fix, relevant tests have been included.

Description:

This pull request addresses a known issue in the error documentation generation script, as highlighted by the following comment in the code:

// TODO: Fix anchor generation

Issue:

The current implementation assigns shortLink directly to anchor without any processing:

const anchor = shortLink;

This can lead to improperly formatted or non-unique anchors, depending on the contents of shortLink. Anchors must adhere to certain formatting rules (e.g., lowercase, no special characters) to be valid and reliable in URLs.


Proposed Solution:

Introduce logic to sanitize and standardize the anchor generation:

const anchor = shortLink.toLowerCase().replace(/[^a-z0-9-]/g, "-");

Benefits of This Approach:

  1. Consistency: Converts all characters to lowercase for uniformity.
  2. Validity: Replaces invalid characters with hyphens (-) to meet common URL anchor conventions.
  3. Reliability: Reduces the risk of anchor conflicts or issues in rendering.

Why This Fix Is Important:

  1. Documentation Accuracy: Proper anchors ensure that users can navigate the error documentation without broken links.
  2. Future-proofing: Simplifies error redirection and avoids potential collisions caused by poorly formatted anchors.
  3. Developer Experience: Resolves a known TODO in the code, improving maintainability and clarity.

Before:

const anchor = shortLink;

After:

const anchor = shortLink.toLowerCase().replace(/[^a-z0-9-]/g, "-");

Copy link

changeset-bot bot commented Nov 23, 2024

⚠️ No Changeset found

Latest commit: 4294f06

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Nov 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 23, 2024 11:10am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants