Skip to content

Conversation

@coliff
Copy link
Member

@coliff coliff commented Nov 26, 2025

implemented autofix support for the attr-no-duplication rule.

Key Features:

  • Smart duplicate detection: Only removes duplicate attributes when the values are identical
  • Safe behavior: Won't autofix cases like <img src="a.png" src="b.png" /> where values differ
  • Multiple duplicates: Handles cases with multiple duplicate attributes in the same tag
  • Proper whitespace handling: Cleans up whitespace when removing duplicates

Examples of what it will fix:

<!-- BEFORE -->
<img src="test.jpg" alt="Test" src="test.jpg" alt="Test" />
<div class="container" class="container" id="main">

<!-- AFTER -->
<img src="test.jpg" alt="Test" />
<div class="container" id="main">

Examples of what it WON'T fix:

<!-- These remain unchanged -->
<img src="a.png" src="b.png" alt="Different">
<div class="red" class="blue" id="main">

Changes Made:

✅ Added createAttrNoDuplicationFix() function in htmlhint-server/src/server.ts
✅ Added the new rule to the autofix switch statement
✅ Updated README.md to document the new autofix support
✅ Compiled successfully with no errors

When users encounter attr-no-duplication warnings in VS Code, they'll see a lightbulb icon offering to automatically remove the duplicate attributes (only when values are identical).

implemented autofix support for the attr-no-duplication rule with your requested logic. Here's what was added:

Key Features:
- Smart duplicate detection: Only removes duplicate attributes when the values are identical
- Safe behavior: Won't autofix cases like <img src="a.png" src="b.png" /> where values differ
- Multiple duplicates: Handles cases with multiple duplicate attributes in the same tag
- Proper whitespace handling: Cleans up whitespace when removing duplicates

Examples of what it will fix:
<!-- BEFORE --><img src="test.jpg" alt="Test" src="test.jpg" alt="Test"><div class="container" class="container" id="main"><!-- AFTER --><img src="test.jpg" alt="Test"><div class="container" id="main">

Examples of what it WON'T fix (as requested):
<!-- These remain unchanged --><img src="a.png" src="b.png" alt="Different"><div class="red" class="blue" id="main">

Changes Made:
✅ Added createAttrNoDuplicationFix() function in htmlhint-server/src/server.ts
✅ Added the new rule to the autofix switch statement
✅ Updated README.md to document the new autofix support
✅ Compiled successfully with no errors

When users encounter attr-no-duplication warnings in VS Code, they'll see a lightbulb icon offering to automatically remove the duplicate attributes (only when values are identical).
Copy link
Contributor

@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 auto-fix capability for the attr-no-duplication rule, which is a great enhancement. The implementation correctly identifies and removes duplicate attributes when their values are identical. I've found a critical issue with how tag boundaries are detected, which could fail on certain edge cases. I've also included a couple of medium-severity suggestions to improve code maintainability and to follow the newly added release process. Overall, this is a valuable addition once the critical issue is addressed.

Copilot finished reviewing on behalf of coliff November 26, 2025 04:07
Copy link
Contributor

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

This PR adds auto-fix functionality for the attr-no-duplication HTMLHint rule. The implementation intelligently removes duplicate HTML attributes only when their values are identical, avoiding potential issues when values differ. The version is bumped from 1.13.0 to 1.14.0.

Key changes:

  • Implemented createAttrNoDuplicationFix() function with smart duplicate detection and safe whitespace handling
  • Integrated the new autofix into the existing code action system
  • Updated documentation to reflect the new capability

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
htmlhint/package.json Version bump to 1.14.0
htmlhint/package-lock.json Updated lockfile to match version 1.14.0
htmlhint/README.md Added attr-no-duplication to the list of supported auto-fixes
htmlhint-server/src/server.ts Implemented createAttrNoDuplicationFix() function and integrated it into the switch statement
README.md Added release process documentation for future version releases
Files not reviewed (1)
  • htmlhint/package-lock.json: Language not supported

coliff and others added 2 commits November 26, 2025 13:10
Introduces robust functions to find tag boundaries and tag ends, properly handling quotes and edge cases in HTML. Updates the attr-no-duplication autofix logic to use these new functions, improving reliability when detecting and removing duplicate attributes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@coliff coliff merged commit 921e2dc into main Nov 26, 2025
13 checks passed
@coliff coliff deleted the dev/coliff/autofix-attr-no-duplication-rule branch November 26, 2025 04:14
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