Skip to content

Conversation

@coliff
Copy link
Member

@coliff coliff commented Nov 28, 2025

This pull request adds support for autofixing the link-rel-canonical-require rule in the HTMLHint extension, allowing the extension to automatically insert a canonical link tag into the <head> section of HTML documents when it is missing. The feature is documented in both the changelog and README, and new tests have been added to ensure correct behavior.

Autofix Feature Addition

  • Implemented the createLinkRelCanonicalRequireFix function in htmlhint-server/src/server.ts, which generates a quick fix to add a <link rel="canonical"> tag to the <head> section if it is missing. The function intelligently determines the best insertion point based on existing meta tags and respects the tag-self-close rule.
  • Integrated the new autofix into the createAutoFixes function so that diagnostics for the link-rel-canonical-require rule now trigger the autofix logic.

Documentation Updates

  • Added an entry for the new autofix in the changelog (htmlhint/CHANGELOG.md).
  • Updated the README to list link-rel-canonical-require as a supported autofix rule.

Testing and Configuration

  • Enabled the link-rel-canonical-require rule in the test configuration (test/autofix/.htmlhintrc).
  • Added a new test HTML file (test/autofix/link-canonical-test.html) to verify the autofix behavior for canonical link tags.

gemini-code-assist[bot]

This comment was marked as resolved.

Copilot finished reviewing on behalf of coliff November 28, 2025 07:58

This comment was marked as resolved.

Updated the regular expression to match <link> tags with the canonical rel attribute regardless of attribute order, improving robustness in canonical link detection.
@coliff coliff merged commit 6e3f612 into main Nov 28, 2025
12 checks passed
@coliff coliff deleted the dev/coliff/link-rel-canonical-require-autofix branch November 28, 2025 08:10
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