-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add autofix support for the form-method-require rule
#337
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 `form-method-require` rule. - ✅ Added createFormMethodRequireFix() 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 The autofix will add an empty method="" attribute, leaving the cursor positioned so users can easily fill in get, post, or dialog as needed.
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 successfully implements autofix support for the form-method-require rule. The changes include adding the createFormMethodRequireFix function, integrating it into the autofix logic, and updating the CHANGELOG.md and README.md files. The implementation is well-done and handles edge cases correctly. I have one minor suggestion to improve code clarity by reducing a small amount of duplication. Overall, this is a valuable addition to the extension's autofix capabilities.
| let insertPosition: number; | ||
| let newText: string; | ||
|
|
||
| if (existingAttrs.trim()) { | ||
| // There are existing attributes, add method after them | ||
| insertPosition = tagStart + beforeAttrs.length + existingAttrs.length; | ||
| newText = ' method=""'; | ||
| } else { | ||
| // No existing attributes, add method right after "form" | ||
| insertPosition = tagStart + beforeAttrs.length; | ||
| newText = ' method=""'; | ||
| } |
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.
The newText variable is assigned the same value ' method=""' in both branches of the if-else statement. You can avoid this duplication by declaring and initializing newText as a constant before the conditional block. This improves code readability and maintainability by making it clear that the text to be inserted is always the same.
// Calculate insertion position
const newText = ' method=""';
let insertPosition: number;
if (existingAttrs.trim()) {
// There are existing attributes, add method after them
insertPosition = tagStart + beforeAttrs.length + existingAttrs.length;
} else {
// No existing attributes, add method right after "form"
insertPosition = tagStart + beforeAttrs.length;
}…tion or class' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
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 autofix support for the form-method-require HTMLHint rule, allowing developers to automatically add the method="" attribute to form tags that are missing it.
Key Changes:
- Implemented
createFormMethodRequireFix()function in the server that addsmethod=""to form tags - Integrated the new autofix into the switch statement for code action handling
- Updated documentation to reflect the new autofix capability
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| htmlhint-server/src/server.ts | Adds the createFormMethodRequireFix() function with robust tag parsing and integrates it into the autofix switch statement |
| htmlhint/README.md | Documents the new form-method-require autofix in the supported autofixes list |
| htmlhint/CHANGELOG.md | Records the addition of the form-method-require autofix in version 1.14.0 |
Comments suppressed due to low confidence (1)
htmlhint-server/src/server.ts:2029
- Unused variable tagClose.
Simplifies the logic for inserting the 'method' attribute into form tags by moving the assignment of newText outside the conditional branches.
form-method-require rule
Implemented autofix support for the
form-method-requirerule.The autofix will add an empty
method=""attribute, leaving the cursor positioned so users can easily fill inget,post, ordialogas needed.