Skip to content

Conversation

@coliff
Copy link
Member

@coliff coliff commented Jun 19, 2025

This pull request introduces a new autofix feature for the tag-self-close rule in the htmlhint-server and refactors existing code to simplify and improve maintainability. It also includes updates to the documentation and test cases to reflect the new functionality.

New Feature: tag-self-close Autofix

  • Added createTagSelfCloseFix function to automatically convert non-self-closing void HTML elements (e.g., <img>) into self-closing tags (e.g., <img />) to comply with standards. (htmlhint-server/src/server.ts, htmlhint-server/src/server.tsR1342-R1468)
  • Integrated the new autofix into the createAutoFixes function, enabling it to handle diagnostics for the tag-self-close rule. (htmlhint-server/src/server.ts, htmlhint-server/src/server.tsR1551-R1554)
  • Updated the diagnostic handling logic in connection.onRequest to support the tag-self-close rule, including extracting raw tag data and ensuring proper range normalization. (htmlhint-server/src/server.ts, [1] [2] [3] [4]

Code Refactoring

  • Simplified position calculations in multiple autofix functions (createAttrValueDoubleQuotesFix, createTagnameLowercaseFix, createAttrLowercaseFix, and createSpecCharEscapeFix) by replacing complex logic with a more direct approach using lineIndex. (htmlhint-server/src/server.ts, [1] [2] [3] [4]

Documentation Updates

  • Added the tag-self-close rule to the list of supported autofix rules in the README.md file. (htmlhint/README.md, htmlhint/README.mdR41)
  • Updated the CHANGELOG.md to document the addition of the tag-self-close autofix feature. (htmlhint/CHANGELOG.md, htmlhint/CHANGELOG.mdR8)

Test Enhancements

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an autofix feature for the tag-self-close rule and refactors existing code for better maintainability. The changes are well-implemented, with good test coverage and documentation updates.

Comment on lines +11 to +16
<img src="test.jpg" alt="Test image">
<br>
<hr>
<input type="text" placeholder="Enter text">
<meta name="test" content="test">
<link rel="stylesheet" href="style.css">

Choose a reason for hiding this comment

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

medium

These test cases effectively validate that the autofix correctly converts non-self-closing void HTML elements into self-closing tags.

@coliff coliff merged commit e6a65c6 into main Jun 19, 2025
9 checks passed
@coliff coliff deleted the dev/coliff/add-tag-self-close-autofix branch June 19, 2025 05:00
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