Skip to content

Conversation

@coliff
Copy link
Member

@coliff coliff commented Nov 26, 2025

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.

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.
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 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.

Comment on lines 2032 to 2043
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=""';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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>
Copilot finished reviewing on behalf of coliff November 26, 2025 04:27
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 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 adds method="" 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.
@coliff coliff changed the title Add autofix support for the form-method-require rule Add autofix support for the form-method-require rule Nov 26, 2025
@coliff coliff merged commit a245dea into main Nov 26, 2025
12 checks passed
@coliff coliff deleted the dev/coliff/add-autofix-for-form-method-require branch November 26, 2025 04:32
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