vue/no-literals-in-template
eslint-plugin-vue
No autofix
eslint.config.js
import vue from "eslint-plugin-vue";
export default [
{
plugins: { vue },
rules: {
"vue/no-literals-in-template": "error",
},
},
]; <div :arr="[]" />
<div :arr="[1, 2, 3]" />
<div :obj="{}" />
<div :obj="{ name: 'Tom', age: 123 }" />
<div :callback="() => someFunction(someArgs)" />
<div :callback="function() { return 1 }" />
<template v-for="i in arr">
<MyComponent :data="[globalVars]" />
<MyComponent :data="{ index: globalVars }" />
<MyComponent :callback="() => someFunction(someArgs, globalVars)" />
</template>
<Child>
<template #default="{ foo }">
<MyComponent :data="[globalVars]" />
<MyComponent :data="{ val: globalVars }" />
<MyComponent :data="() => someFunction(someArgs, globalVars)" />
</template>
</Child>
</template> <MyComponent :wrapper-class="[{ active: isActive }]" />
</template><div :arr="myArray" />
<div :obj="myObject" />
<div :callback="myFunction" />
<div arr="[]" />
<!-- class and style bindings are ignored -->
<div :class="{ active: isActive }" />
<div :style="{ color: 'red' }" />
<template v-for="i in arr">
<MyComponent :data="[i]" />
<MyComponent :data="{ index: i }" />
<MyComponent :callback="() => someFunction(someArgs, i)" />
</template>
<Child>
<template #default="{ foo }">
<MyComponent :data="[foo]" />
<MyComponent :data="{ val: foo }" />
<MyComponent :data="() => someFunction(someArgs, foo)" />
</template>
</Child><MyComponent
:slot-class="[{ active: isActive }]"
:slot-style="{ color: themeColor }"
/>Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
vue/no-literals-in-template
eslint-plugin-vue
import vue from "eslint-plugin-vue";
export default [
{
plugins: { vue },
rules: {
"vue/no-literals-in-template": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Disallow a potential typo in your component property
Disallow the <template> <script> <style> block to be empty
Disallow duplication of class names in class attributes