prettier-plugin-svelte icon indicating copy to clipboard operation
prettier-plugin-svelte copied to clipboard

Disable self-closing tag if empty

Open lacherogwu opened this issue 3 years ago • 2 comments

Describe the bug

Hello,

I think when the html tag is empty, it should use self-closing on format. image

When I'm writing code, sometimes I write just boilerplate of HTML tags before I implement any styles and it's kinda annoying that it's closing empty elements, and to be honest it doesn't really make sense...

If the tag is not empty and contains any attribute so I believe self-closing will be the right way to go for e.g.

<div class="a" /> ✅
<div /> ❌
<div></div> ✅

Thanks!

Reproduction

Write any HTML tag and save the file I use Prettier for formatting, and auto-format on save

Logs

No response

System Info

System:
    OS: macOS 10.15.5
    CPU: (12) x64 Intel(R) Xeon(R) CPU           X5690  @ 3.47GHz
    Memory: 2.86 GB / 48.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Chrome: 100.0.4896.75
    Firefox: 98.0.2
    Firefox Developer Edition: 98.0
    Safari: 13.1.1
  npmPackages:
    svelte: ^3.44.0 => 3.46.6

Severity

annoyance

lacherogwu avatar Apr 08 '22 07:04 lacherogwu

I agree. In fact I'd prefer the option to completely self closing tags for plain HTML elements. It even self-closes auto-closing tags like <br> or <input>. I think it makes the code actually uglier.

khaki32 avatar Jul 18 '22 10:07 khaki32

I think html compliant should be preferred like prettier core and we can adopt the core option.

JounQin avatar Jul 28 '22 03:07 JounQin

Have you fixed the issue somehow?

ajikia15 avatar Feb 20 '23 14:02 ajikia15

In prettier-plugin-svelte version 3 tags will be left as-is.

dummdidumm avatar Jul 17 '23 11:07 dummdidumm