Skip to content

Linter: Fix html-no-self-closing to preserve indentation#1753

Merged
marcoroth merged 1 commit into
marcoroth:mainfrom
fgkolf:html-no-self-closing-preserve-indentation
Jun 5, 2026
Merged

Linter: Fix html-no-self-closing to preserve indentation#1753
marcoroth merged 1 commit into
marcoroth:mainfrom
fgkolf:html-no-self-closing-preserve-indentation

Conversation

@fgkolf

@fgkolf fgkolf commented May 23, 2026

Copy link
Copy Markdown
Contributor

👋 I came across the following issue with the html-no-self-closing rule:

When autofixing nested elements whose closing tag appears on a new line, the self-closing tag is correctly fixed, but the indentation is lost and the closing bracket is placed at column 0.

This can be verified with the following example:

Before

<figure>
  <img
    src="/image.png"
    alt="An image"
  />
</figure>

After

<figure>
  <img
    src="/image.png"
    alt="An image"
>
</figure>

With this fix

<figure>
  <img
    src="/image.png"
    alt="An image"
  >
</figure>

P.S. I wasn't sure whether I should open an issue first. Let me know if you'd prefer that for completeness' sake.

When autofixing multiline self-closing tags (e.g. `<img\n  />`), the rule
was stripping the indentation whitespace before `/>`, causing the resulting
`>` to appear at column 0. This introduces an `isIndentation` helper that
detects when a trailing whitespace node represents indentation (i.e. it
follows a newline sibling) and preserves it during the fix.

@marcoroth marcoroth left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Awesome, thanks for this great catch @fgkolf! 🙏🏼

P.S. I wasn't sure whether I should open an issue first. Let me know if you'd prefer that for completeness' sake.

Whatever is more comfortable for you, but you definitely don't need to open an issue first just for the sake of opening an issue if you already have a proposed solution for the fix, thank you! 🙌🏼

@marcoroth marcoroth merged commit e6ec037 into marcoroth:main Jun 5, 2026
12 checks passed
@marcoroth marcoroth added the bug Something isn't working label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants