Skip to content

Rule Proposal: no unnecessary template #567

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
arianrhodsandlot opened this issue Aug 31, 2018 · 1 comment · Fixed by #1238
Closed

Rule Proposal: no unnecessary template #567

arianrhodsandlot opened this issue Aug 31, 2018 · 1 comment · Fixed by #1238

Comments

@arianrhodsandlot
Copy link

arianrhodsandlot commented Aug 31, 2018

Could we add a rule that emits an error when template tag is not necessary?

If a template tag has only one child element, or it has no v-if / v-else-if / v-else / v-for directive, this tag can be omitted.

For example, there are some examples of incorrect code for this rule:

<template>
  <div class="root">
    <template v-if="isXxx">
      <span>{{ xxx }}</span>
    </template>
  </div>
</template>
<template>
  <div class="root">
    <template>
      <span>{{ xxx }}</span>
      <span>{{ yyy }}</span>
    </template>
  </div>
</template>

Here are some correct ones:

<template>
  <div class="root">
    <span v-if="isXxx">{{ xxx }}</span>
  </div>
</template>
<template>
  <div class="root">
    <template v-for="item in items">
      <span>{{ item.xxx }}</span>
      <span>{{ item.yyy }}</span>
    </template>
  </div>
</template>

What do you think of this?

@ota-meshi
Copy link
Member

Thank you for this rule proposition.

I would like to implement this rule. In Vue 3 the <template> tag is rendered and probably not intended for most users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants