WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-falcons-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-vue": patch
---

Fix `vue/valid-v-for` rule to allow empty value alias
2 changes: 1 addition & 1 deletion lib/rules/valid-v-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = {
const key = lhs[1]
const index = lhs[2]

if (value === null) {
if (value === null && !key) {
context.report({
node: expr,
messageId: 'invalidEmptyAlias'
Expand Down
13 changes: 8 additions & 5 deletions tests/lib/rules/valid-v-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ tester.run('valid-v-for', rule, {
filename: 'test.vue',
code: '<template><div><your-component v-for="x in list" :key="x.id"></your-component></div></template>'
},
{
filename: 'test.vue',
code: '<template><div><div v-for="(, key) in obj"></div></div></template>'
},
{
filename: 'test.vue',
code: '<template><div><div v-for="(, key, index) in obj"></div></div></template>'
},
{
filename: 'test.vue',
code: '<template><div><div is="your-component" v-for="x in list" :key="x.id"></div></div></template>'
Expand Down Expand Up @@ -183,11 +191,6 @@ tester.run('valid-v-for', rule, {
code: '<template><div><div v-for></div></div></template>',
errors: ["'v-for' directives require that attribute value."]
},
{
filename: 'test.vue',
code: '<template><div><div v-for="(,a,b) in list"></div></div></template>',
errors: ["Invalid alias ''."]
},
{
filename: 'test.vue',
code: '<template><div><div v-for="(a,,b) in list"></div></div></template>',
Copy link
Member

@waynzh waynzh Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a valid syntax, we consider it as invalid since no one is actually using the object's index, right?

Copy link
Member

@waynzh waynzh Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using the index makes sense, I wonder if invalidEmptyAlias was intentionally added to avoid potential errors. Maybe this rule recommends explicitly enumerating all variables before use (and pairing it with other rules to handle unused variables).

If that goes beyond this rule, I think cases like (value, , index), (value,,)or (, , index)—while valid syntax—should also be allowed. (or invalidEmptyAlias could just focus on cases like (value,,) where the alias is empty at the end)

Let me know what you guys think.

Expand Down
Loading