vue/no-lone-template
Disallow unnecessary <template> elements.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
No | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The inner template has no directive or slot role that gives it a structural purpose.
<template>
<div><template><p>Details</p></template></div>
</template>
Good
Removing the unnecessary wrapper leaves the paragraph directly inside div.
<template>
<div><p>Details</p></div>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-lone-template": "warn"
}
},
});
Then run vp run lint.