Skip to content

Ignore <template> in vue/html-self-closing rule #2202

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

Closed
Thomasan1999 opened this issue Jun 1, 2023 · 8 comments · Fixed by #2223
Closed

Ignore <template> in vue/html-self-closing rule #2202

Thomasan1999 opened this issue Jun 1, 2023 · 8 comments · Fixed by #2223

Comments

@Thomasan1999
Copy link
Contributor

What rule do you want to change?
vue/html-self-closing

Does this change cause the rule to produce more or fewer warnings?
N/A

How will the change be implemented? (New option, new default behavior, etc.)?
Either by default or add an option to ignore <template> the same way <style> and <script> tags are ignored. Empty <template> tags don't make sense and should either be fully-removed from the Vue template by the engineer or left alone (if that's the way the engineer prefers it).

Please provide some example code that this change will affect:

<CustomComponent>
    <template #slotName></template>
</CustomComponent>
<template></template>

What does the rule currently do for this code?

<CustomComponent>
    <template #slotName />
</CustomComponent>
<template />

What will the rule do after it's changed?
It would leave the code unaffected.

Additional context
N/A

@FloEdelmann
Copy link
Member

Hmm, I'm not sure why <template></template> should be a special case. What is the purpose?
Did you check whether the current options of the vue/html-self-closing rule are maybe already sufficient?

Note that there is the (recommended) vue/no-lone-template rule that disallows empty template elements anyway.

@Dimava
Copy link

Dimava commented Jun 17, 2023

This is a problem when you use autofix on save
I often make templates like

<script setup lang="ts">
</script>
<template>
</template>

and having it to self-close the <template> on save is annoying
I have to either fix that manually (which is annoying) or not to save (which is even more annoying)

As there is vue/no-lone-template empty <template></template> is considered invalid, so <template/> is obviously invalid, so autofixing unfinished <template></template> (which is already a warning) to invalid <template/> (which has to be unself-closed manually) makes no sense

@FloEdelmann
Copy link
Member

I think that top-level block tags should just all be excluded in vue/html-self-closing. A pull request is welcome for this change.

However, I don't think that other <template> elements should then get any special treatment.

@Thomasan1999
Copy link
Contributor Author

What about excluding <template> elements if vue/no-lone-template is turned on? So they're not conflicting each other.

@FloEdelmann
Copy link
Member

No, rules should be independent, i.e. they should not be influenced by which other rules are enabled.

I still don't get why <template></template> should be a special case. "Autofix on save" does also apply to e.g. <div></div>.

@Dimava
Copy link

Dimava commented Jun 20, 2023

Something like exclude: string[] (or regex) would be fine

@Dimava
Copy link

Dimava commented Jun 20, 2023

Or excludeRoot: boolean as I don't think collapsing root items may ever make sense

@FloEdelmann
Copy link
Member

As I said previously, top-level block tags should just all be excluded (without options). A pull request is welcome for this change.

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 a pull request may close this issue.

3 participants