Skip to content

Conversation

@rzzf
Copy link
Contributor

@rzzf rzzf commented Dec 11, 2025

resolves #2733

This is indeed valid syntax.
See Vue Playground

@changeset-bot
Copy link

changeset-bot bot commented Dec 11, 2025

🦋 Changeset detected

Latest commit: 3ea9630

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

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

Thank you for looking into it. Looks good to me 🙂

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the vue/valid-v-for rule to correctly allow empty value aliases in v-for directives, such as v-for="(, key) in obj", which is valid Vue.js syntax when you only need the key/index from an iteration.

Key Changes:

  • Updated validation logic to only report an error when both value and key are empty
  • Added test cases for the newly allowed syntax patterns
  • Removed incorrectly failing test case

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
lib/rules/valid-v-for.js Modified the empty alias validation to allow empty value when a key is present
tests/lib/rules/valid-v-for.js Added valid test cases for (, key) and (, key, index) patterns; removed false-positive invalid test
.changeset/silly-falcons-explain.md Added changeset documenting the patch-level fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

},
{
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.

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 this pull request may close these issues.

vue/valid-v-for should not trigger on looping through only keys of an object

3 participants