-
-
Notifications
You must be signed in to change notification settings - Fork 6
Create auto-fix action for attr-no-duplication rule #336
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
Conversation
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).
There was a problem hiding this 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.
There was a problem hiding this 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
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>
implemented autofix support for the attr-no-duplication rule.
Key Features:
<img src="a.png" src="b.png" />where values differExamples of what it will fix:
Examples of what it WON'T fix:
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).