Skip to content

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

Open
fgkolf wants to merge 1 commit into
marcoroth:mainfrom
fgkolf:html-no-self-closing-preserve-indentation
Open

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

Conversation

@fgkolf
Copy link
Copy Markdown

@fgkolf fgkolf commented May 23, 2026

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

1 participant